omnius 1.0.923 → 1.0.925
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/{providerRegistry.d.ts → _types/backend-vllm/providerRegistry.d.ts} +0 -1
- package/dist/_types/backend-vllm/types.d.ts +209 -0
- package/dist/_types/execution/av/media-capability.d.ts +94 -0
- package/dist/_types/execution/delegation-contract.d.ts +102 -0
- package/dist/_types/execution/evidence.d.ts +68 -0
- package/dist/_types/execution/html-source-evidence.d.ts +65 -0
- package/dist/_types/execution/mcp/types.d.ts +169 -0
- package/dist/_types/execution/mutation-contract.d.ts +102 -0
- package/dist/_types/execution/nol/artifacts.d.ts +39 -0
- package/dist/_types/execution/nol/checkpoint-edits.d.ts +98 -0
- package/dist/_types/execution/nol/distributions.d.ts +128 -0
- package/dist/_types/execution/nol/gguf-checkpoint-edits.d.ts +194 -0
- package/dist/_types/execution/nol/gguf-control-reader.d.ts +224 -0
- package/dist/_types/execution/nol/lora-exports.d.ts +129 -0
- package/dist/_types/execution/nol/neuronary.d.ts +212 -0
- package/dist/_types/execution/nol/pytorch-control-reader.d.ts +143 -0
- package/dist/_types/execution/nol/qwen35-head-sites.d.ts +61 -0
- package/dist/_types/execution/nol/worker-assets.d.ts +82 -0
- package/dist/_types/execution/nol/worker-protocol.d.ts +94 -0
- package/dist/_types/execution/page-content-source.d.ts +40 -0
- package/dist/_types/execution/rapid-computer-use/artifact-store.d.ts +21 -0
- package/dist/_types/execution/rapid-computer-use/contracts.d.ts +320 -0
- package/dist/_types/execution/rapid-computer-use/decision.d.ts +70 -0
- package/dist/_types/execution/rapid-computer-use/desktop-verification.d.ts +23 -0
- package/dist/_types/execution/rapid-computer-use/geometry.d.ts +57 -0
- package/dist/_types/execution/rapid-computer-use/planner.d.ts +78 -0
- package/dist/_types/execution/rapid-computer-use/trace.d.ts +80 -0
- package/dist/_types/execution/rapid-computer-use/visual.d.ts +48 -0
- package/dist/_types/execution/shell-runs.d.ts +78 -0
- package/dist/_types/execution/streamed-web-source.d.ts +64 -0
- package/dist/_types/execution/tools/browser-page-fallback.d.ts +25 -0
- package/dist/_types/execution/tools/network-egress-policy.d.ts +30 -0
- package/dist/_types/execution/tools/pdf-native-tables.d.ts +46 -0
- package/dist/_types/execution/tools/todo-store.d.ts +133 -0
- package/dist/_types/execution/tools/web-fetch.d.ts +57 -0
- package/dist/_types/execution/tools/workboard.d.ts +1223 -0
- package/dist/_types/execution/types.d.ts +549 -0
- package/dist/_types/execution/web-source.d.ts +14 -0
- package/dist/_types/memory/artifactReviewSourceIndex.d.ts +133 -0
- package/dist/_types/memory/contextMemoryLedger.d.ts +213 -0
- package/dist/_types/memory/db.d.ts +12 -0
- package/dist/_types/memory/embeddings.d.ts +36 -0
- package/dist/_types/memory/immutableEvidenceStore.d.ts +165 -0
- package/dist/_types/memory/memoryIngestion.d.ts +65 -0
- package/dist/_types/memory/memoryTypes.d.ts +312 -0
- package/dist/_types/memory/sourceCorpusStore.d.ts +331 -0
- package/dist/_types/memory/structuredMemoryStore.d.ts +105 -0
- package/dist/_types/memory/unifiedMemoryStore.d.ts +127 -0
- package/dist/_types/memory/virtualMemory.d.ts +187 -0
- package/dist/_types/orchestrator/agentic-page-content-receipt.d.ts +20 -0
- package/dist/_types/orchestrator/agentic-web-fetch-receipt.d.ts +20 -0
- package/dist/_types/orchestrator/agenticRunner.d.ts +5219 -0
- package/dist/_types/orchestrator/app-state.d.ts +171 -0
- package/dist/_types/orchestrator/artifactClaimCritic.d.ts +63 -0
- package/dist/_types/orchestrator/artifactQuality.d.ts +15 -0
- package/dist/_types/orchestrator/artifactSemanticIntegrity.d.ts +203 -0
- package/dist/_types/orchestrator/canonical-context-projection.d.ts +254 -0
- package/dist/_types/orchestrator/canonical-source-body-projection.d.ts +51 -0
- package/dist/_types/orchestrator/completion-review-pending.d.ts +24 -0
- package/dist/_types/orchestrator/completionContract.d.ts +103 -0
- package/dist/_types/orchestrator/completionFinalization.d.ts +224 -0
- package/dist/_types/orchestrator/completionLedger.d.ts +429 -0
- package/dist/_types/orchestrator/completionReadiness.d.ts +234 -0
- package/dist/_types/orchestrator/context-admission.d.ts +93 -0
- package/dist/_types/orchestrator/context-dump-retention.d.ts +25 -0
- package/dist/_types/orchestrator/context-fabric.d.ts +133 -0
- package/dist/_types/orchestrator/contextEngine.d.ts +68 -0
- package/dist/_types/orchestrator/contextWindowDump.d.ts +327 -0
- package/dist/_types/orchestrator/convergence-breaker.d.ts +225 -0
- package/dist/_types/orchestrator/convergence-progress.d.ts +66 -0
- package/dist/_types/orchestrator/deliveryCoverage.d.ts +181 -0
- package/dist/_types/orchestrator/document-persistence-goal-binding.d.ts +106 -0
- package/dist/_types/orchestrator/durable-document-worker.d.ts +85 -0
- package/dist/_types/orchestrator/evidenceBranch.d.ts +291 -0
- package/dist/_types/orchestrator/expected-inference-response.d.ts +55 -0
- package/dist/_types/orchestrator/expectedOutcomeContract.d.ts +58 -0
- package/dist/_types/orchestrator/failure-taxonomy.d.ts +36 -0
- package/dist/_types/orchestrator/focusSupervisor.d.ts +436 -0
- package/dist/_types/orchestrator/forced-update-requirement-recovery.d.ts +105 -0
- package/dist/_types/orchestrator/hooks.d.ts +100 -0
- package/dist/_types/orchestrator/inference-pressure.d.ts +61 -0
- package/dist/_types/orchestrator/integrationClosure.d.ts +89 -0
- package/dist/_types/orchestrator/interruption-lifecycle.d.ts +154 -0
- package/dist/_types/orchestrator/live-memory-passages.d.ts +51 -0
- package/dist/_types/orchestrator/liveVirtualContext.d.ts +84 -0
- package/dist/_types/orchestrator/memory-compiler.d.ts +254 -0
- package/dist/_types/orchestrator/memory-consolidation.d.ts +134 -0
- package/dist/_types/orchestrator/model-router.d.ts +17 -0
- package/dist/_types/orchestrator/modelResponseDiagnostics.d.ts +71 -0
- package/dist/_types/orchestrator/nativeRequirementAmendment.d.ts +63 -0
- package/dist/_types/orchestrator/nol/coordinator.d.ts +204 -0
- package/dist/_types/orchestrator/nol/datasets.d.ts +58 -0
- package/dist/_types/orchestrator/nol/discovery.d.ts +286 -0
- package/dist/_types/orchestrator/nol/evaluation.d.ts +59 -0
- package/dist/_types/orchestrator/nol/model-validation.d.ts +198 -0
- package/dist/_types/orchestrator/nol/statistics.d.ts +142 -0
- package/dist/_types/orchestrator/nol/store.d.ts +133 -0
- package/dist/_types/orchestrator/nol/variant-registry.d.ts +292 -0
- package/dist/_types/orchestrator/ollama-context-policy.d.ts +34 -0
- package/dist/_types/orchestrator/personality.d.ts +66 -0
- package/dist/_types/orchestrator/prompt-cache.d.ts +24 -0
- package/dist/_types/orchestrator/remote-inference-fallback.d.ts +224 -0
- package/dist/_types/orchestrator/remote-inference-policy.d.ts +58 -0
- package/dist/_types/orchestrator/request-budget.d.ts +75 -0
- package/dist/_types/orchestrator/requirementCoverage.d.ts +69 -0
- package/dist/_types/orchestrator/reviewedInterpretation.d.ts +111 -0
- package/dist/_types/orchestrator/runEvents.d.ts +115 -0
- package/dist/_types/orchestrator/runtime-rollout.d.ts +63 -0
- package/dist/_types/orchestrator/semanticVerification.d.ts +135 -0
- package/dist/_types/orchestrator/source-wide-extraction.d.ts +202 -0
- package/dist/_types/orchestrator/steeringIntake.d.ts +123 -0
- package/dist/_types/orchestrator/structured-memory-extraction-worker.d.ts +89 -0
- package/dist/_types/orchestrator/structuredMemoryInference.d.ts +62 -0
- package/dist/_types/orchestrator/successful-procedure-memory.d.ts +127 -0
- package/dist/_types/orchestrator/supportedAnswer.d.ts +68 -0
- package/dist/_types/orchestrator/taskEffectEvidence.d.ts +38 -0
- package/dist/_types/orchestrator/taskExecutionSnapshot.d.ts +67 -0
- package/dist/_types/orchestrator/taskObjective.d.ts +310 -0
- package/dist/_types/orchestrator/taskObjectiveContinuation.d.ts +134 -0
- package/dist/_types/orchestrator/taskRequirementReview.d.ts +246 -0
- package/dist/_types/orchestrator/taskRequirements.d.ts +80 -0
- package/dist/_types/orchestrator/taskSemanticAdmission.d.ts +159 -0
- package/dist/_types/orchestrator/taskWorkDelegation.d.ts +147 -0
- package/dist/_types/orchestrator/taskWorkPlan.d.ts +177 -0
- package/dist/_types/orchestrator/telegram-passive-history.d.ts +42 -0
- package/dist/_types/orchestrator/terminalTaskReport.d.ts +91 -0
- package/dist/_types/orchestrator/todoObservability.d.ts +147 -0
- package/dist/_types/orchestrator/tool-exposure-policy.d.ts +100 -0
- package/dist/_types/orchestrator/trajectory-checkpoint.d.ts +159 -0
- package/dist/_types/orchestrator/types.d.ts +185 -0
- package/dist/_types/schemas/dispatch.d.ts +53 -0
- package/dist/_types/schemas/feature-workflow.d.ts +362 -0
- package/dist/_types/schemas/messages.d.ts +15 -0
- package/dist/_types/schemas/nol-assets.d.ts +955 -0
- package/dist/_types/schemas/nol-json.d.ts +2 -0
- package/dist/_types/schemas/nol.d.ts +3995 -0
- package/dist/_types/schemas/patch.d.ts +47 -0
- package/dist/_types/schemas/plan.d.ts +47 -0
- package/dist/_types/schemas/repoProfile.d.ts +116 -0
- package/dist/_types/schemas/retrieval.d.ts +44 -0
- package/dist/_types/schemas/task.d.ts +57 -0
- package/dist/_types/schemas/tools.d.ts +16 -0
- package/dist/_types/schemas/verification.d.ts +31 -0
- package/dist/api/py-embed.js +3353 -1829
- package/dist/assets/nol-checkpoint-editor.py +701 -0
- package/dist/assets/nol-gguf-checkpoint-editor.py +785 -0
- package/dist/assets/nol-gguf-control-reader.py +428 -0
- package/dist/assets/nol-gne-tools-worker.py +425 -0
- package/dist/assets/nol-gne-worker.py +1081 -0
- package/dist/assets/nol-lora-exporter.py +349 -0
- package/dist/assets/nol-pytorch-control-reader.py +470 -0
- package/dist/assets/nol-transformers-nnsight-worker.py +512 -0
- package/dist/assets/nol-transformers-peft-validation-worker.py +385 -0
- package/dist/assets/nol-transformers-peft-worker.py +488 -0
- package/dist/assets/nol-transformers-research-worker.py +472 -0
- package/dist/assets/nol-transformers-worker.py +920 -0
- package/dist/assets/nol-vllm-owned-worker.py +803 -0
- package/dist/assets/nol-vllm-runtime.py +695 -0
- package/dist/assets/nol-vllm-tokenizer.py +93 -0
- package/dist/assets/nol-vllm-worker.py +201 -0
- package/dist/computer-use/configured-planner.d.ts +37 -0
- package/dist/computer-use/configured-point.d.ts +35 -0
- package/dist/computer-use/host-session.d.ts +60 -0
- package/dist/computer-use/runner-ui-port.d.ts +37 -0
- package/dist/computer-use/session-review.d.ts +14 -0
- package/dist/computer-use/task-spec.d.ts +84 -0
- package/dist/discovery.d.ts +16 -2
- package/dist/index.js +2 -2
- package/dist/library.d.ts +94 -10
- package/dist/library.js +144003 -87414
- package/dist/memory-maintenance-worker.js +1676 -511
- package/dist/nol/cpu-control-reader-profile.d.ts +93 -0
- package/dist/nol/cpu-control-reader-service.d.ts +87 -0
- package/dist/nol/cuda-lease.d.ts +111 -0
- package/dist/nol/cuda-mutations.d.ts +34 -0
- package/dist/nol/export-runtime-config.d.ts +114 -0
- package/dist/nol/export-service.d.ts +143 -0
- package/dist/nol/facade.d.ts +147 -0
- package/dist/nol/gguf-cpu-control-reader-profile.d.ts +106 -0
- package/dist/nol/gguf-cpu-control-reader-service.d.ts +91 -0
- package/dist/nol/gguf-model-control-verifier.d.ts +120 -0
- package/dist/nol/gguf-parameter-inventory.d.ts +28 -0
- package/dist/nol/gne-adapter.d.ts +134 -0
- package/dist/nol/gne-agent-evaluation.d.ts +84 -0
- package/dist/nol/gne-profile.d.ts +124 -0
- package/dist/nol/gne-tools-profile.d.ts +148 -0
- package/dist/nol/gne-tools-transport.d.ts +194 -0
- package/dist/nol/model-actions.d.ts +662 -0
- package/dist/nol/model-control-verifier.d.ts +135 -0
- package/dist/nol/model-json-scorer.d.ts +13 -0
- package/dist/nol/model-runtime-config.d.ts +830 -0
- package/dist/nol/model-serving.d.ts +130 -0
- package/dist/nol/model-subject-adapter.d.ts +72 -0
- package/dist/nol/model-validation-factory.d.ts +113 -0
- package/dist/nol/neuronary-catalog.d.ts +130 -0
- package/dist/nol/orphan-custody.d.ts +72 -0
- package/dist/nol/peft-conformance.d.ts +48 -0
- package/dist/nol/peft-control-types.d.ts +137 -0
- package/dist/nol/peft-control-verifier.d.ts +8 -0
- package/dist/nol/peft-model-actions.d.ts +41 -0
- package/dist/nol/peft-model-authority.d.ts +146 -0
- package/dist/nol/peft-model-controls.d.ts +20 -0
- package/dist/nol/peft-model-host.d.ts +47 -0
- package/dist/nol/peft-model-profile.d.ts +161 -0
- package/dist/nol/peft-model-runtime-config.d.ts +174 -0
- package/dist/nol/peft-model-subject-adapter.d.ts +36 -0
- package/dist/nol/peft-validation.d.ts +105 -0
- package/dist/nol/persistent-parameter-inventory.d.ts +32 -0
- package/dist/nol/runtime.d.ts +100 -0
- package/dist/nol/sqlite-store.d.ts +80 -0
- package/dist/nol/transformers-adapter.d.ts +119 -0
- package/dist/nol/transformers-nnsight.d.ts +87 -0
- package/dist/nol/transformers-peft.d.ts +107 -0
- package/dist/nol/transformers-research.d.ts +114 -0
- package/dist/nol/variant-service.d.ts +143 -0
- package/dist/nol/variant-store.d.ts +51 -0
- package/dist/nol/vllm-actions.d.ts +774 -0
- package/dist/nol/vllm-adapter.d.ts +1473 -0
- package/dist/nol/vllm-authority.d.ts +55 -0
- package/dist/nol/vllm-conformance.d.ts +662 -0
- package/dist/nol/vllm-profile.d.ts +850 -0
- package/dist/nol/vllm-protocol.d.ts +1505 -0
- package/dist/nol/vllm-runtime-config.d.ts +120 -0
- package/dist/nol/vllm-runtime.d.ts +34 -0
- package/dist/nol/vllm-startup.d.ts +235 -0
- package/dist/omni-setup-worker.js +3433 -1909
- package/dist/service-version.d.ts +0 -1
- package/dist/tui/async-process.d.ts +27 -0
- package/dist/tui/native/worker.js +3 -1
- package/dist/tui/telegram-action-session-registry.d.ts +136 -0
- package/dist/tui/telegram-cognition-queue.d.ts +154 -0
- package/dist/tui/telegram-context-packet-v2.d.ts +99 -0
- package/dist/tui/telegram-input-ownership.d.ts +78 -0
- package/dist/tui/telegram-turn-contract-v2.d.ts +62 -0
- package/dist/update-worker-runtime.js +4216 -2603
- package/docs/DISCOVERY.json +389 -0
- package/docs/DISCOVERY.md +4 -0
- package/npm-shrinkwrap.json +28 -12
- package/package.json +3 -2
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Owned GNE tool completion with a strict custom Qwen XML decoder.
|
|
3
|
+
|
|
4
|
+
This is NOT an Ollama-native parser. Only fresh assistant rollout bytes enter
|
|
5
|
+
the decoder. The immutable GNE base supplies the same native kernel/lowering;
|
|
6
|
+
host-issued, newly bound independent conformance is still required for edits.
|
|
7
|
+
Stdlib-only until explicit load; never installs dependencies or starts a server.
|
|
8
|
+
"""
|
|
9
|
+
import ctypes
|
|
10
|
+
import hashlib
|
|
11
|
+
import importlib.util
|
|
12
|
+
import json
|
|
13
|
+
import math
|
|
14
|
+
import os
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
import re
|
|
17
|
+
import struct
|
|
18
|
+
import sys
|
|
19
|
+
|
|
20
|
+
VERSION = "omnius.nol.gne-tools.v1"
|
|
21
|
+
DECODER = "custom_qwen_xml_decoder_v1"
|
|
22
|
+
BASE_SHA = "0db5e4df7fb6553e6714f1b51bec40b1e4654373aa4c58623a6a9eeeb9e7de95"
|
|
23
|
+
TEMPLATE_SHA = "c3cf9e34abf4f9e36c2d72165aa9c132d3e2a725b6c2586aaa3a8af9d7a81041"
|
|
24
|
+
MODEL_FILE_SHA = "91804f5668d8e5deef47cced0e4ecff9d30da6e965418307d92f3a2822be4248"
|
|
25
|
+
SCHEMAS_SHA = "16342f4e8164325504a19d11fd7eebe0e25768677d478a92677259bbf14810b9"
|
|
26
|
+
NAMES = {"sandbox_read", "sandbox_write", "verify_sandbox", "task_complete"}
|
|
27
|
+
BASE_PATH = Path(__file__).resolve().parent / "nol-gne-worker.py"
|
|
28
|
+
if BASE_PATH.is_symlink() or hashlib.sha256(BASE_PATH.read_bytes()).hexdigest() != BASE_SHA:
|
|
29
|
+
raise RuntimeError("Frozen GNE companion identity changed")
|
|
30
|
+
spec = importlib.util.spec_from_file_location("_nol_frozen_gne_tools_base", BASE_PATH)
|
|
31
|
+
base = importlib.util.module_from_spec(spec)
|
|
32
|
+
spec.loader.exec_module(base)
|
|
33
|
+
require, fields, integer, number, Rejected = base.require, base.fields, base.integer, base.number, base.Rejected
|
|
34
|
+
ORIGINAL_RUNTIME = base.runtime_info
|
|
35
|
+
# Only this private module namespace changes. Inherited conformance and evidence
|
|
36
|
+
# import must bind the NEW executing worker, never label the old base proof as
|
|
37
|
+
# evidence for a different decoder/runtime. Both immutable hashes remain pins.
|
|
38
|
+
base.__file__ = __file__
|
|
39
|
+
base.WORKER_VERSION = VERSION
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def decoder_binding():
|
|
43
|
+
return {"id": DECODER, "templateDigest": TEMPLATE_SHA, "schemasDigest": SCHEMAS_SHA,
|
|
44
|
+
"source": "full-sha256-bound GGUF tokenizer.chat_template Qwen XML function/parameter protocol",
|
|
45
|
+
"thinking": False, "parallelCallLimit": 4, "streaming": False,
|
|
46
|
+
"mixedProseAndCalls": "unsupported", "hostTextToToolConversion": False}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def runtime_info(*args, **kwargs):
|
|
50
|
+
result = ORIGINAL_RUNTIME(*args, **kwargs)
|
|
51
|
+
result.update(schema="omnius.nol.gne-tools-build.v1", workerVersion=VERSION,
|
|
52
|
+
baseWorkerSha256=BASE_SHA, toolDecoder=decoder_binding())
|
|
53
|
+
return result
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
base.runtime_info = runtime_info
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def tools_inventory(tools):
|
|
60
|
+
require(type(tools) is list and len(tools) == 4, "Exactly the four frozen sandbox schemas are supported", "UNSUPPORTED")
|
|
61
|
+
schemas, names = {}, set()
|
|
62
|
+
for tool in tools:
|
|
63
|
+
fields(tool, ("type", "function"))
|
|
64
|
+
require(tool["type"] == "function", "Only function tools are supported", "UNSUPPORTED")
|
|
65
|
+
function = tool["function"]
|
|
66
|
+
fields(function, ("name", "parameters"), ("description",))
|
|
67
|
+
name = function["name"]
|
|
68
|
+
require(name in NAMES and name not in names, "Unknown or duplicate tool name", "UNSUPPORTED")
|
|
69
|
+
require("description" not in function or type(function["description"]) is str and len(function["description"].encode()) <= 1000, "Tool description exceeds bound")
|
|
70
|
+
names.add(name)
|
|
71
|
+
schemas[name] = function["parameters"]
|
|
72
|
+
require(base.digest_bytes(base.canonical_simple(schemas).encode()) == SCHEMAS_SHA,
|
|
73
|
+
"Sandbox schema inventory differs from frozen native boundary", "IDENTITY")
|
|
74
|
+
return schemas
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def validate(value, schema, depth=0):
|
|
78
|
+
require(depth <= 8, "Tool argument nesting exceeds bound", "MODEL_OUTPUT_INVALID")
|
|
79
|
+
kind = schema["type"]
|
|
80
|
+
if kind == "object":
|
|
81
|
+
require(type(value) is dict and len(value) <= 16, "Expected bounded argument object", "MODEL_OUTPUT_INVALID")
|
|
82
|
+
properties = schema["properties"]
|
|
83
|
+
require(set(schema.get("required", [])) <= value.keys() and not (value.keys() - properties.keys()), "Unknown, missing or duplicate argument", "MODEL_OUTPUT_INVALID")
|
|
84
|
+
for key, item in value.items(): validate(item, properties[key], depth + 1)
|
|
85
|
+
elif kind == "string":
|
|
86
|
+
require(type(value) is str and schema.get("minLength", 0) <= len(value) <= schema.get("maxLength", 1024), "String argument violates schema", "MODEL_OUTPUT_INVALID")
|
|
87
|
+
if "pattern" in schema: require(re.search(schema["pattern"], value) is not None, "String pattern mismatch", "MODEL_OUTPUT_INVALID")
|
|
88
|
+
elif kind == "integer":
|
|
89
|
+
require(type(value) is int and schema.get("minimum", -9007199254740991) <= value <= schema.get("maximum", 9007199254740991), "Integer argument violates schema", "MODEL_OUTPUT_INVALID")
|
|
90
|
+
else:
|
|
91
|
+
raise Rejected("UNSUPPORTED", "Frozen sandbox schema uses an unsupported primitive")
|
|
92
|
+
if "enum" in schema: require(value in schema["enum"], "Argument enum mismatch", "MODEL_OUTPUT_INVALID")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def decode_qwen(raw, schemas, finish_reason):
|
|
96
|
+
require(type(raw) is bytes and len(raw) <= 262144, "Fresh assistant output byte bound exceeded", "CAPACITY")
|
|
97
|
+
text = raw.decode("utf-8", "strict")
|
|
98
|
+
require(finish_reason == "stop", "Truncated completion cannot authorize tools", "MODEL_OUTPUT_INVALID")
|
|
99
|
+
require("```" not in text and "<think>" not in text and "</think>" not in text, "Fenced or thinking output cannot authorize tools", "MODEL_OUTPUT_INVALID")
|
|
100
|
+
stripped = raw.strip(b" \t\r\n")
|
|
101
|
+
if not stripped.startswith(b"<tool_call>"):
|
|
102
|
+
require(b"<tool_call" not in raw and b"<function=" not in raw and not stripped.startswith((b"{", b"[")), "Unframed JSON/XML is not a native call", "MODEL_OUTPUT_INVALID")
|
|
103
|
+
return {"content": text, "tool_calls": [], "callSpans": []}
|
|
104
|
+
calls, spans, seen, position = [], [], set(), 0
|
|
105
|
+
while position < len(raw):
|
|
106
|
+
while position < len(raw) and raw[position] in b" \t\r\n": position += 1
|
|
107
|
+
if position == len(raw): break
|
|
108
|
+
start = position
|
|
109
|
+
marker = b"<tool_call>\n<function="
|
|
110
|
+
require(raw.startswith(marker, position), "Mixed prose or malformed tool framing", "MODEL_OUTPUT_INVALID")
|
|
111
|
+
position += len(marker)
|
|
112
|
+
end = raw.find(b">\n", position)
|
|
113
|
+
require(end >= position and end - position <= 64, "Malformed native function name", "MODEL_OUTPUT_INVALID")
|
|
114
|
+
name = raw[position:end].decode("ascii", "strict")
|
|
115
|
+
require(name in schemas, "Unknown native function", "MODEL_OUTPUT_INVALID")
|
|
116
|
+
position, arguments = end + 2, {}
|
|
117
|
+
while not raw.startswith(b"</function>\n</tool_call>", position):
|
|
118
|
+
marker = b"<parameter="
|
|
119
|
+
require(raw.startswith(marker, position), "Malformed or missing function close", "MODEL_OUTPUT_INVALID")
|
|
120
|
+
position += len(marker)
|
|
121
|
+
end = raw.find(b">\n", position)
|
|
122
|
+
require(end >= position and end - position <= 64, "Malformed parameter name", "MODEL_OUTPUT_INVALID")
|
|
123
|
+
key = raw[position:end].decode("ascii", "strict")
|
|
124
|
+
require(key in schemas[name]["properties"] and key not in arguments, "Unknown or duplicate parameter", "MODEL_OUTPUT_INVALID")
|
|
125
|
+
position = end + 2
|
|
126
|
+
end = raw.find(b"\n</parameter>\n", position)
|
|
127
|
+
require(end >= position and end - position <= 65536, "Unterminated or oversized parameter", "MODEL_OUTPUT_INVALID")
|
|
128
|
+
value = raw[position:end].decode("utf-8", "strict")
|
|
129
|
+
require(not any(marker in value for marker in ("<tool_call", "<function=", "<parameter=", "</function>", "</tool_call>")), "Nested protocol control tags are unsupported", "MODEL_OUTPUT_INVALID")
|
|
130
|
+
schema = schemas[name]["properties"][key]
|
|
131
|
+
arguments[key] = value if schema["type"] == "string" else base.parse_json(value)
|
|
132
|
+
position = end + len(b"\n</parameter>\n")
|
|
133
|
+
position += len(b"</function>\n</tool_call>")
|
|
134
|
+
validate(arguments, schemas[name])
|
|
135
|
+
identity = base.canonical_gguf({"name": name, "arguments": arguments})
|
|
136
|
+
require(identity not in seen and len(calls) < 4, "Duplicate native call or batch bound exceeded", "MODEL_OUTPUT_INVALID")
|
|
137
|
+
seen.add(identity)
|
|
138
|
+
call_id = "gne-call-" + base.digest_bytes(raw[start:position])[:16] + "-" + str(start)
|
|
139
|
+
calls.append({"id": call_id, "type": "function", "function": {"name": name, "arguments": arguments}})
|
|
140
|
+
spans.append({"toolCallId": call_id, "startByte": start, "endByte": position})
|
|
141
|
+
return {"content": "", "tool_calls": calls, "callSpans": spans}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def validate_messages(messages, schemas):
|
|
145
|
+
require(type(messages) is list and 0 < len(messages) <= 256, "Bounded chat history required")
|
|
146
|
+
issued, consumed = {}, set()
|
|
147
|
+
for message in messages:
|
|
148
|
+
fields(message, ("role", "content"), ("tool_calls", "tool_call_id", "name"))
|
|
149
|
+
role = message["role"]
|
|
150
|
+
require(role in ("system", "user", "assistant", "tool") and (type(message["content"]) is str or role == "assistant" and message["content"] is None), "Plain native text history required", "UNSUPPORTED")
|
|
151
|
+
require(len((message["content"] or "").encode()) <= 1048576, "Chat content byte bound exceeded", "CAPACITY")
|
|
152
|
+
if role == "tool":
|
|
153
|
+
require(set(message) <= {"role", "content", "tool_call_id", "name"} and message.get("tool_call_id") in issued and message["tool_call_id"] not in consumed, "Tool result has no unique earlier native assistant call", "IDENTITY")
|
|
154
|
+
require("name" not in message or message["name"] == issued[message["tool_call_id"]], "Tool result name differs from its parent", "IDENTITY")
|
|
155
|
+
consumed.add(message["tool_call_id"])
|
|
156
|
+
elif role == "assistant" and "tool_calls" in message:
|
|
157
|
+
require(set(message) <= {"role", "content", "tool_calls"} and type(message["tool_calls"]) is list and 0 < len(message["tool_calls"]) <= 4, "Invalid typed assistant history")
|
|
158
|
+
for call in message["tool_calls"]:
|
|
159
|
+
fields(call, ("id", "type", "function"));fields(call["function"], ("name", "arguments"))
|
|
160
|
+
name, key = call["function"]["name"], call["id"]
|
|
161
|
+
require(call["type"] == "function" and type(key) is str and 0 < len(key) <= 200 and key not in issued and name in schemas, "Forged, duplicate or unsupported history call", "IDENTITY")
|
|
162
|
+
validate(call["function"]["arguments"], schemas[name]);issued[key] = name
|
|
163
|
+
else: require(set(message) == {"role", "content"}, "Role cannot carry native call metadata", "IDENTITY")
|
|
164
|
+
require(set(issued) == consumed, "Every earlier call needs exactly one tool result before the next model request", "IDENTITY")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class Runtime(base.Runtime):
|
|
168
|
+
def __init__(self):
|
|
169
|
+
super().__init__()
|
|
170
|
+
self.poisoned = self.closed = False
|
|
171
|
+
self.tool_limits = None
|
|
172
|
+
self.charged_tokens = self.turns = self.calls = 0
|
|
173
|
+
self.seen_cache_keys = set()
|
|
174
|
+
self._conformance_tools = None
|
|
175
|
+
|
|
176
|
+
def ready(self):
|
|
177
|
+
require(not self.poisoned and not self.closed, "Tool worker is closed or poisoned", "RESET")
|
|
178
|
+
super().ready()
|
|
179
|
+
|
|
180
|
+
def load(self, payload):
|
|
181
|
+
fields(payload, ("checkpointRoot", "artifactRoot", "workRoot", "gneRoot", "model", "binding", "gpuUuid", "identity", "dependencyLockPath", "limits", "toolLimits"))
|
|
182
|
+
require(not self.poisoned and not self.closed, "Tool worker cannot be reloaded", "RESET")
|
|
183
|
+
model = payload["model"]
|
|
184
|
+
require(model["chatTemplateDigest"] == TEMPLATE_SHA and len(model["files"]) == 1 and model["files"][0]["artifact"]["sha256"] == MODEL_FILE_SHA and model["architecture"] == {"family": "qwen35", "layers": 64, "hiddenSize": 5120}, "Only the exact approved original Qwen GGUF/template is admitted", "UNSUPPORTED")
|
|
185
|
+
limits = payload["toolLimits"]
|
|
186
|
+
fields(limits, ("maxTurns", "maxTotalTokens", "maxToolCalls", "maxOutputBytes"))
|
|
187
|
+
integer(limits["maxTurns"], 1, 16);integer(limits["maxTotalTokens"], 1, 2000000)
|
|
188
|
+
integer(limits["maxToolCalls"], 1, 32);integer(limits["maxOutputBytes"], 1, 262144)
|
|
189
|
+
result = super().load({key: value for key, value in payload.items() if key != "toolLimits"})
|
|
190
|
+
try:
|
|
191
|
+
from gne.engine import render_template, C
|
|
192
|
+
self.render_template, self.native_c = render_template, C
|
|
193
|
+
self.tool_limits = dict(limits)
|
|
194
|
+
result.update(implementation=VERSION, baseWorkerSha256=BASE_SHA, toolDecoder=decoder_binding(),
|
|
195
|
+
supportedRuntimeOperations=["NEURON_ADD"], canonicalEditsRequireFreshHostIssuedConformance=True,
|
|
196
|
+
nativeToolAuthority=False, noHiddenSelectorCalls=True)
|
|
197
|
+
return result
|
|
198
|
+
except BaseException:
|
|
199
|
+
self.poisoned = True
|
|
200
|
+
raise Rejected("LOAD_FAILED", "Native tool initialization failed", True)
|
|
201
|
+
|
|
202
|
+
def tokenize(self, payload):
|
|
203
|
+
self.ready()
|
|
204
|
+
if self._conformance_tools is not None and set(payload) == {"messages"}:
|
|
205
|
+
tools = self._conformance_tools
|
|
206
|
+
else:
|
|
207
|
+
fields(payload, ("messages", "tools", "toolChoice"))
|
|
208
|
+
require(payload["toolChoice"] == "auto", "Only native auto tool selection is supported", "UNSUPPORTED")
|
|
209
|
+
tools = payload["tools"]
|
|
210
|
+
schemas = tools_inventory(tools)
|
|
211
|
+
validate_messages(payload["messages"], schemas)
|
|
212
|
+
engine = self.session.engine
|
|
213
|
+
require(base.digest_bytes(engine.chat_template.encode()) == TEMPLATE_SHA, "Effective native tool template changed", "IDENTITY")
|
|
214
|
+
text = self.render_template(engine.chat_template, payload["messages"], tools=tools,
|
|
215
|
+
enable_thinking=False, add_generation_prompt=True,
|
|
216
|
+
bos_token=engine.token_text(self.native_c.llama_vocab_bos(engine.vocab)),
|
|
217
|
+
eos_token=engine.token_text(self.native_c.llama_vocab_eos(engine.vocab)))
|
|
218
|
+
ids = engine.tokenize_prompt(text)
|
|
219
|
+
require(0 < len(ids) <= self.limits["maxInputTokens"] and len(text.encode()) <= 1048576, "Native tool prompt exceeds budget", "CAPACITY")
|
|
220
|
+
return {"tokenIds": ids, "promptTokens": len(ids), "renderedPrompt": text,
|
|
221
|
+
"renderedPromptDigest": base.digest_bytes(text.encode()), "chatTemplateDigest": TEMPLATE_SHA,
|
|
222
|
+
"decoder": decoder_binding(), "schemasDigest": SCHEMAS_SHA}
|
|
223
|
+
|
|
224
|
+
def reset(self):
|
|
225
|
+
require(not self.poisoned and not self.closed, "Closed or poisoned tool worker cannot reset", "RESET")
|
|
226
|
+
try: return super().reset()
|
|
227
|
+
except BaseException:
|
|
228
|
+
self.poisoned = True
|
|
229
|
+
raise Rejected("RESET", "Native tool reset failed; retire this worker", True)
|
|
230
|
+
|
|
231
|
+
def profile(self, payload):
|
|
232
|
+
self.ready()
|
|
233
|
+
mode = payload.get("mode")
|
|
234
|
+
if mode == "tool_render_conformance":
|
|
235
|
+
fields(payload, ("mode", "messages", "tools", "toolChoice"))
|
|
236
|
+
result = self.tokenize({key: value for key, value in payload.items() if key != "mode"})
|
|
237
|
+
return {"schema": "omnius.nol.gne-tool-render-conformance.v1", "binding": self.binding,
|
|
238
|
+
"workerSha256": base.hash_file(Path(__file__).resolve())["sha256"], "baseWorkerSha256": BASE_SHA,
|
|
239
|
+
"tokenization": result, "inputTokens": 0, "sampledTokens": 0, "nativeForwards": 0,
|
|
240
|
+
"authority": "none"}
|
|
241
|
+
if mode == "neuron_add_conformance":
|
|
242
|
+
fields(payload, ("mode", "messages", "tools", "toolChoice", "operations", "maxTokens", "absoluteTolerance", "relativeTolerance"))
|
|
243
|
+
require(payload["toolChoice"] == "auto" and len(payload["operations"]) == 1, "One exact tool-context cell per bounded conformance capture", "CAPACITY")
|
|
244
|
+
tools_inventory(payload["tools"])
|
|
245
|
+
self._conformance_tools = payload["tools"]
|
|
246
|
+
try:
|
|
247
|
+
tokenized = self.tokenize({"messages": payload["messages"]})
|
|
248
|
+
reserved = 3 * len(tokenized["tokenIds"])
|
|
249
|
+
require(self.charged_tokens + reserved <= self.tool_limits["maxTotalTokens"], "Conformance token budget exhausted", "CAPACITY")
|
|
250
|
+
self.charged_tokens += reserved
|
|
251
|
+
return base.Runtime.conformance(self, {key: value for key, value in payload.items() if key not in ("tools", "toolChoice")})
|
|
252
|
+
finally:
|
|
253
|
+
self._conformance_tools = None
|
|
254
|
+
# Local numeric self-reports grant no canonical edit authority.
|
|
255
|
+
# Only a subsequent private-host-issued evidence import can.
|
|
256
|
+
for operation in payload["operations"]: self.validated_cells.pop(self.cell_key(operation), None)
|
|
257
|
+
if mode == "accept_neuron_add_conformance":
|
|
258
|
+
return base.Runtime.accept_conformance(self, payload)
|
|
259
|
+
raise Rejected("UNSUPPORTED", "Unknown explicit tool-worker profile mode")
|
|
260
|
+
|
|
261
|
+
def raw_output(self, engine, token_ids, stopped):
|
|
262
|
+
pieces, body, offset = [], [], 0
|
|
263
|
+
for index, token in enumerate(token_ids):
|
|
264
|
+
integer(token, 0, engine.n_vocab - 1)
|
|
265
|
+
size = 256
|
|
266
|
+
while True:
|
|
267
|
+
buffer = ctypes.create_string_buffer(size)
|
|
268
|
+
length = self.native_c.llama_token_to_piece(engine.vocab, token, buffer, size, 0, True)
|
|
269
|
+
if length >= 0: break
|
|
270
|
+
size = -length
|
|
271
|
+
require(0 < size <= 65536, "Native token piece exceeds byte budget", "CAPACITY")
|
|
272
|
+
piece = buffer.raw[:length]
|
|
273
|
+
terminal = stopped and index == len(token_ids) - 1
|
|
274
|
+
require(not terminal or engine.is_eog(token), "Native stop token is not EOG", "IDENTITY")
|
|
275
|
+
pieces.append({"index": index, "tokenId": token, "bytesHex": piece.hex(),
|
|
276
|
+
"startByte": offset, "endByte": offset if terminal else offset + len(piece), "terminalEog": terminal})
|
|
277
|
+
if not terminal:
|
|
278
|
+
offset += len(piece)
|
|
279
|
+
require(offset <= self.tool_limits["maxOutputBytes"], "Native raw output exceeds storage budget", "CAPACITY")
|
|
280
|
+
body.append(piece)
|
|
281
|
+
raw = b"".join(body)
|
|
282
|
+
visible = token_ids[:-1] if stopped else token_ids
|
|
283
|
+
require(engine.detokenize(visible, special=True) == raw.decode("utf-8", "strict"), "Native token pieces do not reconstruct exact output", "IDENTITY")
|
|
284
|
+
return raw, pieces
|
|
285
|
+
|
|
286
|
+
def generate(self, payload):
|
|
287
|
+
self.ready()
|
|
288
|
+
fields(payload, ("messages", "tools", "toolChoice", "recipe", "recipeIdentityJson", "cacheKeyDigest", "seed", "maxTokens", "decoding"))
|
|
289
|
+
schemas = tools_inventory(payload["tools"])
|
|
290
|
+
tokenized = self.tokenize({key: payload[key] for key in ("messages", "tools", "toolChoice")})
|
|
291
|
+
prompt = tokenized["tokenIds"]
|
|
292
|
+
maximum = integer(payload["maxTokens"], 1, self.limits["maxOutputTokens"])
|
|
293
|
+
seed = integer(payload["seed"], 0, 4294967295)
|
|
294
|
+
require(base.SHA.fullmatch(payload["cacheKeyDigest"] or ""), "Cold completion identity required")
|
|
295
|
+
require(payload["cacheKeyDigest"] not in self.seen_cache_keys, "A logical native completion cannot be dispatched twice", "IDENTITY")
|
|
296
|
+
decoding = payload["decoding"]
|
|
297
|
+
fields(decoding, ("temperature", "topP", "topK", "constrainedDecoding"))
|
|
298
|
+
require(number(decoding["temperature"]) == 0 and number(decoding["topP"]) == 1 and integer(decoding["topK"]) == 0 and decoding["constrainedDecoding"] == "none", "V1 tool evaluation is fixed greedy/no-grammar decoding", "UNSUPPORTED")
|
|
299
|
+
require(self.last_reset is not None and not self.created_loras, "Explicit clean reset required before each model turn", "RESET")
|
|
300
|
+
require(len(prompt) + maximum <= self.binding["contextLimit"] and self.turns < self.tool_limits["maxTurns"] and self.charged_tokens + len(prompt) + maximum <= self.tool_limits["maxTotalTokens"], "Native turn/context/total reservation budget exhausted", "CAPACITY")
|
|
301
|
+
recipe = payload["recipe"]
|
|
302
|
+
if recipe is None: require(payload["recipeIdentityJson"] is None, "Baseline cannot carry a recipe identity")
|
|
303
|
+
else:
|
|
304
|
+
base.verify_identity(payload["recipeIdentityJson"], {key: value for key, value in recipe.items() if key != "recipeDigest"}, recipe["recipeDigest"])
|
|
305
|
+
require(all(operation["operation"] == "NEURON_ADD" and operation["units"] == "raw" for operation in recipe["operations"]), "Only freshly validated raw neuron-add cells are supported", "UNSUPPORTED")
|
|
306
|
+
before, engine = self.last_reset, self.session.engine
|
|
307
|
+
context = engine.steer_ctx()
|
|
308
|
+
original_decode, original_prefill = engine._decode, engine.prefill
|
|
309
|
+
observed, counts = {}, {"prefillCalls": 0, "rolloutCalls": 0}
|
|
310
|
+
def decode(ctx, items):
|
|
311
|
+
require(ctx is context and all(item[2] == 0 and 0 <= item[1] < len(prompt) + maximum - 1 and item[1] not in observed for item in items), "Unexpected or repeated native decode position", "CAPACITY")
|
|
312
|
+
require(len({item[1] for item in items}) == len(items), "Duplicate position inside native batch", "CAPACITY")
|
|
313
|
+
for token, position, sequence, logits in items:
|
|
314
|
+
require(position >= len(prompt) or token == prompt[position], "Native prefill token differs from rendered request", "IDENTITY")
|
|
315
|
+
result = original_decode(ctx, items)
|
|
316
|
+
for token, position, sequence, logits in items: observed[position] = token
|
|
317
|
+
return result
|
|
318
|
+
def prefill(ctx, sequences, **kwargs):
|
|
319
|
+
require(counts["prefillCalls"] == 0 and ctx is context and sequences == [prompt], "Hidden selector or second prefill is prohibited", "CAPACITY")
|
|
320
|
+
counts["prefillCalls"] += 1
|
|
321
|
+
return original_prefill(ctx, sequences, **kwargs)
|
|
322
|
+
self.turns += 1
|
|
323
|
+
self.seen_cache_keys.add(payload["cacheKeyDigest"])
|
|
324
|
+
reservation = len(prompt) + maximum
|
|
325
|
+
self.charged_tokens += reservation
|
|
326
|
+
try:
|
|
327
|
+
vectors, lora, operations = self.install(recipe)
|
|
328
|
+
engine.set_lora(context, lora);engine.set_cvec(context, vectors or None)
|
|
329
|
+
engine._decode, engine.prefill = decode, prefill
|
|
330
|
+
prefilled = engine.prefill(context, [prompt])
|
|
331
|
+
counts["rolloutCalls"] += 1
|
|
332
|
+
sampling = self.Sampling(temperature=0, top_p=1, top_k=0, min_p=0, presence_penalty=0, seed=seed, dry_multiplier=0)
|
|
333
|
+
rollout = engine.generate_greedy(context, [prompt], max_tokens=maximum, top_k=min(5, engine.n_vocab), prefilled=prefilled, sampling=sampling)[0]
|
|
334
|
+
ids = rollout.token_ids
|
|
335
|
+
require(type(ids) is list and 0 < len(ids) <= maximum and counts == {"prefillCalls": 1, "rolloutCalls": 1}, "Native rollout count or token budget changed", "IDENTITY")
|
|
336
|
+
expected = prompt + ids[:-1]
|
|
337
|
+
require(sorted(observed) == list(range(len(expected))) and all(observed[index] == token for index, token in enumerate(expected)), "Native decode ledger omits or repeats actual work", "IDENTITY")
|
|
338
|
+
stopped = rollout.finish == "eog"
|
|
339
|
+
raw, pieces = self.raw_output(engine, ids, stopped)
|
|
340
|
+
finish = "stop" if stopped else "length"
|
|
341
|
+
try:
|
|
342
|
+
message = decode_qwen(raw, schemas, finish)
|
|
343
|
+
require(self.calls + len(message["tool_calls"]) <= self.tool_limits["maxToolCalls"], "Total native tool-call budget exceeded", "CAPACITY")
|
|
344
|
+
for call, span in zip(message["tool_calls"], message["callSpans"]):
|
|
345
|
+
call_id = "gne-call-" + base.digest_bytes((payload["cacheKeyDigest"] + ":" + str(span["startByte"]) + ":" + str(span["endByte"]) + ":").encode() + raw)[:32]
|
|
346
|
+
call["id"] = span["toolCallId"] = call_id
|
|
347
|
+
covered = [piece["index"] for piece in pieces if not piece["terminalEog"] and piece["endByte"] > span["startByte"] and piece["startByte"] < span["endByte"]]
|
|
348
|
+
require(covered, "Native call has no generated token span", "IDENTITY")
|
|
349
|
+
span.update(startToken=covered[0], endToken=covered[-1] + 1)
|
|
350
|
+
self.calls += len(message["tool_calls"])
|
|
351
|
+
status, failure = "decoded", None
|
|
352
|
+
except (Rejected, UnicodeError, ValueError) as error:
|
|
353
|
+
message = {"content": "", "tool_calls": [], "callSpans": []}
|
|
354
|
+
status, failure = "invalid_model_output", {"code": "MODEL_OUTPUT_INVALID", "message": str(error)[:1000]}
|
|
355
|
+
self.charged_tokens -= maximum - len(ids)
|
|
356
|
+
engine._decode, engine.prefill = original_decode, original_prefill
|
|
357
|
+
after = self.reset()
|
|
358
|
+
return {"schema": "omnius.nol.gne-native-tool-completion.v1", "status": status,
|
|
359
|
+
"message": {"role": "assistant", "content": message["content"], "tool_calls": message["tool_calls"]},
|
|
360
|
+
"decoder": {**decoder_binding(), "callSpans": message["callSpans"], "failure": failure},
|
|
361
|
+
"rawOutputHex": raw.hex(), "rawOutputSha256": base.digest_bytes(raw), "tokenPieces": pieces,
|
|
362
|
+
"promptTokenIds": prompt, "tokenIds": ids, "renderedPrompt": tokenized["renderedPrompt"],
|
|
363
|
+
"renderedPromptDigest": tokenized["renderedPromptDigest"], "usage": {"promptTokens": len(prompt), "completionTokens": len(ids)},
|
|
364
|
+
"finishReason": finish, "execution": {**counts, "decodePositions": sorted(observed), "usageAttested": True, "cumulativeChargedTokens": self.charged_tokens},
|
|
365
|
+
"native": {"binding": self.binding, "implementation": VERSION, "workerSha256": base.hash_file(Path(__file__).resolve())["sha256"], "baseWorkerSha256": BASE_SHA,
|
|
366
|
+
"operations": operations, "editedPositions": {item["operationId"]: sorted(observed) for item in operations},
|
|
367
|
+
"recipeDigest": recipe["recipeDigest"] if recipe else None, "cacheKeyDigest": payload["cacheKeyDigest"],
|
|
368
|
+
"resetBefore": before, "resetAfter": after, "usesCache": True, "cacheScope": "within_model_request_only", "capabilityAuthority": "none"}}
|
|
369
|
+
except BaseException:
|
|
370
|
+
engine._decode, engine.prefill = original_decode, original_prefill
|
|
371
|
+
try: self.reset()
|
|
372
|
+
except BaseException:
|
|
373
|
+
self.poisoned = True
|
|
374
|
+
raise Rejected("RESET", "Tool generation failed to restore native state", True)
|
|
375
|
+
raise
|
|
376
|
+
|
|
377
|
+
def close(self):
|
|
378
|
+
require(not self.poisoned, "Poisoned worker must retire without fallback", "RESET")
|
|
379
|
+
try:
|
|
380
|
+
result = super().close();self.closed = True;return result
|
|
381
|
+
except BaseException:
|
|
382
|
+
self.poisoned = True
|
|
383
|
+
raise Rejected("RESET", "Native tool close failed; retire process", True)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def serve():
|
|
387
|
+
sys.stdout = sys.stderr
|
|
388
|
+
require(0 < base.MAX_FRAME <= 67108864 and all(base.OWNER.values()), "Owned worker scope and frame limit required")
|
|
389
|
+
runtime, sequence = Runtime(), 0
|
|
390
|
+
while True:
|
|
391
|
+
header = base.read_exact(sys.stdin.buffer, 4)
|
|
392
|
+
if header is None: break
|
|
393
|
+
size = struct.unpack(">I", header)[0];require(0 < size <= base.MAX_FRAME, "Frame bound exceeded", "CAPACITY")
|
|
394
|
+
raw = base.read_exact(sys.stdin.buffer, size);require(raw is not None, "Truncated frame")
|
|
395
|
+
request = base.parse_json(raw.decode("utf-8", "strict"))
|
|
396
|
+
fields(request, ("schema", "kind", "sessionId", "jobId", "ownerId", "generation", "id", "action", "payload"))
|
|
397
|
+
require(request["schema"] == base.PROTOCOL and request["kind"] == "request" and all(request[key] == value for key, value in base.OWNER.items()) and request["id"] == sequence + 1, "Owner/generation/sequence mismatch", "IDENTITY")
|
|
398
|
+
sequence += 1
|
|
399
|
+
response = {key: request[key] for key in ("schema", "sessionId", "jobId", "ownerId", "generation", "id", "action")};response["kind"] = "response"
|
|
400
|
+
closing = False
|
|
401
|
+
try:
|
|
402
|
+
action, payload = request["action"], request["payload"]
|
|
403
|
+
if action == "hello":
|
|
404
|
+
fields(payload, ())
|
|
405
|
+
result = {"protocol": base.PROTOCOL, "workerVersion": VERSION, "workerSha256": base.hash_file(Path(__file__).resolve())["sha256"], "baseWorkerSha256": BASE_SHA,
|
|
406
|
+
"pid": os.getpid(), "loaded": runtime.loaded, "nativeImported": any(name == "gne" or name.startswith("gne.") or name.startswith("llama_cpp") for name in sys.modules), "toolDecoder": decoder_binding(), "capabilityAuthority": "none"}
|
|
407
|
+
elif action in ("inspect", "load", "tokenize", "generate", "profile"):
|
|
408
|
+
result = getattr(runtime, action)(payload)
|
|
409
|
+
elif action == "confirm_placement": result = runtime.confirm(payload)
|
|
410
|
+
elif action in ("reset", "close"):
|
|
411
|
+
fields(payload, ());result = getattr(runtime, action)();closing = action == "close"
|
|
412
|
+
else: raise Rejected("UNSUPPORTED", "Unknown tool worker action")
|
|
413
|
+
response["result"] = result
|
|
414
|
+
except Rejected as error:
|
|
415
|
+
closing = error.fatal or runtime.poisoned or action in ("load", "close")
|
|
416
|
+
response["error"] = {"code": error.code, "message": str(error)[:4096], "fatal": closing}
|
|
417
|
+
except BaseException as error:
|
|
418
|
+
closing = True;response["error"] = {"code": "RUNTIME_FAILURE", "message": type(error).__name__, "fatal": True}
|
|
419
|
+
body = json.dumps(response, ensure_ascii=False, separators=(",", ":"), allow_nan=False).encode()
|
|
420
|
+
require(len(body) <= base.MAX_FRAME, "Response frame bound exceeded", "CAPACITY")
|
|
421
|
+
base.WIRE_OUT.write(struct.pack(">I", len(body)) + body);base.WIRE_OUT.flush()
|
|
422
|
+
if closing: return
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
if __name__ == "__main__": serve()
|