@konneal/engine 0.1.0
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/LICENSE +29 -0
- package/README.md +13 -0
- package/dist/admin.d.ts +26 -0
- package/dist/ai.d.ts +6 -0
- package/dist/anchors.d.ts +6 -0
- package/dist/answercache.d.ts +22 -0
- package/dist/ask.d.ts +5 -0
- package/dist/auth.d.ts +12 -0
- package/dist/bubble.d.ts +14 -0
- package/dist/chunk-LLWPT2XV.js +49 -0
- package/dist/chunk-MB74PTRM.js +114 -0
- package/dist/chunk-WOGQM7DJ.js +197 -0
- package/dist/chunk-WWNCWKKC.js +42 -0
- package/dist/completion.d.ts +5 -0
- package/dist/config.d.ts +154 -0
- package/dist/config.js +37 -0
- package/dist/context.d.ts +115 -0
- package/dist/conversations.d.ts +5 -0
- package/dist/drafts.d.ts +129 -0
- package/dist/env.d.ts +57 -0
- package/dist/faithfulness.d.ts +5 -0
- package/dist/grader.d.ts +3 -0
- package/dist/graph.d.ts +13 -0
- package/dist/hybrid.d.ts +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5373 -0
- package/dist/internal_gateway.d.ts +14 -0
- package/dist/lexical.d.ts +7 -0
- package/dist/livedata.d.ts +77 -0
- package/dist/memories.d.ts +10 -0
- package/dist/modelplane.d.ts +61 -0
- package/dist/oidc.d.ts +73 -0
- package/dist/pipeline.d.ts +57 -0
- package/dist/profile.d.ts +2 -0
- package/dist/profile.gen.d.ts +70 -0
- package/dist/profile.js +8 -0
- package/dist/projects.d.ts +8 -0
- package/dist/prompts/conversational.md +8 -0
- package/dist/prompts/enrichment.md +3 -0
- package/dist/prompts/faithfulness.md +1 -0
- package/dist/prompts/grader.md +5 -0
- package/dist/prompts/listwise.md +3 -0
- package/dist/prompts/precision.md +1 -0
- package/dist/prompts/reflect.md +1 -0
- package/dist/prompts/relevancy.md +1 -0
- package/dist/prompts/research.md +10 -0
- package/dist/prompts/section-summary.md +5 -0
- package/dist/prompts/summarize.md +1 -0
- package/dist/prompts/system.md +18 -0
- package/dist/prompts/understanding.md +17 -0
- package/dist/quota.d.ts +13 -0
- package/dist/reflect.d.ts +5 -0
- package/dist/refs.d.ts +40 -0
- package/dist/refusal.d.ts +9 -0
- package/dist/refusal.js +9 -0
- package/dist/requestScope.d.ts +26 -0
- package/dist/requestScope.js +10 -0
- package/dist/research.d.ts +8 -0
- package/dist/search.d.ts +4 -0
- package/dist/selfquery.d.ts +7 -0
- package/dist/session.d.ts +1 -0
- package/dist/share.d.ts +2 -0
- package/dist/structural.d.ts +27 -0
- package/dist/tablecontext.d.ts +11 -0
- package/dist/understand.d.ts +11 -0
- package/dist/understandContract.d.ts +29 -0
- package/dist/verdict.d.ts +24 -0
- package/docs/API.md +451 -0
- package/docs/ARCHITECTURE.md +302 -0
- package/docs/AUDIT-2026-08-24.md +71 -0
- package/docs/CONTRIBUTOR-AUDIT-2026-08-25.md +147 -0
- package/docs/INGEST-ARCHITECTURE.md +158 -0
- package/docs/MCP.md +92 -0
- package/docs/METANORMA-AI-SERIALIZATION.md +247 -0
- package/docs/MKO-EXPORT-PIPELINE.md +147 -0
- package/docs/REDESIGN-NORMATIVE-RAG-ETSI.md +485 -0
- package/docs/RESEARCH-SOTA-2026.md +243 -0
- package/docs/ROADMAP-SOTA.md +130 -0
- package/docs/SOTA-STAGE-SPECS.md +509 -0
- package/docs/annealment/F1-verdict.md +27 -0
- package/docs/annealment/F10-notes.md +19 -0
- package/docs/annealment/F11-composition.md +17 -0
- package/docs/annealment/F12-passport.md +17 -0
- package/docs/annealment/F2-counterfactual.md +20 -0
- package/docs/annealment/F3-absence.md +21 -0
- package/docs/annealment/F4-instance.md +18 -0
- package/docs/annealment/F5-workflow.md +21 -0
- package/docs/annealment/F6-impact.md +21 -0
- package/docs/annealment/F7-editions.md +18 -0
- package/docs/annealment/F8-selfverify.md +19 -0
- package/docs/annealment/F9-projection-qa.md +17 -0
- package/docs/annealment/L0-locate.md +19 -0
- package/docs/annealment/L1-extract.md +18 -0
- package/docs/annealment/L2-nomenclature.md +22 -0
- package/docs/annealment/L3-geometry.md +23 -0
- package/docs/annealment/L4-composition.md +21 -0
- package/docs/annealment/L5-cross-standard.md +20 -0
- package/docs/annealment/L6-diachrony.md +21 -0
- package/docs/annealment/L7-perception.md +20 -0
- package/docs/annealment/L8-computation.md +22 -0
- package/docs/annealment/L9-instance-process.md +23 -0
- package/docs/annealment/README.md +10 -0
- package/docs/guidelines-metanorma-ai-programme.md +279 -0
- package/docs/identity-onboarding-rag.md +65 -0
- package/docs/identity-service.md +219 -0
- package/docs/knowledge-annealment.md +273 -0
- package/docs/konneal-extraction-plan.md +481 -0
- package/docs/metanorma-for-ai.md +270 -0
- package/docs/mirror-plan.md +36 -0
- package/docs/multi-sdo-architecture.md +191 -0
- package/docs/paper-annealment-comparison.md +259 -0
- package/docs/paper-assets/architecture.svg +94 -0
- package/docs/paper-assets/contract-v2.svg +94 -0
- package/docs/paper-assets/mko-ingest.svg +91 -0
- package/docs/paper-oiml-bulletin.md +402 -0
- package/docs/paper-oiml-bulletin.mdx +419 -0
- package/docs/product-branding-options.md +172 -0
- package/docs/projects-design.md +88 -0
- package/docs/sota-mechanisms.md +184 -0
- package/docs/spec-api.md +77 -0
- package/docs/spec-pipeline.md +126 -0
- package/docs/vector-adapter.md +88 -0
- package/package.json +70 -0
- package/profile/corpora.yaml +5 -0
- package/profile/datasets.yaml +14 -0
- package/profile/prompts.yaml +5 -0
- package/profile/publisher.yaml +17 -0
- package/profile/retrieval.yaml +1 -0
- package/profile/sources.yaml +5 -0
- package/profile/ui.yaml +7 -0
- package/scripts/gen_profile.mjs +33 -0
- package/workers/shared/ai.ts +21 -0
- package/workers/shared/auth.ts +16 -0
- package/workers/shared/chunk.ts +108 -0
- package/workers/shared/oidc.ts +312 -0
- package/workers/shared/router.ts +45 -0
- package/workers/shared/session.ts +104 -0
- package/workers/worker_internal/src/index.ts +157 -0
- package/workers/worker_internal/tsconfig.json +15 -0
- package/workers/worker_internal/wrangler.toml +32 -0
- package/workers/worker_mcp/src/index.ts +175 -0
- package/workers/worker_mcp/tsconfig.json +13 -0
- package/workers/worker_mcp/wrangler.toml +18 -0
- package/workers/worker_public/migrations/0002_conversations.sql +22 -0
- package/workers/worker_public/migrations/0003_shared_conversations.sql +9 -0
- package/workers/worker_public/migrations/0004_graph.sql +16 -0
- package/workers/worker_public/migrations/0005_documents.sql +19 -0
- package/workers/worker_public/migrations/0006_conversation_entities.sql +11 -0
- package/workers/worker_public/migrations/0007_chunks_fts.sql +43 -0
- package/workers/worker_public/migrations/0008_unit_payloads.sql +15 -0
- package/workers/worker_public/migrations/0009_chunks_unit.sql +8 -0
- package/workers/worker_public/migrations/0009_message_context.sql +7 -0
- package/workers/worker_public/migrations/0010_model_nodes.sql +33 -0
- package/workers/worker_public/migrations/0011_schema_union.sql +38 -0
- package/workers/worker_public/migrations/0012_memories.sql +15 -0
- package/workers/worker_public/migrations/0013_projects.sql +21 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2021-11-03/index.d.ts +16306 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2021-11-03/index.ts +16261 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-01-31/index.d.ts +16373 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-01-31/index.ts +16328 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-03-21/index.d.ts +16382 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-03-21/index.ts +16337 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-08-04/index.d.ts +16383 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-08-04/index.ts +16338 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-10-31/index.d.ts +16403 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-10-31/index.ts +16358 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-11-30/index.d.ts +16408 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2022-11-30/index.ts +16363 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2023-03-01/index.d.ts +16414 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2023-03-01/index.ts +16369 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2023-07-01/index.d.ts +16414 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/2023-07-01/index.ts +16369 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/README.md +135 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/entrypoints.svg +53 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/experimental/index.d.ts +17095 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/experimental/index.ts +17050 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/index.d.ts +16306 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/index.ts +16261 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/latest/index.d.ts +16447 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/latest/index.ts +16402 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/oldest/index.d.ts +16306 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/oldest/index.ts +16261 -0
- package/workers/worker_public/node_modules/@cloudflare/workers-types/package.json +11 -0
- package/workers/worker_public/package.json +13 -0
- package/workers/worker_public/prompts/conversational.md +8 -0
- package/workers/worker_public/prompts/enrichment.md +3 -0
- package/workers/worker_public/prompts/faithfulness.md +1 -0
- package/workers/worker_public/prompts/grader.md +5 -0
- package/workers/worker_public/prompts/listwise.md +3 -0
- package/workers/worker_public/prompts/precision.md +1 -0
- package/workers/worker_public/prompts/reflect.md +1 -0
- package/workers/worker_public/prompts/relevancy.md +1 -0
- package/workers/worker_public/prompts/research.md +10 -0
- package/workers/worker_public/prompts/section-summary.md +5 -0
- package/workers/worker_public/prompts/summarize.md +1 -0
- package/workers/worker_public/prompts/system.md +18 -0
- package/workers/worker_public/prompts/understanding.md +17 -0
- package/workers/worker_public/public/app.js +166 -0
- package/workers/worker_public/public/index.html +48 -0
- package/workers/worker_public/public/style.css +147 -0
- package/workers/worker_public/schema.sql +248 -0
- package/workers/worker_public/src/admin.ts +358 -0
- package/workers/worker_public/src/ai.ts +71 -0
- package/workers/worker_public/src/anchors.ts +41 -0
- package/workers/worker_public/src/answercache.ts +72 -0
- package/workers/worker_public/src/ask.ts +1094 -0
- package/workers/worker_public/src/auth.ts +252 -0
- package/workers/worker_public/src/bubble.ts +111 -0
- package/workers/worker_public/src/completion.ts +75 -0
- package/workers/worker_public/src/config.ts +238 -0
- package/workers/worker_public/src/context.ts +238 -0
- package/workers/worker_public/src/conversations.ts +162 -0
- package/workers/worker_public/src/drafts.ts +497 -0
- package/workers/worker_public/src/env.ts +90 -0
- package/workers/worker_public/src/faithfulness.ts +63 -0
- package/workers/worker_public/src/grader.ts +89 -0
- package/workers/worker_public/src/graph.ts +63 -0
- package/workers/worker_public/src/hybrid.ts +77 -0
- package/workers/worker_public/src/index.ts +441 -0
- package/workers/worker_public/src/internal_gateway.ts +41 -0
- package/workers/worker_public/src/lexical.ts +86 -0
- package/workers/worker_public/src/lib/hit.ts +4 -0
- package/workers/worker_public/src/lib/http.ts +83 -0
- package/workers/worker_public/src/lib/router.ts +4 -0
- package/workers/worker_public/src/livedata.ts +334 -0
- package/workers/worker_public/src/memories.ts +81 -0
- package/workers/worker_public/src/modelplane.ts +213 -0
- package/workers/worker_public/src/oidc.ts +333 -0
- package/workers/worker_public/src/pipeline.ts +377 -0
- package/workers/worker_public/src/ports/blobs.ts +7 -0
- package/workers/worker_public/src/ports/cloudflare/adapters.ts +177 -0
- package/workers/worker_public/src/ports/kv.ts +8 -0
- package/workers/worker_public/src/ports/model.ts +28 -0
- package/workers/worker_public/src/ports/runtime.ts +13 -0
- package/workers/worker_public/src/ports/store.ts +20 -0
- package/workers/worker_public/src/ports/vector.ts +26 -0
- package/workers/worker_public/src/profile.gen.ts +101 -0
- package/workers/worker_public/src/profile.ts +16 -0
- package/workers/worker_public/src/projects.ts +108 -0
- package/workers/worker_public/src/prompts.d.ts +6 -0
- package/workers/worker_public/src/quota.ts +54 -0
- package/workers/worker_public/src/reflect.ts +67 -0
- package/workers/worker_public/src/refs.ts +107 -0
- package/workers/worker_public/src/refusal.ts +65 -0
- package/workers/worker_public/src/requestScope.ts +71 -0
- package/workers/worker_public/src/research.ts +126 -0
- package/workers/worker_public/src/search.ts +56 -0
- package/workers/worker_public/src/selfquery.ts +25 -0
- package/workers/worker_public/src/session.ts +4 -0
- package/workers/worker_public/src/share.ts +53 -0
- package/workers/worker_public/src/stages/conceptGraph.ts +68 -0
- package/workers/worker_public/src/stages/conceptSteer.ts +39 -0
- package/workers/worker_public/src/stages/corpusScope.ts +25 -0
- package/workers/worker_public/src/stages/dedup.ts +10 -0
- package/workers/worker_public/src/stages/dense.ts +73 -0
- package/workers/worker_public/src/stages/diversity.ts +33 -0
- package/workers/worker_public/src/stages/editionCover.ts +63 -0
- package/workers/worker_public/src/stages/editionSteer.ts +88 -0
- package/workers/worker_public/src/stages/familyBoost.ts +22 -0
- package/workers/worker_public/src/stages/federate.ts +22 -0
- package/workers/worker_public/src/stages/glossary.ts +65 -0
- package/workers/worker_public/src/stages/graphLane.ts +31 -0
- package/workers/worker_public/src/stages/hyde.ts +29 -0
- package/workers/worker_public/src/stages/index.ts +69 -0
- package/workers/worker_public/src/stages/lexicalUnion.ts +21 -0
- package/workers/worker_public/src/stages/multiQuery.ts +57 -0
- package/workers/worker_public/src/stages/overviewDemote.ts +14 -0
- package/workers/worker_public/src/stages/poolOpen.ts +10 -0
- package/workers/worker_public/src/stages/propagate.ts +15 -0
- package/workers/worker_public/src/stages/rerank.ts +47 -0
- package/workers/worker_public/src/stages/seal.ts +16 -0
- package/workers/worker_public/src/stages/sectionDescent.ts +61 -0
- package/workers/worker_public/src/stages/stdRefNudge.ts +35 -0
- package/workers/worker_public/src/stages/subQuery.ts +42 -0
- package/workers/worker_public/src/stages/termNudge.ts +24 -0
- package/workers/worker_public/src/stages/typedPin.ts +131 -0
- package/workers/worker_public/src/stages/types.ts +112 -0
- package/workers/worker_public/src/stages/windowFloor.ts +23 -0
- package/workers/worker_public/src/structural.ts +171 -0
- package/workers/worker_public/src/tablecontext.ts +41 -0
- package/workers/worker_public/src/understand.ts +72 -0
- package/workers/worker_public/src/understandContract.ts +67 -0
- package/workers/worker_public/src/verdict.ts +255 -0
- package/workers/worker_public/tsconfig.json +18 -0
- package/workers/worker_public/wrangler.toml +104 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Konneal
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Konneal Engine
|
|
2
|
+
|
|
3
|
+
The publisher-agnostic serving layer for standards intelligence: hybrid
|
|
4
|
+
retrieval over clause-structured corpora, citation-grounded answers,
|
|
5
|
+
typed tables/formulas/figures, conformance checking by execution, and
|
|
6
|
+
the measurement gates that keep it honest. Konneal builds the databases
|
|
7
|
+
and serves the API; publishers own their content, profile and frontend.
|
|
8
|
+
|
|
9
|
+
Architecture and plan: docs/konneal-extraction-plan.md (and
|
|
10
|
+
docs/multi-sdo-architecture.md). The reference deployment is OIML SMART
|
|
11
|
+
AI (oimlsmart/ai — the reference profile). This repository was born
|
|
12
|
+
from it with history preserved (git filter-repo over the engine
|
|
13
|
+
subtrees); the README seed commit was replaced by the extraction.
|
package/dist/admin.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Env } from "./env";
|
|
2
|
+
/** Contextual enrichment (quality-first lane): for each chunk, write a
|
|
3
|
+
* situating context (KV-cached per chunk id), embed context+text, and
|
|
4
|
+
* upsert in place — the enrichment persists into every future retrieval
|
|
5
|
+
* of that chunk. Driven by ingest/enrich.py in resumable batches. */
|
|
6
|
+
export declare function handleEnrich(env: Env, ctx: ExecutionContext, req: Request): Promise<Response>;
|
|
7
|
+
/** Section-summary units (FABLE/BEAR multi-granularity, arXiv:2601.18116):
|
|
8
|
+
* the corpus's clause chunks start at depth 2 ("3.1"), so the tree has no
|
|
9
|
+
* depth-1 nodes. This endpoint writes them: a summary of each top-level
|
|
10
|
+
* clause generated from its child chunks' excerpts (quality-first lane,
|
|
11
|
+
* KV-cached per unit id), embedded as toc-path ⊕ summary à la FABLE's
|
|
12
|
+
* internal-node indexing, and upserted as a navigation node — serving
|
|
13
|
+
* descends from it to quotable leaf clauses (pipeline.ts section
|
|
14
|
+
* descent). Credential, batching and ledger mirror /admin/enrich. */
|
|
15
|
+
export declare function handleSectionUnit(env: Env, ctx: ExecutionContext, req: Request): Promise<Response>;
|
|
16
|
+
/** Ops access to the Vectorize binding (get/upsert by id) for offline
|
|
17
|
+
* passes like embedding smoothing (G-ETSI-4) — the binding is the
|
|
18
|
+
* credential, admin-token gated exactly like /admin/enrich. */
|
|
19
|
+
/** One-time figure captioning (TODO.remaining/03): fetch the unit's asset
|
|
20
|
+
* from R2, describe it with the vision-capable answer model, store the
|
|
21
|
+
* description into unit_payloads. Admin-gated; idempotent. */
|
|
22
|
+
export declare function handleCaption(env: Env, req: Request): Promise<Response>;
|
|
23
|
+
export declare function handleVectors(env: Env, req: Request): Promise<Response>;
|
|
24
|
+
export declare function handleJudge(env: Env, req: Request): Promise<Response>;
|
|
25
|
+
export declare function handleCreateKey(env: Env, req: Request): Promise<Response>;
|
|
26
|
+
export declare function handleListKeys(env: Env, req: Request): Promise<Response>;
|
package/dist/ai.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ModelRunner } from "./ports/model.ts";
|
|
2
|
+
type AnyAi = ModelRunner;
|
|
3
|
+
export declare function embed(ai: ModelRunner, _model: string, text: string): Promise<number[]>;
|
|
4
|
+
export declare function rerank(ai: AnyAi, model: string, query: string, texts: string[]): Promise<number[] | null>;
|
|
5
|
+
export declare function generateOnce(env: any, model: string, messages: any[], effort?: string): Promise<string | null>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Kv } from "./ports/kv.ts";
|
|
2
|
+
/** KV key carrying the corpus-generation stamp (the house sys:
|
|
3
|
+
* convention, cf. sys:generation). Absent = "0". */
|
|
4
|
+
export declare const CORPUS_GEN_KEY = "sys:corpus_gen";
|
|
5
|
+
/** Read the corpus-generation stamp; a KV failure fails open to "0"
|
|
6
|
+
* (the cache keeps working, generation pinning degrades to deploy-only). */
|
|
7
|
+
export declare function corpusGen(cache: Pick<Kv, "get">): Promise<string>;
|
|
8
|
+
/** The fresh (regenerate) flag: the JSON boolean, plus the string/1
|
|
9
|
+
* forms a caller may serialize. Anything else is not a bypass request. */
|
|
10
|
+
export declare function freshRequested(body: any): boolean;
|
|
11
|
+
/** The exact cache's hash input: the query lowercased and whitespace-
|
|
12
|
+
* folded, plus the output-language pin (a pinned language gets its own
|
|
13
|
+
* entry). Hashed with sha256Hex (./config) at the call site. */
|
|
14
|
+
/** `salt`: per-request context that materially changes the answer — the
|
|
15
|
+
* dataset scope selection and the memory-file selection. Requests that
|
|
16
|
+
* differ ONLY in salt share the query text, so an unsalted key would
|
|
17
|
+
* serve a scoped (or memory-flavored) answer to a plain ask. Null/empty
|
|
18
|
+
* = the default scope (no salt segment — keys stay byte-identical to
|
|
19
|
+
* the pre-salt era). */
|
|
20
|
+
export declare function cacheKeyMaterial(query: string, lang?: string, salt?: string | null): string;
|
|
21
|
+
export declare function exactCacheKey(indexVersion: string, gen: string, ns: string, queryHash: string): string;
|
|
22
|
+
export declare function semanticCacheKey(indexVersion: string, gen: string, signature: string): string;
|
package/dist/ask.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Env } from "./env";
|
|
2
|
+
export type { Env };
|
|
3
|
+
import { type ApiKey } from "./lib/http";
|
|
4
|
+
declare function handleAsk(env: Env, ctx: ExecutionContext, req: Request, tier: "anon" | "key" | "member", key: ApiKey | null): Promise<Response>;
|
|
5
|
+
export { handleAsk };
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SessionClaims } from "./session";
|
|
2
|
+
export interface AuthConfig {
|
|
3
|
+
issuer: string;
|
|
4
|
+
clientId: string;
|
|
5
|
+
redirectUri: string;
|
|
6
|
+
sessionSecret: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function handleLogin(env: any, req: Request): Promise<Response>;
|
|
9
|
+
export declare function handleCallback(env: any, req: Request): Promise<Response>;
|
|
10
|
+
export declare function sessionFrom(req: Request, env: any): Promise<SessionClaims | null>;
|
|
11
|
+
export declare function handleMe(env: any, req: Request): Promise<Response>;
|
|
12
|
+
export declare function handleLogout(env: any, req: Request): Promise<Response>;
|
package/dist/bubble.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The origins a bubble may ride from: the estate pattern (the same rule
|
|
2
|
+
* corsHeaders applies) plus localhost for the local dev posture. */
|
|
3
|
+
export declare function isAllowedBubbleOrigin(origin: string): boolean;
|
|
4
|
+
/** The confirm page the callback renders in bubble mode. Static inline
|
|
5
|
+
* HTML+JS, everything escaped, targetOrigin = the validated origin
|
|
6
|
+
* (never "*"). The token leaves ONLY on the user's explicit Continue —
|
|
7
|
+
* a popup the user never asked for (a page opening it under the OP's
|
|
8
|
+
* SSO session) shows the request and stops here. */
|
|
9
|
+
export declare function bubbleConfirmPage(opts: {
|
|
10
|
+
name: string;
|
|
11
|
+
origin: string;
|
|
12
|
+
token: string;
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
P
|
|
3
|
+
} from "./chunk-MB74PTRM.js";
|
|
4
|
+
|
|
5
|
+
// workers/worker_public/src/refusal.ts
|
|
6
|
+
function refusalAnswer() {
|
|
7
|
+
return P().prompts.vars.refusal_sentence;
|
|
8
|
+
}
|
|
9
|
+
var REFUSAL_VARIANT = /^\s*I don[’']?t have information on .{1,120}? in the indexed OIML(?: \w+){0,2} (?:publications|passages|documents|corpus)\.?/i;
|
|
10
|
+
var REFUSAL_DRIFT = [
|
|
11
|
+
/\b(can'?t|cannot|couldn'?t|unable)\b[^.]{0,120}?\b(indexed )?OIML(?: \w+){0,2} publications\b/i,
|
|
12
|
+
/\bno real answer to give\b[^.]{0,120}?\bOIML\b/i,
|
|
13
|
+
/\b(?:falls|well) outside\b[^.]{0,120}?\b(?:what I can answer|my scope|the scope of)\b/i,
|
|
14
|
+
/\boutside (?:of )?what (?:I|this service) can answer\b/i,
|
|
15
|
+
// "I can't answer that — weather forecasting is outside my scope":
|
|
16
|
+
// requires the refusal verb, so a scope DISCUSSION inside a real answer
|
|
17
|
+
// ("this exemption is outside the scope of R 60") never matches
|
|
18
|
+
/\bI can[’']?t answer\b[^.]{0,100}?\bscope\b/i,
|
|
19
|
+
/^\s*I don[’']?t have any indexed OIML \w+(?:s)? (?:covering|about|on)\b/im
|
|
20
|
+
];
|
|
21
|
+
function sentenceStart(answer, i) {
|
|
22
|
+
let s = 0;
|
|
23
|
+
for (const sep of [". ", "! ", "? ", "\n"]) {
|
|
24
|
+
const j = answer.lastIndexOf(sep, i);
|
|
25
|
+
if (j >= 0) s = Math.max(s, j + sep.length);
|
|
26
|
+
}
|
|
27
|
+
return s;
|
|
28
|
+
}
|
|
29
|
+
function sentenceEnd(answer, i) {
|
|
30
|
+
const m = /[.!?\n]/.exec(answer.slice(i));
|
|
31
|
+
return m ? i + m.index + 1 : answer.length;
|
|
32
|
+
}
|
|
33
|
+
function canonicalRefusal(answer) {
|
|
34
|
+
const CANON = refusalAnswer();
|
|
35
|
+
if (answer.includes(CANON)) return answer;
|
|
36
|
+
const variant = answer.match(REFUSAL_VARIANT);
|
|
37
|
+
if (variant) return answer.replace(variant[0], CANON);
|
|
38
|
+
for (const drift of REFUSAL_DRIFT) {
|
|
39
|
+
const m = drift.exec(answer);
|
|
40
|
+
if (!m) continue;
|
|
41
|
+
return answer.slice(0, sentenceStart(answer, m.index)) + CANON + answer.slice(sentenceEnd(answer, m.index));
|
|
42
|
+
}
|
|
43
|
+
return answer;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
refusalAnswer,
|
|
48
|
+
canonicalRefusal
|
|
49
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// workers/worker_public/src/profile.gen.ts
|
|
2
|
+
var PROFILE = {
|
|
3
|
+
"publisher": {
|
|
4
|
+
"id": "fixture",
|
|
5
|
+
"name": "Fixture",
|
|
6
|
+
"full_name": "The Fixture Publisher",
|
|
7
|
+
"product_name": "Fixture Answers",
|
|
8
|
+
"description": "A minimal publisher profile exercising every declared surface: an open dataset, a permission-gated dataset, production and lane corpora, prompt vars and retrieval vocabulary.",
|
|
9
|
+
"domains": {
|
|
10
|
+
"public": "fixture.example.org"
|
|
11
|
+
},
|
|
12
|
+
"identity": {
|
|
13
|
+
"issuer": "https://id.fixture.example.org"
|
|
14
|
+
},
|
|
15
|
+
"codec": "plain-slug"
|
|
16
|
+
},
|
|
17
|
+
"datasets": [
|
|
18
|
+
{
|
|
19
|
+
"id": "pub",
|
|
20
|
+
"label": "Fixture Publications",
|
|
21
|
+
"description": "The fixture publisher's corpus",
|
|
22
|
+
"corpora": [
|
|
23
|
+
"pub",
|
|
24
|
+
"dirty",
|
|
25
|
+
"clean",
|
|
26
|
+
"synthetic"
|
|
27
|
+
],
|
|
28
|
+
"note": "Some passages come from the fixture corpus \u2014 cite them the same way as every other passage."
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "internal",
|
|
32
|
+
"label": "Internal corpus",
|
|
33
|
+
"description": "An access-restricted corpus proving the permission gate",
|
|
34
|
+
"session": true,
|
|
35
|
+
"permission": "preview",
|
|
36
|
+
"corpora": [
|
|
37
|
+
"internal"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"corpora": {
|
|
42
|
+
"production": [
|
|
43
|
+
"pub",
|
|
44
|
+
"dirty",
|
|
45
|
+
"clean",
|
|
46
|
+
"synthetic",
|
|
47
|
+
"model"
|
|
48
|
+
],
|
|
49
|
+
"lanes": {
|
|
50
|
+
"exp_a": [
|
|
51
|
+
"exp_a"
|
|
52
|
+
],
|
|
53
|
+
"exp_b": [
|
|
54
|
+
"exp_b"
|
|
55
|
+
],
|
|
56
|
+
"glossary": [
|
|
57
|
+
"glossary"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"sources": {
|
|
62
|
+
"corpora": {
|
|
63
|
+
"clean": {
|
|
64
|
+
"repo": "fixtures/corpus",
|
|
65
|
+
"note": "the engine's fixture corpus"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"bibliography": {},
|
|
69
|
+
"terminology": {},
|
|
70
|
+
"models": {}
|
|
71
|
+
},
|
|
72
|
+
"ui": {
|
|
73
|
+
"suggestions": [
|
|
74
|
+
"What is in the fixture corpus?",
|
|
75
|
+
"Which documents does the fixture publisher issue?"
|
|
76
|
+
],
|
|
77
|
+
"models_disclosure": [
|
|
78
|
+
{
|
|
79
|
+
"role": "Answers",
|
|
80
|
+
"model": "fixture-answer-model"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"smoke": [
|
|
84
|
+
{
|
|
85
|
+
"label": "sanity",
|
|
86
|
+
"query": "What is in the fixture corpus?",
|
|
87
|
+
"expect": "fixture"
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
"retrieval": {
|
|
92
|
+
"process_expansion": " fixture certification system framework application evaluation"
|
|
93
|
+
},
|
|
94
|
+
"prompts": {
|
|
95
|
+
"vars": {
|
|
96
|
+
"assistant_identity": "the fixture assistant \u2014 a public service answering questions about the fixture publisher's documents",
|
|
97
|
+
"refusal_sentence": "I don't have information on this in the indexed fixture documents."
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// workers/worker_public/src/profile.ts
|
|
103
|
+
var current = PROFILE;
|
|
104
|
+
function setProfile(profile) {
|
|
105
|
+
current = profile;
|
|
106
|
+
}
|
|
107
|
+
function P() {
|
|
108
|
+
return current;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export {
|
|
112
|
+
setProfile,
|
|
113
|
+
P
|
|
114
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import {
|
|
2
|
+
P
|
|
3
|
+
} from "./chunk-MB74PTRM.js";
|
|
4
|
+
|
|
5
|
+
// workers/worker_public/src/config.ts
|
|
6
|
+
var MODELS = {
|
|
7
|
+
embed: "@cf/qwen/qwen3-embedding-0.6b",
|
|
8
|
+
rerank: "@cf/baai/bge-reranker-base",
|
|
9
|
+
// ANSWER MODEL (all tiers, user decision 2026-08-29): glm-5.3-flash —
|
|
10
|
+
// natively multimodal (vision-unified contract), GLM family, flash tier.
|
|
11
|
+
// Vision image-parts land with answer contract v2; text answers work now.
|
|
12
|
+
anon: "@cf/zai-org/glm-5.3-flash",
|
|
13
|
+
member: "@cf/zai-org/glm-5.3-flash",
|
|
14
|
+
// hot-path understanding/summarize stays on the cheap Qwen (cost-first lane)
|
|
15
|
+
understand: "@cf/qwen/qwen3-30b-a3b-fp8",
|
|
16
|
+
// generation fallback when the answer model is unavailable
|
|
17
|
+
fallback: "@cf/qwen/qwen3-30b-a3b-fp8",
|
|
18
|
+
grader: "@cf/deepseek-ai/deepseek-v4-flash-0731",
|
|
19
|
+
// CRAG grader + judges (unsuffixed slug was retired → silent 5018s)
|
|
20
|
+
// contextual enrichment is the QUALITY-FIRST lane (one-time spend over
|
|
21
|
+
// the corpus, its quality persists into every future retrieval)
|
|
22
|
+
enrich: "@cf/deepseek-ai/deepseek-v4-pro-0813",
|
|
23
|
+
// final-tier listwise reranker for hard/member queries (cascade:
|
|
24
|
+
// cross-encoder prunes, listwise orders jointly)
|
|
25
|
+
listwise: "@cf/zai-org/glm-4.7-flash",
|
|
26
|
+
// deep-research loop (G10): bounded agentic iterations, members-only
|
|
27
|
+
research: "@cf/zai-org/glm-5.3-flash"
|
|
28
|
+
};
|
|
29
|
+
var LIMITS = {
|
|
30
|
+
// input sizes: generous — real questions can be long (pasted scenarios,
|
|
31
|
+
// multi-part asks). The context BUDGET is the real governor of what the
|
|
32
|
+
// model sees; these caps only bound abuse.
|
|
33
|
+
maxInputChars: 8e3,
|
|
34
|
+
maxOutputTokens: 3072,
|
|
35
|
+
// qwen3-30b-a3b always reasons; 768 starved the answer entirely
|
|
36
|
+
retrieveK: 50,
|
|
37
|
+
// Vectorize caps topK at 50 when returnMetadata=all
|
|
38
|
+
rerankKeep: 10,
|
|
39
|
+
// 8 crowded out dirty-lane goldens once 3k enriched MKO clean chunks entered the pool
|
|
40
|
+
cacheTtlSec: 6 * 3600,
|
|
41
|
+
// context-window budget (estimated tokens) for the assembled prompt —
|
|
42
|
+
// system + summary + history slice + passages must fit or the model
|
|
43
|
+
// request fails. 16k is conservative for the qwen3 tier (pre-budget
|
|
44
|
+
// traffic at ~12k+ never hit a length error); raise via INPUT_TOKEN_BUDGET
|
|
45
|
+
// after watching logs for length rejections
|
|
46
|
+
inputTokenBudget: 16e3,
|
|
47
|
+
maxPassageTokens: 900
|
|
48
|
+
// per-passage cap (clause chunks with tables can be huge)
|
|
49
|
+
};
|
|
50
|
+
var THRESHOLDS = {
|
|
51
|
+
/** HyDE candidate score discount — hypothetical-answer vectors match
|
|
52
|
+
* differently than question vectors; 0.7 keeps them competitive
|
|
53
|
+
* without letting a bad hypothetical outrank the real query. */
|
|
54
|
+
hydeDiscount: 0.7,
|
|
55
|
+
/** Graph-lane candidate discount — graph-filtered chunks enter the
|
|
56
|
+
* pool below the primary dense lane; they must earn their window
|
|
57
|
+
* slot under the cross-encoder, not by graph membership alone. */
|
|
58
|
+
graphLaneDiscount: 0.75,
|
|
59
|
+
/** Concept-graph candidate discount — same rationale as the graph
|
|
60
|
+
* lane: definitional content enters discounted. */
|
|
61
|
+
conceptGraphDiscount: 0.75,
|
|
62
|
+
/** Multi-hop sub-query discount — sub-question hits are unioned, not
|
|
63
|
+
* RRF-fused; the discount keeps them from dominating the primary
|
|
64
|
+
* ranking on their first appearance. */
|
|
65
|
+
subQueryDiscount: 0.8,
|
|
66
|
+
/** Federated-ISO discount — the public corpus answers by default;
|
|
67
|
+
* internal ISO passages compete but don't preempt. */
|
|
68
|
+
federateDiscount: 0.95,
|
|
69
|
+
/** Standard-reference nudge (L5): when the question asks about an
|
|
70
|
+
* invoked ISO/IEC standard, chunks that CARRY such a citation (their
|
|
71
|
+
* text contains an ISO/IEC identifier) get a spread-scaled boost —
|
|
72
|
+
* the citing clause is the answer, and generic family prose otherwise
|
|
73
|
+
* fills the window (measured: l5a-iso-humidity flips ~1/6 runs). */
|
|
74
|
+
stdRefNudgeSpread: 0.35,
|
|
75
|
+
/** Edition cover — the score multiplier for current-edition chunks the
|
|
76
|
+
* cover stage fetches when a pool holds ONLY stale editions of a
|
|
77
|
+
* document. Just under the top: the point is REPRESENTATION (so
|
|
78
|
+
* edition steering can demote the stale siblings and diversity keeps
|
|
79
|
+
* the current overview), not free ranking. */
|
|
80
|
+
editionCoverDiscount: 0.9,
|
|
81
|
+
/** Overview-chunk demotion — overview chunks repeat title/doctype
|
|
82
|
+
* boilerplate and embed strongly for name-like queries, crowding
|
|
83
|
+
* clause chunks out of the rerank window. */
|
|
84
|
+
overviewDemotion: 0.85,
|
|
85
|
+
/** Glossary-link cosine floor — below this the dense match to a
|
|
86
|
+
* defined term is noise, not a candidate. Calibrated on the
|
|
87
|
+
* drifting→durability probe (durability-def 0.542, noise ~0.3). */
|
|
88
|
+
glossaryCosineFloor: 0.5,
|
|
89
|
+
/** Exact-term nudge (spread multiplier) — clause chunks whose head IS
|
|
90
|
+
* the asked-for term get a decisive nudge because publication headers
|
|
91
|
+
* contain the title words and the reranker alone is unreliable there;
|
|
92
|
+
* >1 so it dominates the spread, unlike the additive steering boosts. */
|
|
93
|
+
termNudgeSpread: 1.5,
|
|
94
|
+
/** Concept-steering rerank boost (spread fraction) — the vocabulary
|
|
95
|
+
* link's defining families get the edition-steering boost idiom.
|
|
96
|
+
* 0.15 is enough to lift in-family content past the cross-encoder's
|
|
97
|
+
* vocabulary bias without overriding genuine relevance. */
|
|
98
|
+
conceptSteerSpread: 0.15,
|
|
99
|
+
/** Cross-publication recency boost (spread fraction) — a
|
|
100
|
+
* current-edition publication ranks over stale ones; composed with
|
|
101
|
+
* the family-relative demotion below. */
|
|
102
|
+
crossPubRecencySpread: 0.1,
|
|
103
|
+
/** Family-relative edition demotion (spread fraction) — superseded
|
|
104
|
+
* editions are demoted when a newer edition of the same publication
|
|
105
|
+
* is in the pool; a sibling one revision back still competes. */
|
|
106
|
+
familyDemoteSpread: 0.4,
|
|
107
|
+
/** Relevance-floored window — passages below this fraction of the
|
|
108
|
+
* top rerank score leave the window (the evidence-budget principle;
|
|
109
|
+
* structural units are exempt). */
|
|
110
|
+
windowFloorFraction: 0.25,
|
|
111
|
+
/** Small-to-big parent fetch discount — the parent clause enters at
|
|
112
|
+
* a discount because it's supplementary grounding, not the answer. */
|
|
113
|
+
smallToBigDiscount: 0.7,
|
|
114
|
+
/** Section-descent child discount — children fetched from a ranked
|
|
115
|
+
* depth-1 summary enter discounted. */
|
|
116
|
+
sectionDescentDiscount: 0.8,
|
|
117
|
+
/** History budget share — the fraction of the context budget the
|
|
118
|
+
* conversation slice may consume; older turns overflow into the
|
|
119
|
+
* compacted summary instead of starving the passages. */
|
|
120
|
+
historyBudgetShare: 0.3
|
|
121
|
+
};
|
|
122
|
+
function processExpansion() {
|
|
123
|
+
return P().retrieval.process_expansion;
|
|
124
|
+
}
|
|
125
|
+
function roleModel(env, role) {
|
|
126
|
+
const ov = env[`${role.toUpperCase()}_MODEL`];
|
|
127
|
+
return typeof ov === "string" && ov.startsWith("@cf/") ? ov : MODELS[role];
|
|
128
|
+
}
|
|
129
|
+
var EFFORTS = /* @__PURE__ */ new Set(["low", "medium", "high", "max"]);
|
|
130
|
+
function answerEffort(env) {
|
|
131
|
+
const v = env?.ANSWER_EFFORT;
|
|
132
|
+
return typeof v === "string" && EFFORTS.has(v) ? v : "low";
|
|
133
|
+
}
|
|
134
|
+
function effortBudget(effort) {
|
|
135
|
+
if (effort === "medium") return LIMITS.maxOutputTokens * 2;
|
|
136
|
+
if (effort === "high" || effort === "max") return LIMITS.maxOutputTokens * 4;
|
|
137
|
+
return LIMITS.maxOutputTokens;
|
|
138
|
+
}
|
|
139
|
+
function requestEffort(env, session, requested) {
|
|
140
|
+
if (typeof requested !== "string" || !EFFORTS.has(requested)) return answerEffort(env);
|
|
141
|
+
if (requested === "low") return requested;
|
|
142
|
+
return session ? requested : answerEffort(env);
|
|
143
|
+
}
|
|
144
|
+
function DATASETS() {
|
|
145
|
+
return P().datasets;
|
|
146
|
+
}
|
|
147
|
+
function hasPermission(session, code) {
|
|
148
|
+
const roles = session?.roles;
|
|
149
|
+
return Array.isArray(roles) && roles.map(String).includes(code);
|
|
150
|
+
}
|
|
151
|
+
function datasetAllowed(d, session) {
|
|
152
|
+
if (!d.session) return true;
|
|
153
|
+
if (!session) return false;
|
|
154
|
+
return hasPermission(session, d.permission ?? "ai-preview");
|
|
155
|
+
}
|
|
156
|
+
function datasetsFor(session) {
|
|
157
|
+
return DATASETS().map((d) => ({
|
|
158
|
+
id: d.id,
|
|
159
|
+
label: d.label,
|
|
160
|
+
description: d.description,
|
|
161
|
+
enabled: datasetAllowed(d, session),
|
|
162
|
+
...d.session ? { requires: `the ${d.permission ?? "ai-preview"} permission (id.oimlsmart.org)`, authenticated: !!session } : {}
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
function SUGGESTIONS() {
|
|
166
|
+
return [...P().ui.suggestions];
|
|
167
|
+
}
|
|
168
|
+
function num(env, key, fallback) {
|
|
169
|
+
const v = Number(env[key]);
|
|
170
|
+
return Number.isFinite(v) && v > 0 ? v : fallback;
|
|
171
|
+
}
|
|
172
|
+
function today() {
|
|
173
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
174
|
+
}
|
|
175
|
+
async function sha256Hex(s) {
|
|
176
|
+
const d = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(s));
|
|
177
|
+
return [...new Uint8Array(d)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export {
|
|
181
|
+
MODELS,
|
|
182
|
+
LIMITS,
|
|
183
|
+
THRESHOLDS,
|
|
184
|
+
processExpansion,
|
|
185
|
+
roleModel,
|
|
186
|
+
answerEffort,
|
|
187
|
+
effortBudget,
|
|
188
|
+
requestEffort,
|
|
189
|
+
DATASETS,
|
|
190
|
+
hasPermission,
|
|
191
|
+
datasetAllowed,
|
|
192
|
+
datasetsFor,
|
|
193
|
+
SUGGESTIONS,
|
|
194
|
+
num,
|
|
195
|
+
today,
|
|
196
|
+
sha256Hex
|
|
197
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DATASETS,
|
|
3
|
+
datasetAllowed
|
|
4
|
+
} from "./chunk-WOGQM7DJ.js";
|
|
5
|
+
|
|
6
|
+
// workers/worker_public/src/requestScope.ts
|
|
7
|
+
function resolveRequestScope(body, member) {
|
|
8
|
+
const allIds = DATASETS().map((d) => d.id);
|
|
9
|
+
const requested = Array.isArray(body?.datasets) ? body.datasets.filter((x) => typeof x === "string" && allIds.includes(x)) : null;
|
|
10
|
+
if (requested !== null && requested.length === 0) return { error: "empty-datasets" };
|
|
11
|
+
const permittedIds = allIds.filter((id) => {
|
|
12
|
+
const d = DATASETS().find((x) => x.id === id);
|
|
13
|
+
return d.session ? datasetAllowed(d, member) : true;
|
|
14
|
+
});
|
|
15
|
+
const scopeIds = (requested ?? permittedIds).filter((id) => permittedIds.includes(id));
|
|
16
|
+
const corpora = /* @__PURE__ */ new Set();
|
|
17
|
+
for (const id of scopeIds) {
|
|
18
|
+
const d = DATASETS().find((x) => x.id === id);
|
|
19
|
+
for (const v of d?.corpora ?? [id]) corpora.add(v);
|
|
20
|
+
}
|
|
21
|
+
const memoryIds = member && Array.isArray(body?.memories) ? body.memories.filter((x) => typeof x === "string").slice(0, 4) : [];
|
|
22
|
+
return {
|
|
23
|
+
scopeIds,
|
|
24
|
+
corpora,
|
|
25
|
+
narrowed: scopeIds.length < permittedIds.length,
|
|
26
|
+
// federation flag: any session-gated (federated) dataset in scope
|
|
27
|
+
isoOn: scopeIds.some((id) => DATASETS().find((x) => x.id === id)?.session === true),
|
|
28
|
+
memoryIds
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function requestSalt(scope, memoryUsed) {
|
|
32
|
+
if (!scope.narrowed && !memoryUsed.length) return null;
|
|
33
|
+
return JSON.stringify({
|
|
34
|
+
...scope.narrowed ? { d: [...scope.corpora].sort() } : {},
|
|
35
|
+
...memoryUsed.length ? { m: [...memoryUsed].sort() } : {}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
resolveRequestScope,
|
|
41
|
+
requestSalt
|
|
42
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StoreQuery } from "./ports/store.ts";
|
|
2
|
+
import { type ResolvedBlock } from "./refs.ts";
|
|
3
|
+
import type { Hit } from "./pipeline.ts";
|
|
4
|
+
export declare function completeTables(db: StoreQuery, answer: string, used: Hit[]): Promise<ResolvedBlock[]>;
|
|
5
|
+
export declare function completeFigures(db: StoreQuery, answer: string, alreadyAttached: ResolvedBlock[]): Promise<ResolvedBlock[]>;
|