From 0746d7ffd565351e1131b3e27d8c4bb2a5f12f6a Mon Sep 17 00:00:00 2001 From: elpresidank Date: Thu, 11 Jun 2026 06:40:01 -0500 Subject: [PATCH] =?UTF-8?q?feat(ts):=20add=20real=20quality=20gates=20?= =?UTF-8?q?=E2=80=94=20Biome=20lint=20+=20effect-law=20ratchet=20+=20class?= =?UTF-8?q?=20inventory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - biome.json (2.4.16, linter-only) wired as "lint" in all six packages - scripts/check-effect-laws.ts: Effect-native law enforcement encoding the adapted beep-effect effect-first/schema-first laws (no native JSON/switch/ sort/fetch/timers, no process.env, no throw new, no Effect.run* outside boundaries, no Schema-suffixed constants, no node:fs/path, AST-based pure-data interface detection per law 38/39) - ratcheting baseline allowlist (95 entries / 290 findings) that must shrink to documented exemptions only; stale counts fail the gate - root lint chains turbo lint + law check + native-class inventory - fix all 163 initial Biome findings: import-type style, templates, two `any`s, ten non-null assertions (librarian getService gate, A.matchRight in atoms, ensureNode returning nodes, main.tsx mount guard) Gates: lint, check:tsgo, build, test (force, 11 tasks) all green. Co-Authored-By: Claude Fable 5 --- ts/biome.json | 95 ++++++++++++++++++ ts/bun.lock | 19 ++++ ts/package.json | 6 +- ts/packages/base/package.json | 3 +- .../base/src/__tests__/consumer.test.ts | 5 +- .../src/__tests__/embeddings-service.test.ts | 18 ++-- .../__tests__/flow-processor-runtime.test.ts | 16 +-- .../src/__tests__/flow-spec-runtime.test.ts | 16 +-- .../src/__tests__/messaging-runtime.test.ts | 16 +-- .../base/src/__tests__/producer.test.ts | 12 ++- .../src/__tests__/request-response.test.ts | 14 +-- .../src/__tests__/runtime-services.test.ts | 16 +-- ts/packages/base/src/backend/nats.ts | 17 ++-- ts/packages/base/src/messaging/consumer.ts | 13 ++- ts/packages/base/src/messaging/producer.ts | 9 +- .../base/src/messaging/request-response.ts | 19 ++-- ts/packages/base/src/messaging/runtime.ts | 25 +++-- ts/packages/base/src/metrics/prometheus.ts | 3 +- .../base/src/processor/async-processor.ts | 6 +- .../base/src/processor/flow-processor.ts | 24 +++-- ts/packages/base/src/processor/flow.ts | 27 +++-- ts/packages/base/src/processor/program.ts | 15 +-- .../base/src/services/embeddings-service.ts | 8 +- ts/packages/base/src/services/llm-service.ts | 6 +- ts/packages/base/src/spec/consumer-spec.ts | 10 +- ts/packages/base/src/spec/producer-spec.ts | 14 ++- .../base/src/spec/request-response-spec.ts | 14 ++- ts/packages/cli/package.json | 3 +- ts/packages/cli/src/commands/agent.ts | 3 +- ts/packages/cli/src/commands/util.ts | 6 +- ts/packages/client/package.json | 4 +- .../client/src/__tests__/flows-api.test.ts | 6 +- .../client/src/__tests__/messages.test.ts | 2 +- .../client/src/__tests__/rpc-timeout.test.ts | 6 +- .../src/__tests__/workbench-contracts.test.ts | 4 +- ts/packages/client/src/models/namespaces.ts | 40 ++++---- .../client/src/socket/effect-rpc-client.ts | 3 +- .../client/src/socket/trustgraph-socket.ts | 17 ++-- .../client/src/socket/websocket-adapter.ts | 3 +- ts/packages/flow/package.json | 3 +- .../src/__tests__/chunking-service.test.ts | 18 ++-- .../src/__tests__/falkordb-lifecycle.test.ts | 12 ++- .../__tests__/flow-manager-service.test.ts | 24 +++-- .../flow/src/__tests__/gateway-routes.test.ts | 3 +- .../__tests__/knowledge-core-service.test.ts | 20 ++-- .../src/__tests__/librarian-service.test.ts | 18 ++-- .../src/__tests__/prompt-template.test.ts | 18 ++-- .../flow/src/__tests__/retrieval-rag.test.ts | 6 +- .../flow/src/agent/mcp-tool/service.ts | 21 ++-- ts/packages/flow/src/agent/react/service.ts | 55 +++++----- ts/packages/flow/src/agent/react/tools.ts | 4 +- ts/packages/flow/src/agent/tool-filter.ts | 4 +- ts/packages/flow/src/chunking/service.ts | 20 ++-- ts/packages/flow/src/config/service.ts | 18 ++-- ts/packages/flow/src/cores/service.ts | 20 ++-- ts/packages/flow/src/decoding/pdf-decoder.ts | 32 +++--- ts/packages/flow/src/embeddings/ollama.ts | 6 +- .../flow/src/extract/knowledge-extract.ts | 38 +++---- ts/packages/flow/src/flow-manager/service.ts | 20 ++-- .../flow/src/gateway/dispatch/manager.ts | 20 ++-- .../flow/src/gateway/dispatch/serialize.ts | 6 +- ts/packages/flow/src/gateway/rpc-server.ts | 8 +- ts/packages/flow/src/gateway/server.ts | 10 +- ts/packages/flow/src/librarian/service.ts | 66 ++++++------ .../src/model/text-completion/azure-openai.ts | 16 +-- .../flow/src/model/text-completion/claude.ts | 14 ++- .../flow/src/model/text-completion/common.ts | 14 ++- .../flow/src/model/text-completion/mistral.ts | 16 +-- .../flow/src/model/text-completion/ollama.ts | 20 ++-- .../text-completion/openai-compatible.ts | 16 +-- .../flow/src/model/text-completion/openai.ts | 16 +-- ts/packages/flow/src/prompt/template.ts | 20 ++-- ts/packages/flow/src/qdrant/client.ts | 3 +- .../query/embeddings/qdrant-doc-service.ts | 26 +++-- .../flow/src/query/embeddings/qdrant-doc.ts | 3 +- .../query/embeddings/qdrant-graph-service.ts | 26 +++-- .../flow/src/query/embeddings/qdrant-graph.ts | 6 +- .../src/query/triples/falkordb-service.ts | 26 +++-- .../flow/src/query/triples/falkordb.ts | 3 +- .../src/retrieval/document-rag-service.ts | 40 ++++---- .../flow/src/retrieval/graph-rag-service.ts | 46 +++++---- .../embeddings/graph-embeddings-service.ts | 32 +++--- .../flow/src/storage/embeddings/qdrant-doc.ts | 3 +- .../src/storage/embeddings/qdrant-graph.ts | 6 +- .../src/storage/triples/falkordb-service.ts | 20 ++-- .../flow/src/storage/triples/falkordb.ts | 3 +- ts/packages/mcp/package.json | 3 +- .../mcp/src/__tests__/server-effect.test.ts | 5 +- ts/packages/mcp/src/server-effect.ts | 8 +- ts/packages/workbench/package.json | 3 +- ts/packages/workbench/src/atoms/workbench.ts | 49 +++++---- .../src/components/chat/explain-graph.tsx | 6 +- .../src/components/error-boundary.tsx | 4 +- .../src/components/notification-toasts.tsx | 3 +- ts/packages/workbench/src/index.css | 4 +- ts/packages/workbench/src/lib/graph-utils.ts | 28 +++--- ts/packages/workbench/src/lib/utils.ts | 3 +- ts/packages/workbench/src/main.tsx | 8 +- ts/packages/workbench/src/pages/chat.tsx | 4 +- ts/packages/workbench/src/pages/graph.tsx | 6 +- ts/packages/workbench/src/pages/library.tsx | 4 +- ts/packages/workbench/src/pages/mcp-tools.tsx | 6 +- ts/packages/workbench/src/pages/prompts.tsx | 4 +- .../workbench/src/qa/initial-values.ts | 11 +- ts/packages/workbench/src/qa/mock-api.ts | 3 +- ts/scripts/check-effect-laws.ts | Bin 0 -> 11793 bytes ts/scripts/create-test-pdf.ts | 2 +- ts/scripts/effect-laws.allowlist.json | 1 + ts/scripts/test-pipeline.ts | 9 +- 109 files changed, 951 insertions(+), 611 deletions(-) create mode 100644 ts/biome.json create mode 100644 ts/scripts/check-effect-laws.ts create mode 100644 ts/scripts/effect-laws.allowlist.json diff --git a/ts/biome.json b/ts/biome.json new file mode 100644 index 00000000..494297d0 --- /dev/null +++ b/ts/biome.json @@ -0,0 +1,95 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.4.16/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "root": true, + "files": { + "includes": [ + "packages/*/src/**", + "scripts/**", + "!**/node_modules", + "!**/dist", + "!**/.turbo", + "!**/__snapshots__" + ] + }, + "css": { + "parser": { + "tailwindDirectives": true + } + }, + "formatter": { + "enabled": false + }, + "assist": { + "enabled": false + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "security": { + "noGlobalEval": "error" + }, + "a11y": { + "useFocusableInteractive": "off", + "useAriaPropsForRole": "off", + "useSemanticElements": "off", + "useKeyWithClickEvents": "off", + "noStaticElementInteractions": "off", + "noSvgWithoutTitle": "off", + "useButtonType": "off", + "noLabelWithoutControl": "off" + }, + "complexity": { + "noBannedTypes": "off", + "noForEach": "off", + "noUselessFragments": "off" + }, + "correctness": { + "noUnusedImports": "error", + "noUnusedVariables": "off", + "noUnusedFunctionParameters": "off", + "useExhaustiveDependencies": "off", + "useHookAtTopLevel": "off", + "useYield": "off", + "noChildrenProp": "off" + }, + "performance": { + "noDelete": "off", + "noAccumulatingSpread": "off" + }, + "suspicious": { + "noDebugger": "error", + "noExplicitAny": "error", + "noConfusingVoidType": "off", + "noAssignInExpressions": "off", + "noArrayIndexKey": "off", + "noDoubleEquals": "off", + "noThenProperty": "off", + "noRedeclare": "off" + }, + "style": { + "noNonNullAssertion": "error", + "useImportType": { + "level": "error", + "options": { + "style": "separatedType" + } + }, + "useAsConstAssertion": "error", + "useDefaultParameterLast": "error", + "useSelfClosingElements": "error", + "useSingleVarDeclarator": "error", + "useNumberNamespace": "error", + "noInferrableTypes": "error", + "noUselessElse": "error", + "noParameterAssign": "off", + "noUnusedTemplateLiteral": "off" + } + } + } +} diff --git a/ts/bun.lock b/ts/bun.lock index a4b7b0df..23a708f5 100644 --- a/ts/bun.lock +++ b/ts/bun.lock @@ -8,6 +8,7 @@ "effect": "4.0.0-beta.78", }, "devDependencies": { + "@biomejs/biome": "^2", "@effect/platform-bun": "4.0.0-beta.78", "@effect/tsgo": "0.14.0", "@effect/vitest": "4.0.0-beta.78", @@ -190,6 +191,24 @@ "@babel/types": ["@babel/types@7.29.0", "", { "dependencies": { "@babel/helper-string-parser": "7.27.1", "@babel/helper-validator-identifier": "7.28.5" } }, "sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A=="], + "@biomejs/biome": ["@biomejs/biome@2.4.16", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.4.16", "@biomejs/cli-darwin-x64": "2.4.16", "@biomejs/cli-linux-arm64": "2.4.16", "@biomejs/cli-linux-arm64-musl": "2.4.16", "@biomejs/cli-linux-x64": "2.4.16", "@biomejs/cli-linux-x64-musl": "2.4.16", "@biomejs/cli-win32-arm64": "2.4.16", "@biomejs/cli-win32-x64": "2.4.16" }, "bin": { "biome": "bin/biome" } }, "sha512-x9ajFh1zChVybCiM3TN6OD4phAqLgtPZjFrZF+aTMYCPjwBO+k529TX7PPsAqtGNLeV4UgzwQnowEgS7bGmzcA=="], + + "@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.4.16", "", { "os": "darwin", "cpu": "arm64" }, "sha512-wxPvu4XOA85YJk9ixSWUmq/QBHbid85BISbOAqqBM/5xQpPk9ayjk5375tOlSC0BeCwNSbPFafQBm+vBumXq0A=="], + + "@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.4.16", "", { "os": "darwin", "cpu": "x64" }, "sha512-xFCqGPwYusQJp4N4NJLi1XJiZqjwFdjhT+KqtNy+Ug3qgfczqnTa6MSDvxJF6TkuDLoYJItMapz6tAf7kCekFw=="], + + "@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.4.16", "", { "os": "linux", "cpu": "arm64" }, "sha512-2kFb4//jxfZaP6D+Rj5VkHkxgyD9EoRAVBEQb8PKRv+s4NO2zYNJKXFaJmK1CmhufJOWEfpHKaRbOja7qjmdhQ=="], + + "@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.4.16", "", { "os": "linux", "cpu": "arm64" }, "sha512-oYxnW0ARfJkr72ezzF2OR8N/rtkgLUQeYtF8cFhVswbknHxtTcmzSsanVJP8yQKnGpGpc2ck6c5zLvHahL6Cbg=="], + + "@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.4.16", "", { "os": "linux", "cpu": "x64" }, "sha512-NbcBbi/nJqn5baae6wqRXdS7Gadf2uRpehSh6vMSYpG8OhkXl/Xg8aorWrJ+9VWqAT5ml90alLvorkpMW0nBwQ=="], + + "@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.4.16", "", { "os": "linux", "cpu": "x64" }, "sha512-iHDS+MCM65DPqWGu+ECC3uoALyj2H7F4nVUPxIPjz/PIl94EUu+EDfGZDzFP+NY1EOPVt9NQvwFqq7HdMmowdg=="], + + "@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.4.16", "", { "os": "win32", "cpu": "arm64" }, "sha512-0rgImMsNb5v/chhkIFe3wu7PEFClS6RBAYUijGL9UsYN3PanSaoK24HSSuSJb1pYbYYVjzAyZTl3gtjJ84BM8A=="], + + "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.4.16", "", { "os": "win32", "cpu": "x64" }, "sha512-Kp85jgoBHa05gix6UIRjfCDiUV3w/8VIdZ247VyyO2gEjaw12WEVhdIjlxp/AMzXxqxQwbxNTDVZ3Mwd2RG5rw=="], + "@effect/ai-anthropic": ["@effect/ai-anthropic@4.0.0-beta.78", "", { "peerDependencies": { "effect": "^4.0.0-beta.78" } }, "sha512-FZzwvKx2k+UIDJyv+FWMtC2CKRxJMWTII+z8EmMcT6tw1uzkkn+ouIyJ32AU+lfveKScNV1SXL4ml3VdcYGy/g=="], "@effect/atom-react": ["@effect/atom-react@4.0.0-beta.78", "", { "peerDependencies": { "effect": "^4.0.0-beta.78", "react": "^19.2.4", "scheduler": "*" } }, "sha512-cgxDXJaD0wlbQXbp6tiEmmY+yajwurB0ynkFG20RVucvH4LsQMB3ogiHe0mt42wGggfbVYMEDxgBpQdqDRY8yA=="], diff --git a/ts/package.json b/ts/package.json index aade7951..a59838be 100644 --- a/ts/package.json +++ b/ts/package.json @@ -4,7 +4,9 @@ "scripts": { "build": "bunx --bun turbo build", "dev": "bunx --bun turbo dev", - "lint": "bunx --bun turbo lint", + "lint": "bunx --bun turbo lint && bun run lint:laws", + "lint:laws": "bun scripts/check-effect-laws.ts && bun scripts/inventory-native-classes.ts", + "lint:laws:baseline": "bun scripts/check-effect-laws.ts --write-baseline", "test": "bunx --bun turbo test", "check": "bun run check:tsgo", "check:tsgo": "effect-tsgo patch && tsgo -b tsconfig.json", @@ -44,6 +46,7 @@ "llm:mistral": "bun scripts/run-llm-mistral.ts" }, "devDependencies": { + "@biomejs/biome": "^2", "@effect/platform-bun": "4.0.0-beta.78", "@effect/tsgo": "0.14.0", "@effect/vitest": "4.0.0-beta.78", @@ -55,7 +58,6 @@ "pdf-lib": "^1.17.1", "tsx": "^4.21.0", "turbo": "^2.5.0", - "typescript": "^5.8.0", "vitest": "^4.1.6" }, diff --git a/ts/packages/base/package.json b/ts/packages/base/package.json index d87b4e79..79303a84 100644 --- a/ts/packages/base/package.json +++ b/ts/packages/base/package.json @@ -17,7 +17,8 @@ "build": "bunx --bun tsc", "dev": "tsc --watch", "clean": "rm -rf dist", - "test": "bunx --bun vitest run" + "test": "bunx --bun vitest run", + "lint": "bunx --bun biome check src" }, "dependencies": { "effect": "4.0.0-beta.78", diff --git a/ts/packages/base/src/__tests__/consumer.test.ts b/ts/packages/base/src/__tests__/consumer.test.ts index 1ff9a5b9..ca26c0c9 100644 --- a/ts/packages/base/src/__tests__/consumer.test.ts +++ b/ts/packages/base/src/__tests__/consumer.test.ts @@ -1,13 +1,12 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; import { Effect } from "effect"; -import { makeConsumer, type ConsumerOptions, type FlowContext } from "../messaging/consumer.js"; +import type { FlowContext } from "../messaging/consumer.js"; +import { makeConsumer, } from "../messaging/consumer.js"; import type { PubSubBackend, BackendConsumer, Message, BackendProducer, - CreateProducerOptions, - CreateConsumerOptions, } from "../backend/types.js"; import { tooManyRequestsError } from "../errors.js"; import type { Flow } from "../processor/flow.js"; diff --git a/ts/packages/base/src/__tests__/embeddings-service.test.ts b/ts/packages/base/src/__tests__/embeddings-service.test.ts index 3699e77a..caa13260 100644 --- a/ts/packages/base/src/__tests__/embeddings-service.test.ts +++ b/ts/packages/base/src/__tests__/embeddings-service.test.ts @@ -1,6 +1,16 @@ import { describe, expect, it } from "@effect/vitest"; import { ConfigProvider, Effect, Fiber } from "effect"; import * as S from "effect/Schema"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + EmbeddingsRequest, + EmbeddingsResponse, + Message, + PubSubBackend, +} from "../index.js"; import { Embeddings, EmbeddingsService, @@ -9,14 +19,6 @@ import { embeddingsError, runProcessorScoped, topics, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type EmbeddingsRequest, - type EmbeddingsResponse, - type Message, - type PubSubBackend, } from "../index.js"; class WaitForTimeout extends S.TaggedErrorClass()( diff --git a/ts/packages/base/src/__tests__/flow-processor-runtime.test.ts b/ts/packages/base/src/__tests__/flow-processor-runtime.test.ts index 25537326..80c100a2 100644 --- a/ts/packages/base/src/__tests__/flow-processor-runtime.test.ts +++ b/ts/packages/base/src/__tests__/flow-processor-runtime.test.ts @@ -1,6 +1,15 @@ import { describe, expect, it } from "@effect/vitest"; import { ConfigProvider, Effect, Fiber } from "effect"; import * as S from "effect/Schema"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + Message, + ProcessorConfig, + PubSubBackend, +} from "../index.js"; import { FlowProcessor, MessagingRuntimeLive, @@ -9,13 +18,6 @@ import { runFlowProcessorDefinitionScoped, runProcessorScoped, topics, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type Message, - type ProcessorConfig, - type PubSubBackend, } from "../index.js"; class WaitForTimeout extends S.TaggedErrorClass()( diff --git a/ts/packages/base/src/__tests__/flow-spec-runtime.test.ts b/ts/packages/base/src/__tests__/flow-spec-runtime.test.ts index 160ff6a5..27044e8d 100644 --- a/ts/packages/base/src/__tests__/flow-spec-runtime.test.ts +++ b/ts/packages/base/src/__tests__/flow-spec-runtime.test.ts @@ -2,6 +2,15 @@ import { describe, expect, it } from "@effect/vitest"; import { ConfigProvider, Duration, Effect, Fiber } from "effect"; import * as S from "effect/Schema"; import * as TestClock from "effect/testing/TestClock"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + FlowContext, + Message, + PubSubBackend, +} from "../index.js"; import { makeConsumerSpec, Flow, @@ -10,13 +19,6 @@ import { makeProducerSpec, PubSub, makeRequestResponseSpec, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type FlowContext, - type Message, - type PubSubBackend, } from "../index.js"; function createMessage(value: T, properties: Record = {}): Message { diff --git a/ts/packages/base/src/__tests__/messaging-runtime.test.ts b/ts/packages/base/src/__tests__/messaging-runtime.test.ts index 13830c0e..04f6e5b0 100644 --- a/ts/packages/base/src/__tests__/messaging-runtime.test.ts +++ b/ts/packages/base/src/__tests__/messaging-runtime.test.ts @@ -1,6 +1,15 @@ import { describe, expect, it } from "@effect/vitest"; import { Duration, Effect, Fiber } from "effect"; import * as TestClock from "effect/testing/TestClock"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + FlowContext, + Message, + PubSubBackend, +} from "../index.js"; import { PubSub, defaultMessagingRuntimeConfig, @@ -11,13 +20,6 @@ import { runEffectProducerScoped, runFlowScoped, tooManyRequestsError, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type FlowContext, - type Message, - type PubSubBackend, } from "../index.js"; import type { Flow } from "../processor/flow.js"; import { Flow as RuntimeFlow } from "../processor/flow.js"; diff --git a/ts/packages/base/src/__tests__/producer.test.ts b/ts/packages/base/src/__tests__/producer.test.ts index fa812a80..1643f127 100644 --- a/ts/packages/base/src/__tests__/producer.test.ts +++ b/ts/packages/base/src/__tests__/producer.test.ts @@ -1,13 +1,15 @@ import { describe, expect, it } from "vitest"; import { Effect } from "effect"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + PubSubBackend, +} from "../index.js"; import { makeProducer, pubSubError, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type PubSubBackend, } from "../index.js"; class ProducerBackend implements PubSubBackend { diff --git a/ts/packages/base/src/__tests__/request-response.test.ts b/ts/packages/base/src/__tests__/request-response.test.ts index 3e4643d3..c3414763 100644 --- a/ts/packages/base/src/__tests__/request-response.test.ts +++ b/ts/packages/base/src/__tests__/request-response.test.ts @@ -1,13 +1,15 @@ import { describe, expect, it } from "vitest"; import { Effect } from "effect"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + Message, + PubSubBackend, +} from "../index.js"; import { makeRequestResponse, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type Message, - type PubSubBackend, } from "../index.js"; function createMessage(value: T, properties: Record = {}): Message { diff --git a/ts/packages/base/src/__tests__/runtime-services.test.ts b/ts/packages/base/src/__tests__/runtime-services.test.ts index bfea144f..7786eb44 100644 --- a/ts/packages/base/src/__tests__/runtime-services.test.ts +++ b/ts/packages/base/src/__tests__/runtime-services.test.ts @@ -1,18 +1,20 @@ import { describe, expect, it } from "@effect/vitest"; import { Effect } from "effect"; import * as S from "effect/Schema"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + Message, + ProcessorConfig, + PubSubBackend, +} from "../index.js"; import { PubSub, makeAsyncProcessor, pubSubError, runProcessorScoped, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type Message, - type ProcessorConfig, - type PubSubBackend, } from "../index.js"; class RuntimeServicesTestError extends S.TaggedErrorClass()( diff --git a/ts/packages/base/src/backend/nats.ts b/ts/packages/base/src/backend/nats.ts index 2c41ae61..b8bbc1fa 100644 --- a/ts/packages/base/src/backend/nats.ts +++ b/ts/packages/base/src/backend/nats.ts @@ -8,16 +8,18 @@ * Python reference: trustgraph-base/trustgraph/base/pulsar_backend.py */ +import type { + NatsConnection, + JetStreamClient, + JetStreamManager, + Consumer as NatsJsConsumer, + JsMsg, + JetStreamPublishOptions, +} from "nats"; import { connect, ErrorCode, - type NatsConnection, - type JetStreamClient, - type JetStreamManager, - type Consumer as NatsJsConsumer, headers, - type JsMsg, - type JetStreamPublishOptions, NatsError, StringCodec, AckPolicy, @@ -36,7 +38,8 @@ import type { CreateConsumerOptions, Message, } from "./types.js"; -import { pubSubError, type PubSubError } from "../errors.js"; +import type { PubSubError } from "../errors.js"; +import { pubSubError, } from "../errors.js"; const sc = StringCodec(); diff --git a/ts/packages/base/src/messaging/consumer.ts b/ts/packages/base/src/messaging/consumer.ts index 47f0bb17..350730fe 100644 --- a/ts/packages/base/src/messaging/consumer.ts +++ b/ts/packages/base/src/messaging/consumer.ts @@ -7,20 +7,25 @@ import type { PubSubBackend } from "../backend/types.js"; import { PubSub } from "../backend/pubsub.js"; import type { Flow } from "../processor/flow.js"; -import { +import type { MessagingHandlerError, + MessagingLifecycleError, +} from "../errors.js"; +import { TooManyRequestsError, messagingHandlerError, messagingLifecycleError, - type MessagingLifecycleError, } from "../errors.js"; -import { Config as EffectConfig, Effect, Exit, Scope } from "effect"; +import type { Config as EffectConfig, } from "effect"; +import { Effect, Exit, Scope } from "effect"; import * as P from "effect/Predicate"; import * as S from "effect/Schema"; import { loadMessagingRuntimeConfig } from "../runtime/index.ts"; +import type { + EffectConsumer, +} from "./runtime.js"; import { makeEffectConsumerFromPubSub, - type EffectConsumer, } from "./runtime.js"; export type MessageHandler = ( diff --git a/ts/packages/base/src/messaging/producer.ts b/ts/packages/base/src/messaging/producer.ts index e8b6a72f..e432a8c7 100644 --- a/ts/packages/base/src/messaging/producer.ts +++ b/ts/packages/base/src/messaging/producer.ts @@ -8,11 +8,14 @@ import type { PubSubBackend } from "../backend/types.js"; import type { ProducerMetrics } from "../metrics/index.ts"; import { Effect, Exit, Scope } from "effect"; import { PubSub } from "../backend/pubsub.js"; -import { makeEffectProducerFromPubSub, type EffectProducer } from "./runtime.js"; +import type { EffectProducer } from "./runtime.js"; +import { makeEffectProducerFromPubSub, } from "./runtime.js"; +import type { + MessagingDeliveryError, + MessagingLifecycleError, +} from "../errors.js"; import { messagingLifecycleError, - type MessagingDeliveryError, - type MessagingLifecycleError, } from "../errors.js"; export interface Producer { diff --git a/ts/packages/base/src/messaging/request-response.ts b/ts/packages/base/src/messaging/request-response.ts index 639c82dd..9ae1d044 100644 --- a/ts/packages/base/src/messaging/request-response.ts +++ b/ts/packages/base/src/messaging/request-response.ts @@ -7,21 +7,26 @@ * Python reference: trustgraph-base/trustgraph/base/request_response_spec.py */ -import { Config as EffectConfig, Effect, Exit, Scope } from "effect"; +import type { Config as EffectConfig, } from "effect"; +import { Effect, Exit, Scope } from "effect"; import type { PubSubBackend } from "../backend/types.js"; import { PubSub } from "../backend/pubsub.js"; +import type { + MessagingDeliveryError, + MessagingLifecycleError, + MessagingTimeoutError, + PubSubError, +} from "../errors.js"; import { messagingLifecycleError, - type MessagingDeliveryError, - type MessagingLifecycleError, - type MessagingTimeoutError, - type PubSubError, } from "../errors.js"; import { loadMessagingRuntimeConfig } from "../runtime/index.ts"; +import type { + EffectRequestOptions, + EffectRequestResponse, +} from "./runtime.js"; import { makeEffectRequestResponseFromPubSub, - type EffectRequestOptions, - type EffectRequestResponse, } from "./runtime.js"; export interface RequestResponseOptions { diff --git a/ts/packages/base/src/messaging/runtime.ts b/ts/packages/base/src/messaging/runtime.ts index 4f792a7d..9be7efee 100644 --- a/ts/packages/base/src/messaging/runtime.ts +++ b/ts/packages/base/src/messaging/runtime.ts @@ -3,6 +3,9 @@ */ import { randomUUID } from "node:crypto"; +import type { + Scope, +} from "effect"; import { Context, Deferred, @@ -14,7 +17,6 @@ import { Ref, Result, Schedule, - Scope, Stream, } from "effect"; import * as O from "effect/Option"; @@ -26,7 +28,16 @@ import type { CreateProducerOptions, Message, } from "../backend/types.js"; -import { PubSub, type PubSubService } from "../backend/pubsub.js"; +import type { PubSubService } from "../backend/pubsub.js"; +import { PubSub, } from "../backend/pubsub.js"; +import type { + FlowRuntimeError, + MessagingDeliveryError, + MessagingHandlerError, + MessagingLifecycleError, + MessagingTimeoutError, + PubSubError, +} from "../errors.js"; import { flowRuntimeError, messagingDeliveryError, @@ -34,20 +45,16 @@ import { messagingLifecycleError, messagingTimeoutError, TooManyRequestsError, - type FlowRuntimeError, - type MessagingDeliveryError, - type MessagingHandlerError, - type MessagingLifecycleError, - type MessagingTimeoutError, - type PubSubError, } from "../errors.js"; import type { ProducerMetrics } from "../metrics/index.js"; import type { FlowContext } from "./consumer.js"; import type { Flow } from "../processor/flow.js"; import type { SpecRuntimeRequirements } from "../spec/types.js"; +import type { + MessagingRuntimeConfig, +} from "../runtime/messaging-config.js"; import { loadMessagingRuntimeConfig, - type MessagingRuntimeConfig, } from "../runtime/messaging-config.js"; const isTooManyRequestsError = S.is(TooManyRequestsError); diff --git a/ts/packages/base/src/metrics/prometheus.ts b/ts/packages/base/src/metrics/prometheus.ts index 9dcfd374..cb7c422f 100644 --- a/ts/packages/base/src/metrics/prometheus.ts +++ b/ts/packages/base/src/metrics/prometheus.ts @@ -4,7 +4,8 @@ * Python reference: trustgraph-base/trustgraph/base/metrics.py */ -import { Effect, Metric } from "effect"; +import type { Effect, } from "effect"; +import { Metric } from "effect"; import { PrometheusMetrics } from "effect/unstable/observability"; export const prometheusContentType = "text/plain; version=0.0.4; charset=utf-8"; diff --git a/ts/packages/base/src/processor/async-processor.ts b/ts/packages/base/src/processor/async-processor.ts index 46fb6339..1737d0f6 100644 --- a/ts/packages/base/src/processor/async-processor.ts +++ b/ts/packages/base/src/processor/async-processor.ts @@ -8,8 +8,10 @@ import type { PubSubBackend } from "../backend/types.js"; import { makeNatsBackend, makeNatsBackendScoped } from "../backend/nats.js"; -import { Cause, Config as EffectConfig, Context, Effect } from "effect"; -import { processorLifecycleError, type ProcessorLifecycleError } from "../errors.js"; +import type { Cause, Config as EffectConfig, } from "effect"; +import { Context, Effect } from "effect"; +import type { ProcessorLifecycleError } from "../errors.js"; +import { processorLifecycleError, } from "../errors.js"; import { loadProcessorRuntimeConfig } from "../runtime/config.js"; export interface ProcessorConfig { diff --git a/ts/packages/base/src/processor/flow-processor.ts b/ts/packages/base/src/processor/flow-processor.ts index 84c48b1b..a5c83e7f 100644 --- a/ts/packages/base/src/processor/flow-processor.ts +++ b/ts/packages/base/src/processor/flow-processor.ts @@ -7,23 +7,28 @@ * Python reference: trustgraph-base/trustgraph/base/flow_processor.py */ +import type { + AsyncProcessorRuntime, + EffectConfigHandler, + ProcessorRuntime, + ProcessorConfig, +} from "./async-processor.js"; import { makeAsyncProcessor, - type AsyncProcessorRuntime, - type EffectConfigHandler, - type ProcessorRuntime, - type ProcessorConfig, } from "./async-processor.js"; import type { Spec } from "../spec/types.js"; import type { BackendConsumer, PubSubBackend } from "../backend/types.js"; -import { Flow, type FlowDefinition } from "./flow.js"; +import type { FlowDefinition } from "./flow.js"; +import { Flow, } from "./flow.js"; import { topics } from "../schema/topics.js"; +import type { + FlowRuntimeError, + ProcessorLifecycleError, + PubSubError, +} from "../errors.js"; import { errorMessage, pubSubError, - type FlowRuntimeError, - type ProcessorLifecycleError, - type PubSubError, } from "../errors.js"; import { ConsumerFactory, @@ -37,7 +42,8 @@ import { } from "../messaging/runtime.js"; import { makePubSubService, PubSub } from "../backend/pubsub.js"; import { loadMessagingRuntimeConfig } from "../runtime/index.ts"; -import { Config as EffectConfig, Context, Duration, Effect, Exit, Scope } from "effect"; +import type { Config as EffectConfig, Context, } from "effect"; +import { Duration, Effect, Exit, Scope } from "effect"; import * as MutableHashMap from "effect/MutableHashMap"; import * as O from "effect/Option"; import * as S from "effect/Schema"; diff --git a/ts/packages/base/src/processor/flow.ts b/ts/packages/base/src/processor/flow.ts index 7e03512a..ceaa9e36 100644 --- a/ts/packages/base/src/processor/flow.ts +++ b/ts/packages/base/src/processor/flow.ts @@ -4,30 +4,35 @@ * Python reference: trustgraph-base/trustgraph/base/flow.py */ -import { Config as EffectConfig, Context, Effect, Exit, Scope } from "effect"; +import type { Config as EffectConfig, Context, } from "effect"; +import { Effect, Exit, Scope } from "effect"; import * as MutableHashMap from "effect/MutableHashMap"; import * as O from "effect/Option"; import * as S from "effect/Schema"; import type { PubSubBackend } from "../backend/types.js"; import { makePubSubService } from "../backend/pubsub.js"; +import type { + FlowParameterDecodeError, + FlowResourceNotFoundError, + MessagingDeliveryError, + MessagingLifecycleError, + MessagingTimeoutError, + PubSubError, +} from "../errors.js"; import { flowParameterDecodeError, flowResourceNotFoundError, - type FlowParameterDecodeError, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type MessagingLifecycleError, - type MessagingTimeoutError, - type PubSubError, } from "../errors.js"; +import type { + EffectConsumer, + EffectProducer, + EffectRequestOptions, + EffectRequestResponse, +} from "../messaging/runtime.js"; import { ConsumerFactory, ProducerFactory, RequestResponseFactory, - type EffectConsumer, - type EffectProducer, - type EffectRequestOptions, - type EffectRequestResponse, makeConsumerFactoryService, makeProducerFactoryService, makeRequestResponseFactoryService, diff --git a/ts/packages/base/src/processor/program.ts b/ts/packages/base/src/processor/program.ts index 411069af..1f3bffb2 100644 --- a/ts/packages/base/src/processor/program.ts +++ b/ts/packages/base/src/processor/program.ts @@ -5,11 +5,12 @@ * executable path while the processor internals remain Promise-based. */ -import { Config as EffectConfig, Effect, Layer } from "effect"; -import { - type FlowRuntimeError, - type ProcessorLifecycleError, - type PubSubError, +import type { Config as EffectConfig, } from "effect"; +import { Effect, Layer } from "effect"; +import type { + FlowRuntimeError, + ProcessorLifecycleError, + PubSubError, } from "../errors.js"; import { makeNatsBackendScoped } from "../backend/nats.js"; import { makePubSubService, PubSub } from "../backend/pubsub.js"; @@ -23,9 +24,11 @@ import { makeRequestResponseFactoryService, runFlowRuntimeScoped, } from "../messaging/runtime.js"; +import type { + ProcessorRuntimeConfigOptions, +} from "../runtime/config.js"; import { loadProcessorRuntimeConfig, - type ProcessorRuntimeConfigOptions, } from "../runtime/config.js"; import { loadMessagingRuntimeConfig } from "../runtime/messaging-config.js"; import type { diff --git a/ts/packages/base/src/services/embeddings-service.ts b/ts/packages/base/src/services/embeddings-service.ts index be75e400..88d52013 100644 --- a/ts/packages/base/src/services/embeddings-service.ts +++ b/ts/packages/base/src/services/embeddings-service.ts @@ -5,11 +5,13 @@ */ import { Context, Effect } from "effect"; +import type { + EmbeddingsError, + FlowResourceNotFoundError, + MessagingDeliveryError, +} from "../errors.js"; import { errorMessage, - type EmbeddingsError, - type FlowResourceNotFoundError, - type MessagingDeliveryError, } from "../errors.js"; import type { FlowContext } from "../messaging/consumer.js"; import { makeFlowProcessor } from "../processor/index.ts"; diff --git a/ts/packages/base/src/services/llm-service.ts b/ts/packages/base/src/services/llm-service.ts index e30ee396..bf827691 100644 --- a/ts/packages/base/src/services/llm-service.ts +++ b/ts/packages/base/src/services/llm-service.ts @@ -6,10 +6,12 @@ import { Context, Effect, Stream } from "effect"; import * as S from "effect/Schema"; +import type { + FlowResourceNotFoundError, + MessagingDeliveryError, +} from "../errors.js"; import { errorMessage, - type FlowResourceNotFoundError, - type MessagingDeliveryError, } from "../errors.js"; import type { FlowContext } from "../messaging/consumer.js"; import { makeFlowProcessor } from "../processor/index.ts"; diff --git a/ts/packages/base/src/spec/consumer-spec.ts b/ts/packages/base/src/spec/consumer-spec.ts index 89807ecf..835946f0 100644 --- a/ts/packages/base/src/spec/consumer-spec.ts +++ b/ts/packages/base/src/spec/consumer-spec.ts @@ -8,12 +8,14 @@ import { Effect } from "effect"; import type { Spec } from "./types.js"; import type { SpecRuntimeRequirements } from "./types.js"; import type { Flow, FlowDefinition } from "../processor/flow.js"; -import { - ConsumerFactory, - type EffectMessageHandler, +import type { + EffectMessageHandler, } from "../messaging/runtime.js"; import { - type PubSubError, + ConsumerFactory, +} from "../messaging/runtime.js"; +import type { + PubSubError, } from "../errors.js"; declare const ConsumerSpecType: unique symbol; diff --git a/ts/packages/base/src/spec/producer-spec.ts b/ts/packages/base/src/spec/producer-spec.ts index 27c6fcaf..30ed5223 100644 --- a/ts/packages/base/src/spec/producer-spec.ts +++ b/ts/packages/base/src/spec/producer-spec.ts @@ -7,13 +7,17 @@ import { Effect } from "effect"; import type { SpecRuntimeRequirements } from "./types.js"; import type { Flow, FlowDefinition } from "../processor/flow.js"; -import { - flowResourceNotFoundError, - type FlowResourceNotFoundError, - type PubSubError, +import type { + FlowResourceNotFoundError, + PubSubError, } from "../errors.js"; import { - type EffectProducer, + flowResourceNotFoundError, +} from "../errors.js"; +import type { + EffectProducer, +} from "../messaging/runtime.js"; +import { ProducerFactory, } from "../messaging/runtime.js"; diff --git a/ts/packages/base/src/spec/request-response-spec.ts b/ts/packages/base/src/spec/request-response-spec.ts index fc9af214..be040e0d 100644 --- a/ts/packages/base/src/spec/request-response-spec.ts +++ b/ts/packages/base/src/spec/request-response-spec.ts @@ -10,13 +10,17 @@ import { Effect } from "effect"; import type { SpecRuntimeRequirements } from "./types.js"; import type { Flow, FlowDefinition } from "../processor/flow.js"; -import { - flowResourceNotFoundError, - type FlowResourceNotFoundError, - type PubSubError, +import type { + FlowResourceNotFoundError, + PubSubError, } from "../errors.js"; import { - type EffectRequestResponse, + flowResourceNotFoundError, +} from "../errors.js"; +import type { + EffectRequestResponse, +} from "../messaging/runtime.js"; +import { RequestResponseFactory, } from "../messaging/runtime.js"; diff --git a/ts/packages/cli/package.json b/ts/packages/cli/package.json index d1a0266b..fd374c6a 100644 --- a/ts/packages/cli/package.json +++ b/ts/packages/cli/package.json @@ -9,7 +9,8 @@ "build": "bunx --bun tsc", "dev": "tsc --watch", "clean": "rm -rf dist", - "test": "bunx --bun vitest run --passWithNoTests --exclude=dist/**" + "test": "bunx --bun vitest run --passWithNoTests --exclude=dist/**", + "lint": "bunx --bun biome check src" }, "dependencies": { "@effect/platform-bun": "4.0.0-beta.78", diff --git a/ts/packages/cli/src/commands/agent.ts b/ts/packages/cli/src/commands/agent.ts index 7ef213c6..631fc265 100644 --- a/ts/packages/cli/src/commands/agent.ts +++ b/ts/packages/cli/src/commands/agent.ts @@ -7,7 +7,8 @@ import { Effect } from "effect"; import * as Argument from "effect/unstable/cli/Argument"; import * as Command from "effect/unstable/cli/Command"; -import { cliCommandError, withGatewayClient, type CliCommandError } from "./util.js"; +import type { CliCommandError } from "./util.js"; +import { cliCommandError, withGatewayClient, } from "./util.js"; function asRecord(value: unknown): Record { return typeof value === "object" && value !== null && !Array.isArray(value) diff --git a/ts/packages/cli/src/commands/util.ts b/ts/packages/cli/src/commands/util.ts index a492555e..f21243cc 100644 --- a/ts/packages/cli/src/commands/util.ts +++ b/ts/packages/cli/src/commands/util.ts @@ -2,11 +2,13 @@ * Shared CLI utilities. */ +import type { + BaseApi, + TrustGraphGatewayClient, +} from "@trustgraph/client"; import { createTrustGraphSocket, makeTrustGraphGatewayClientScoped, - type BaseApi, - type TrustGraphGatewayClient, } from "@trustgraph/client"; import { Duration, Effect } from "effect"; import * as O from "effect/Option"; diff --git a/ts/packages/client/package.json b/ts/packages/client/package.json index b42faa75..b044a869 100644 --- a/ts/packages/client/package.json +++ b/ts/packages/client/package.json @@ -19,7 +19,8 @@ "build": "bunx --bun tsc", "dev": "tsc --watch", "clean": "rm -rf dist", - "test": "bunx --bun vitest run" + "test": "bunx --bun vitest run", + "lint": "bunx --bun biome check src" }, "dependencies": { "effect": "4.0.0-beta.78" @@ -36,7 +37,6 @@ "@effect/vitest": "4.0.0-beta.78", "@types/node": "^22.0.0", "@types/ws": "^8.5.0", - "typescript": "^5.8.0", "vitest": "^4.1.6", "happy-dom": "^20.0.0" diff --git a/ts/packages/client/src/__tests__/flows-api.test.ts b/ts/packages/client/src/__tests__/flows-api.test.ts index 5ca9edc9..c8f0294a 100644 --- a/ts/packages/client/src/__tests__/flows-api.test.ts +++ b/ts/packages/client/src/__tests__/flows-api.test.ts @@ -1,6 +1,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; +import type { BaseApi } from "../socket/trustgraph-socket"; import { FlowsApi, TrustGraphSocketError } from "../socket/trustgraph-socket"; -import { FlowResponse } from "../models/messages"; +import type { FlowResponse } from "../models/messages"; describe("FlowsApi", () => { let mockApi: { @@ -12,8 +13,7 @@ describe("FlowsApi", () => { mockApi = { makeRequest: vi.fn(), }; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - flowsApi = FlowsApi(mockApi as any); + flowsApi = FlowsApi(mockApi as unknown as BaseApi); }); describe("startFlow", () => { diff --git a/ts/packages/client/src/__tests__/messages.test.ts b/ts/packages/client/src/__tests__/messages.test.ts index 33939b00..f92c307a 100644 --- a/ts/packages/client/src/__tests__/messages.test.ts +++ b/ts/packages/client/src/__tests__/messages.test.ts @@ -342,7 +342,7 @@ describe("Message Types", () => { type: "library-error", }); expect(response["document-metadatas"]).toHaveLength(1); - expect(response["document-metadatas"]![0].id).toBe("doc-1"); + expect(response["document-metadatas"]?.[0].id).toBe("doc-1"); }); }); diff --git a/ts/packages/client/src/__tests__/rpc-timeout.test.ts b/ts/packages/client/src/__tests__/rpc-timeout.test.ts index fcf160eb..99eb3588 100644 --- a/ts/packages/client/src/__tests__/rpc-timeout.test.ts +++ b/ts/packages/client/src/__tests__/rpc-timeout.test.ts @@ -1,8 +1,10 @@ import { Effect } from "effect"; import { describe, expect, it, vi } from "vitest"; import { DispatchError, DispatchStreamChunk } from "../rpc/contract"; -import { type DispatchInput, type RpcConnectionState, withDispatchRequestPolicy } from "../socket/effect-rpc-client"; -import { type ConnectionState, makeBaseApiWithRpc } from "../socket/trustgraph-socket"; +import type { DispatchInput, RpcConnectionState, } from "../socket/effect-rpc-client"; +import { withDispatchRequestPolicy } from "../socket/effect-rpc-client"; +import type { ConnectionState, } from "../socket/trustgraph-socket"; +import { makeBaseApiWithRpc } from "../socket/trustgraph-socket"; const input: DispatchInput = { scope: "global", diff --git a/ts/packages/client/src/__tests__/workbench-contracts.test.ts b/ts/packages/client/src/__tests__/workbench-contracts.test.ts index abf0ada4..49269cc8 100644 --- a/ts/packages/client/src/__tests__/workbench-contracts.test.ts +++ b/ts/packages/client/src/__tests__/workbench-contracts.test.ts @@ -1,6 +1,8 @@ import { describe, expect, it, vi } from "vitest"; -import { +import type { BaseApi, +} from "../socket/trustgraph-socket"; +import { ConfigApi, KnowledgeApi, LibrarianApi, diff --git a/ts/packages/client/src/models/namespaces.ts b/ts/packages/client/src/models/namespaces.ts index df75fc04..9248c990 100644 --- a/ts/packages/client/src/models/namespaces.ts +++ b/ts/packages/client/src/models/namespaces.ts @@ -5,38 +5,38 @@ // TrustGraph namespace export const TG = "https://trustgraph.ai/ns/"; -export const TG_QUERY = TG + "query"; -export const TG_EDGE_COUNT = TG + "edgeCount"; -export const TG_SELECTED_EDGE = TG + "selectedEdge"; -export const TG_EDGE = TG + "edge"; -export const TG_REASONING = TG + "reasoning"; -export const TG_CONTENT = TG + "content"; -export const TG_REIFIES = TG + "reifies"; -export const TG_DOCUMENT = TG + "document"; +export const TG_QUERY = `${TG}query`; +export const TG_EDGE_COUNT = `${TG}edgeCount`; +export const TG_SELECTED_EDGE = `${TG}selectedEdge`; +export const TG_EDGE = `${TG}edge`; +export const TG_REASONING = `${TG}reasoning`; +export const TG_CONTENT = `${TG}content`; +export const TG_REIFIES = `${TG}reifies`; +export const TG_DOCUMENT = `${TG}document`; // W3C PROV-O namespace export const PROV = "http://www.w3.org/ns/prov#"; -export const PROV_STARTED_AT_TIME = PROV + "startedAtTime"; -export const PROV_WAS_DERIVED_FROM = PROV + "wasDerivedFrom"; -export const PROV_WAS_GENERATED_BY = PROV + "wasGeneratedBy"; -export const PROV_ACTIVITY = PROV + "Activity"; -export const PROV_ENTITY = PROV + "Entity"; +export const PROV_STARTED_AT_TIME = `${PROV}startedAtTime`; +export const PROV_WAS_DERIVED_FROM = `${PROV}wasDerivedFrom`; +export const PROV_WAS_GENERATED_BY = `${PROV}wasGeneratedBy`; +export const PROV_ACTIVITY = `${PROV}Activity`; +export const PROV_ENTITY = `${PROV}Entity`; // RDFS namespace export const RDFS = "http://www.w3.org/2000/01/rdf-schema#"; -export const RDFS_LABEL = RDFS + "label"; +export const RDFS_LABEL = `${RDFS}label`; // RDF namespace export const RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; -export const RDF_TYPE = RDF + "type"; +export const RDF_TYPE = `${RDF}type`; // Schema.org namespace (used in document metadata) export const SCHEMA = "https://schema.org/"; -export const SCHEMA_NAME = SCHEMA + "name"; -export const SCHEMA_DESCRIPTION = SCHEMA + "description"; -export const SCHEMA_AUTHOR = SCHEMA + "author"; -export const SCHEMA_KEYWORDS = SCHEMA + "keywords"; +export const SCHEMA_NAME = `${SCHEMA}name`; +export const SCHEMA_DESCRIPTION = `${SCHEMA}description`; +export const SCHEMA_AUTHOR = `${SCHEMA}author`; +export const SCHEMA_KEYWORDS = `${SCHEMA}keywords`; // SKOS namespace export const SKOS = "http://www.w3.org/2004/02/skos/core#"; -export const SKOS_DEFINITION = SKOS + "definition"; +export const SKOS_DEFINITION = `${SKOS}definition`; diff --git a/ts/packages/client/src/socket/effect-rpc-client.ts b/ts/packages/client/src/socket/effect-rpc-client.ts index a3669e86..08928591 100644 --- a/ts/packages/client/src/socket/effect-rpc-client.ts +++ b/ts/packages/client/src/socket/effect-rpc-client.ts @@ -4,7 +4,8 @@ import * as RpcClient from "effect/unstable/rpc/RpcClient"; import type { RpcClientError } from "effect/unstable/rpc/RpcClientError"; import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"; import * as Socket from "effect/unstable/socket/Socket"; -import { DispatchPayload, DispatchError, TrustGraphRpcs, type DispatchStreamChunk } from "../rpc/contract.js"; +import type { DispatchStreamChunk } from "../rpc/contract.js"; +import { DispatchPayload, DispatchError, TrustGraphRpcs, } from "../rpc/contract.js"; type TrustGraphRpcClient = RpcClient.RpcClient< RpcGroup.Rpcs, diff --git a/ts/packages/client/src/socket/trustgraph-socket.ts b/ts/packages/client/src/socket/trustgraph-socket.ts index 7d66c2b1..7eb543d4 100644 --- a/ts/packages/client/src/socket/trustgraph-socket.ts +++ b/ts/packages/client/src/socket/trustgraph-socket.ts @@ -1,10 +1,12 @@ // Import core types and classes for the TrustGraph API import type { Term, Triple } from "../models/Triple.js"; +import type { + EffectRpcClient, + DispatchInput, + DispatchOptions, + RpcConnectionState, +} from "./effect-rpc-client.js"; import { - type EffectRpcClient, - type DispatchInput, - type DispatchOptions, - type RpcConnectionState, makeEffectRpcClient, } from "./effect-rpc-client.js"; import { getDefaultSocketUrl, getRandomValues } from "./websocket-adapter.js"; @@ -479,7 +481,7 @@ export function makeBaseApi( hasApiKey: isNonEmptyString(token), }), ); - let lastError: string | undefined = undefined; + let lastError: string | undefined ; let rpcState: RpcConnectionState = { status: "connecting" }; const api = { @@ -536,7 +538,7 @@ export function makeBaseApi( * Format: {clientTag}-{incrementingNumber} */ getNextId() { - const mid = api.tag + "-" + api.id.toString(); + const mid = `${api.tag}-${api.id.toString()}`; api.id++; return mid; }, @@ -2530,11 +2532,10 @@ export function makeKnowledgeApi(api: BaseApi) { // End of stream - notify receiver and signal completion receiver(msg, true); return true; - } else { + } // Regular message - continue streaming receiver(msg, false); return false; - } }; return this.api.makeRequestMulti( diff --git a/ts/packages/client/src/socket/websocket-adapter.ts b/ts/packages/client/src/socket/websocket-adapter.ts index 92d9bf27..29896a71 100644 --- a/ts/packages/client/src/socket/websocket-adapter.ts +++ b/ts/packages/client/src/socket/websocket-adapter.ts @@ -56,8 +56,7 @@ export interface IsomorphicWebSocket { addEventListener(type: "close", listener: (event: WsCloseEvent) => void): void; addEventListener(type: "open", listener: (event: WsEvent) => void): void; addEventListener(type: "error", listener: (event: WsEvent) => void): void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - removeEventListener(type: string, listener: (...args: any[]) => void): void; + removeEventListener(type: string, listener: (...args: ReadonlyArray) => void): void; } /** Constructor signature for an isomorphic WebSocket implementation. */ diff --git a/ts/packages/flow/package.json b/ts/packages/flow/package.json index d155b42c..d4183bd0 100644 --- a/ts/packages/flow/package.json +++ b/ts/packages/flow/package.json @@ -8,7 +8,8 @@ "build": "bunx --bun tsc", "dev": "tsc --watch", "clean": "rm -rf dist", - "test": "bunx --bun vitest run" + "test": "bunx --bun vitest run", + "lint": "bunx --bun biome check src" }, "dependencies": { "@effect/ai-anthropic": "4.0.0-beta.78", diff --git a/ts/packages/flow/src/__tests__/chunking-service.test.ts b/ts/packages/flow/src/__tests__/chunking-service.test.ts index c76c4c8d..4f0a68c7 100644 --- a/ts/packages/flow/src/__tests__/chunking-service.test.ts +++ b/ts/packages/flow/src/__tests__/chunking-service.test.ts @@ -2,19 +2,21 @@ import { describe, expect, it } from "@effect/vitest"; import { ConfigProvider, Effect, Fiber } from "effect"; import * as EffectChunk from "effect/Chunk"; import * as S from "effect/Schema"; +import type { + BackendConsumer, + BackendProducer, + Chunk, + CreateConsumerOptions, + CreateProducerOptions, + Message, + PubSubBackend, + TextDocument, +} from "@trustgraph/base"; import { MessagingRuntimeLive, PubSub, runProcessorScoped, topics, - type BackendConsumer, - type BackendProducer, - type Chunk, - type CreateConsumerOptions, - type CreateProducerOptions, - type Message, - type PubSubBackend, - type TextDocument, } from "@trustgraph/base"; import { ChunkingService } from "../chunking/service.js"; import { recursiveSplit } from "../chunking/recursive-splitter.js"; diff --git a/ts/packages/flow/src/__tests__/falkordb-lifecycle.test.ts b/ts/packages/flow/src/__tests__/falkordb-lifecycle.test.ts index 85e8cb6b..5a21fbeb 100644 --- a/ts/packages/flow/src/__tests__/falkordb-lifecycle.test.ts +++ b/ts/packages/flow/src/__tests__/falkordb-lifecycle.test.ts @@ -1,16 +1,20 @@ import { Effect } from "effect"; import { describe, expect, it } from "vitest"; +import type { + FalkorDBClosableClient as FalkorDBQueryClient, + FalkorDBQueryGraph, +} from "../query/triples/falkordb.js"; import { FalkorDBTriplesQueryLive, FalkorDBTriplesQueryService, - type FalkorDBClosableClient as FalkorDBQueryClient, - type FalkorDBQueryGraph, } from "../query/triples/falkordb.js"; +import type { + FalkorDBClosableClient as FalkorDBStoreClient, + FalkorDBStoreGraph, +} from "../storage/triples/falkordb.js"; import { FalkorDBTriplesStoreLive, FalkorDBTriplesStoreService, - type FalkorDBClosableClient as FalkorDBStoreClient, - type FalkorDBStoreGraph, } from "../storage/triples/falkordb.js"; class FakeFalkorDBClient implements FalkorDBStoreClient, FalkorDBQueryClient { diff --git a/ts/packages/flow/src/__tests__/flow-manager-service.test.ts b/ts/packages/flow/src/__tests__/flow-manager-service.test.ts index 68b21804..b04c7e75 100644 --- a/ts/packages/flow/src/__tests__/flow-manager-service.test.ts +++ b/ts/packages/flow/src/__tests__/flow-manager-service.test.ts @@ -1,18 +1,20 @@ import {Effect, HashMap, Option, SynchronizedRef} from "effect"; import {describe, expect, it} from "vitest"; +import type { + BackendConsumer, + BackendProducer, + ConfigRequest, + ConfigResponse, + CreateConsumerOptions, + CreateProducerOptions, + FlowRequest, + FlowResponse, + Message, + PubSubBackend, + RequestResponse, +} from "@trustgraph/base"; import { topics, - type BackendConsumer, - type BackendProducer, - type ConfigRequest, - type ConfigResponse, - type CreateConsumerOptions, - type CreateProducerOptions, - type FlowRequest, - type FlowResponse, - type Message, - type PubSubBackend, - type RequestResponse, } from "@trustgraph/base"; import {FlowManagerError, makeFlowManagerService} from "../flow-manager/service.js"; diff --git a/ts/packages/flow/src/__tests__/gateway-routes.test.ts b/ts/packages/flow/src/__tests__/gateway-routes.test.ts index e2180785..db1d743b 100644 --- a/ts/packages/flow/src/__tests__/gateway-routes.test.ts +++ b/ts/packages/flow/src/__tests__/gateway-routes.test.ts @@ -3,7 +3,8 @@ import { Effect, Exit, Scope } from "effect"; import { HttpRouter, HttpServerResponse } from "effect/unstable/http"; import type { DispatcherManager } from "../gateway/dispatch/manager.js"; import type { GatewayRpcServer } from "../gateway/rpc-server.js"; -import { makeGatewayRoutes, type GatewayConfig } from "../gateway/server.js"; +import type { GatewayConfig } from "../gateway/server.js"; +import { makeGatewayRoutes, } from "../gateway/server.js"; interface DispatchCall { readonly scope: "global" | "flow"; diff --git a/ts/packages/flow/src/__tests__/knowledge-core-service.test.ts b/ts/packages/flow/src/__tests__/knowledge-core-service.test.ts index ef6a13d6..6c90fb46 100644 --- a/ts/packages/flow/src/__tests__/knowledge-core-service.test.ts +++ b/ts/packages/flow/src/__tests__/knowledge-core-service.test.ts @@ -3,17 +3,19 @@ import {tmpdir} from "node:os"; import {join} from "node:path"; import {Effect, HashMap, Option, SynchronizedRef} from "effect"; import {describe, expect, it} from "vitest"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + KnowledgeRequest, + KnowledgeResponse, + Message, + PubSubBackend, + Triple, +} from "@trustgraph/base"; import { topics, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type KnowledgeRequest, - type KnowledgeResponse, - type Message, - type PubSubBackend, - type Triple, } from "@trustgraph/base"; import {makeKnowledgeCoreService} from "../cores/service.js"; diff --git a/ts/packages/flow/src/__tests__/librarian-service.test.ts b/ts/packages/flow/src/__tests__/librarian-service.test.ts index c5725a71..8fb4271d 100644 --- a/ts/packages/flow/src/__tests__/librarian-service.test.ts +++ b/ts/packages/flow/src/__tests__/librarian-service.test.ts @@ -3,15 +3,15 @@ import {tmpdir} from "node:os"; import {join} from "node:path"; import {Effect} from "effect"; import {describe, expect, it} from "vitest"; -import { - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type DocumentMetadata, - type Message, - type PubSubBackend, - type Triple, +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + DocumentMetadata, + Message, + PubSubBackend, + Triple, } from "@trustgraph/base"; import {makeLibrarianService} from "../librarian/service.js"; diff --git a/ts/packages/flow/src/__tests__/prompt-template.test.ts b/ts/packages/flow/src/__tests__/prompt-template.test.ts index d875ebb0..fe4ba036 100644 --- a/ts/packages/flow/src/__tests__/prompt-template.test.ts +++ b/ts/packages/flow/src/__tests__/prompt-template.test.ts @@ -1,19 +1,21 @@ import { describe, expect, it } from "@effect/vitest"; import { ConfigProvider, Effect, Fiber } from "effect"; import * as S from "effect/Schema"; +import type { + BackendConsumer, + BackendProducer, + CreateConsumerOptions, + CreateProducerOptions, + Message, + PromptRequest, + PromptResponse, + PubSubBackend, +} from "@trustgraph/base"; import { MessagingRuntimeLive, PubSub, runProcessorScoped, topics, - type BackendConsumer, - type BackendProducer, - type CreateConsumerOptions, - type CreateProducerOptions, - type Message, - type PromptRequest, - type PromptResponse, - type PubSubBackend, } from "@trustgraph/base"; import { PromptTemplateService } from "../prompt/template.js"; diff --git a/ts/packages/flow/src/__tests__/retrieval-rag.test.ts b/ts/packages/flow/src/__tests__/retrieval-rag.test.ts index 5baec87c..9f038c14 100644 --- a/ts/packages/flow/src/__tests__/retrieval-rag.test.ts +++ b/ts/packages/flow/src/__tests__/retrieval-rag.test.ts @@ -15,8 +15,10 @@ import type { TriplesQueryRequest, TriplesQueryResponse, } from "@trustgraph/base"; -import { makeDocumentRagEngine, type DocumentRagClients } from "../retrieval/document-rag.js"; -import { makeGraphRagEngine, type GraphRagClients } from "../retrieval/graph-rag.js"; +import type { DocumentRagClients } from "../retrieval/document-rag.js"; +import { makeDocumentRagEngine, } from "../retrieval/document-rag.js"; +import type { GraphRagClients } from "../retrieval/graph-rag.js"; +import { makeGraphRagEngine, } from "../retrieval/graph-rag.js"; const requestor = ( handler: (request: TReq) => TRes, diff --git a/ts/packages/flow/src/agent/mcp-tool/service.ts b/ts/packages/flow/src/agent/mcp-tool/service.ts index efa9cb47..4ff42613 100644 --- a/ts/packages/flow/src/agent/mcp-tool/service.ts +++ b/ts/packages/flow/src/agent/mcp-tool/service.ts @@ -14,22 +14,23 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"; import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js"; import { NodeRuntime } from "@effect/platform-node"; - +import type { + ProcessorConfig, + FlowContext, + FlowProcessorRuntime, + ToolRequest, + ToolResponse, + EffectConfigHandler, + FlowResourceNotFoundError, + MessagingDeliveryError, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeProducerSpec, makeFlowProcessorProgram, errorMessage, - type ProcessorConfig, - type FlowContext, - type FlowProcessorRuntime, - type ToolRequest, - type ToolResponse, - type EffectConfigHandler, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type Spec, } from "@trustgraph/base"; import { Context, Effect, Layer, Ref } from "effect"; import * as O from "effect/Option"; diff --git a/ts/packages/flow/src/agent/react/service.ts b/ts/packages/flow/src/agent/react/service.ts index 0d4763fd..1d22e5fb 100644 --- a/ts/packages/flow/src/agent/react/service.ts +++ b/ts/packages/flow/src/agent/react/service.ts @@ -19,6 +19,27 @@ import { NodeRuntime, } from "@effect/platform-node"; +import type { + ProcessorConfig, + FlowContext, + FlowProcessorRuntime, + AgentRequest, + AgentResponse, + TextCompletionRequest, + TextCompletionResponse, + GraphRagRequest, + GraphRagResponse, + DocumentRagRequest, + DocumentRagResponse, + TriplesQueryRequest, + TriplesQueryResponse, + ToolRequest, + ToolResponse, + EffectConfigHandler, + FlowResourceNotFoundError, + MessagingDeliveryError, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, @@ -26,37 +47,19 @@ import { makeRequestResponseSpec, makeFlowProcessorProgram, errorMessage, - type ProcessorConfig, - type FlowContext, - type FlowProcessorRuntime, - type AgentRequest, - type AgentResponse, - type TextCompletionRequest, - type TextCompletionResponse, - type GraphRagRequest, - type GraphRagResponse, - type DocumentRagRequest, - type DocumentRagResponse, - type TriplesQueryRequest, - type TriplesQueryResponse, - type ToolRequest, - type ToolResponse, - type EffectConfigHandler, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type Spec, } from "@trustgraph/base"; import {Context, Effect, Layer, Match, Ref} from "effect"; import * as O from "effect/Option"; import * as Predicate from "effect/Predicate"; import * as S from "effect/Schema"; - +import type { + ExplainData, +} from "./tools.js"; import { createKnowledgeQueryTool, createDocumentQueryTool, createTriplesQueryTool, createMcpTool, - type ExplainData, } from "./tools.js"; import { buildReActPrompt } from "./prompt.js"; import { filterToolsByGroupAndState } from "../tool-filter.js"; @@ -550,9 +553,9 @@ export function parseReActResponse(text: string): { const firstLine = trimmed.slice("Final Answer:".length).trim(); const remainingLines = lines.slice(i + 1).join("\n").trim(); finalAnswer = - firstLine + (remainingLines.length > 0 ? "\n" + remainingLines : ""); + firstLine + (remainingLines.length > 0 ? `\n${remainingLines}` : ""); break; - } else if (trimmed.startsWith("Thought:")) { + }if (trimmed.startsWith("Thought:")) { currentSection = "thought"; const content = trimmed.slice("Thought:".length).trim(); if (content.length > 0) { @@ -577,14 +580,14 @@ export function parseReActResponse(text: string): { // Continuation line for current section Match.value(currentSection).pipe( Match.when("thought", () => { - thought += "\n" + trimmed; + thought += `\n${trimmed}`; }), Match.when("action", () => { // Action should be a single line (tool name), but handle multi-line - action += " " + trimmed; + action += ` ${trimmed}`; }), Match.when("action_input", () => { - actionInput += "\n" + trimmed; + actionInput += `\n${trimmed}`; }), Match.exhaustive, ); diff --git a/ts/packages/flow/src/agent/react/tools.ts b/ts/packages/flow/src/agent/react/tools.ts index 023359a0..91290387 100644 --- a/ts/packages/flow/src/agent/react/tools.ts +++ b/ts/packages/flow/src/agent/react/tools.ts @@ -23,8 +23,8 @@ import { Effect, Match } from "effect"; import * as O from "effect/Option"; import * as Predicate from "effect/Predicate"; import * as S from "effect/Schema"; - -import { agentToolError, type AgentTool, type ToolArg } from "./types.js"; +import type { AgentTool, ToolArg } from "./types.js"; +import { agentToolError, } from "./types.js"; const decodeJsonUnknown = S.decodeUnknownOption(S.UnknownFromJsonString); const decodeTerm = S.decodeUnknownOption(TermSchema); diff --git a/ts/packages/flow/src/agent/tool-filter.ts b/ts/packages/flow/src/agent/tool-filter.ts index b0094cf7..a70b9605 100644 --- a/ts/packages/flow/src/agent/tool-filter.ts +++ b/ts/packages/flow/src/agent/tool-filter.ts @@ -30,7 +30,7 @@ function isToolAvailable( const config = tool.config ?? {}; // Get tool groups (default to ["default"]) - let toolGroups = config["group"] as string[] | string | undefined; + let toolGroups = config.group as string[] | string | undefined; if (toolGroups === undefined) toolGroups = ["default"]; if (!Array.isArray(toolGroups)) toolGroups = [toolGroups]; @@ -56,6 +56,6 @@ function isToolAvailable( * Get the next state after successful tool execution. */ export function getNextState(tool: AgentTool, currentState: string): string { - const nextState = tool.config?.["state"] as string | undefined; + const nextState = tool.config?.state as string | undefined; return nextState ?? currentState; } diff --git a/ts/packages/flow/src/chunking/service.ts b/ts/packages/flow/src/chunking/service.ts index 3dfd3991..82b256dc 100644 --- a/ts/packages/flow/src/chunking/service.ts +++ b/ts/packages/flow/src/chunking/service.ts @@ -9,20 +9,22 @@ * Python reference: trustgraph-flow/trustgraph/chunking/recursive_splitter/service.py */ +import type { + ProcessorConfig, + FlowProcessorRuntime, + FlowContext, + FlowResourceNotFoundError, + MessagingDeliveryError, + TextDocument, + Chunk, + Triples, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeProducerSpec, makeParameterSpec, - type ProcessorConfig, - type FlowProcessorRuntime, - type FlowContext, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type TextDocument, - type Chunk, - type Triples, - type Spec, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { makeFlowProcessorProgram } from "@trustgraph/base"; diff --git a/ts/packages/flow/src/config/service.ts b/ts/packages/flow/src/config/service.ts index 1be6a7fc..24fcf4bd 100644 --- a/ts/packages/flow/src/config/service.ts +++ b/ts/packages/flow/src/config/service.ts @@ -8,6 +8,16 @@ import {NodeRuntime} from "@effect/platform-node"; import {Duration, Effect, HashMap, Match, Option, SynchronizedRef} from "effect"; import * as Predicate from "effect/Predicate"; import * as S from "effect/Schema"; +import type { + AsyncProcessorRuntime, + BackendConsumer, + BackendProducer, + ConfigOperation, + ConfigRequest, + ConfigResponse, + Message, + ProcessorConfig, +} from "@trustgraph/base"; import { ConfigRequest as ConfigRequestSchema, ConfigResponse as ConfigResponseSchema, @@ -18,14 +28,6 @@ import { optionalStringConfig, processorLifecycleError, topics, - type AsyncProcessorRuntime, - type BackendConsumer, - type BackendProducer, - type ConfigOperation, - type ConfigRequest, - type ConfigResponse, - type Message, - type ProcessorConfig, } from "@trustgraph/base"; import {readTextFileEffect, writeTextFileEffect} from "../runtime/effect-files.js"; diff --git a/ts/packages/flow/src/cores/service.ts b/ts/packages/flow/src/cores/service.ts index 8756cadb..be38fbd2 100644 --- a/ts/packages/flow/src/cores/service.ts +++ b/ts/packages/flow/src/cores/service.ts @@ -5,6 +5,17 @@ */ import {NodeRuntime} from "@effect/platform-node"; +import type { + AsyncProcessorRuntime, + BackendConsumer, + BackendProducer, + KnowledgeOperation, + KnowledgeRequest, + KnowledgeResponse, + Message, + ProcessorConfig, + PubSubError, +} from "@trustgraph/base"; import { KnowledgeRequest as KnowledgeRequestSchema, KnowledgeResponse as KnowledgeResponseSchema, @@ -17,15 +28,6 @@ import { optionalStringConfig, processorLifecycleError, topics, - type AsyncProcessorRuntime, - type BackendConsumer, - type BackendProducer, - type KnowledgeOperation, - type KnowledgeRequest, - type KnowledgeResponse, - type Message, - type ProcessorConfig, - type PubSubError, } from "@trustgraph/base"; import {Duration, Effect, HashMap, Match, SynchronizedRef} from "effect"; import * as O from "effect/Option"; diff --git a/ts/packages/flow/src/decoding/pdf-decoder.ts b/ts/packages/flow/src/decoding/pdf-decoder.ts index 061258ab..526c97cd 100644 --- a/ts/packages/flow/src/decoding/pdf-decoder.ts +++ b/ts/packages/flow/src/decoding/pdf-decoder.ts @@ -15,26 +15,28 @@ import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs"; import type { TextItem } from "pdfjs-dist/types/src/display/api.js"; +import type { + ProcessorConfig, + FlowProcessorRuntime, + FlowContext, + FlowResourceNotFoundError, + Document, + TextDocument, + Triples, + Triple, + Term, + LibrarianRequest, + LibrarianResponse, + MessagingDeliveryError, + MessagingLifecycleError, + MessagingTimeoutError, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeProducerSpec, makeRequestResponseSpec, - type ProcessorConfig, - type FlowProcessorRuntime, - type FlowContext, - type FlowResourceNotFoundError, - type Document, - type TextDocument, - type Triples, - type Triple, - type Term, - type LibrarianRequest, - type LibrarianResponse, - type MessagingDeliveryError, - type MessagingLifecycleError, - type MessagingTimeoutError, - type Spec, errorMessage, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; diff --git a/ts/packages/flow/src/embeddings/ollama.ts b/ts/packages/flow/src/embeddings/ollama.ts index be95cddb..f763f8be 100644 --- a/ts/packages/flow/src/embeddings/ollama.ts +++ b/ts/packages/flow/src/embeddings/ollama.ts @@ -8,14 +8,16 @@ import { NodeRuntime } from "@effect/platform-node"; import { Config, Effect, Layer } from "effect"; import * as O from "effect/Option"; import * as S from "effect/Schema"; +import type { + EmbeddingsServiceShape, + ProcessorConfig, +} from "@trustgraph/base"; import { Embeddings, EmbeddingsError, errorMessage, makeEmbeddingsService, makeEmbeddingsSpecs, - type EmbeddingsServiceShape, - type ProcessorConfig, } from "@trustgraph/base"; import { makeFlowProcessorProgram } from "@trustgraph/base"; diff --git a/ts/packages/flow/src/extract/knowledge-extract.ts b/ts/packages/flow/src/extract/knowledge-extract.ts index d53b6016..6233bec6 100644 --- a/ts/packages/flow/src/extract/knowledge-extract.ts +++ b/ts/packages/flow/src/extract/knowledge-extract.ts @@ -10,29 +10,31 @@ * Python reference: trustgraph-flow/trustgraph/extract/knowledge/service.py */ +import type { + ProcessorConfig, + FlowProcessorRuntime, + FlowContext, + Chunk, + Triples, + EntityContexts, + EntityContext, + PromptRequest, + PromptResponse, + TextCompletionRequest, + TextCompletionResponse, + Triple, + Term, + FlowResourceNotFoundError, + MessagingDeliveryError, + EffectRequestResponse, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeProducerSpec, makeRequestResponseSpec, makeFlowProcessorProgram, - type ProcessorConfig, - type FlowProcessorRuntime, - type FlowContext, - type Chunk, - type Triples, - type EntityContexts, - type EntityContext, - type PromptRequest, - type PromptResponse, - type TextCompletionRequest, - type TextCompletionResponse, - type Triple, - type Term, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type EffectRequestResponse, - type Spec, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { Effect } from "effect"; @@ -375,7 +377,7 @@ function jsonCandidates(raw: string): ReadonlyArray { const partial = arrayMatch[0]; const lastBrace = partial.lastIndexOf("}"); if (lastBrace > 0) { - candidates.push(partial.slice(0, lastBrace + 1) + "]"); + candidates.push(`${partial.slice(0, lastBrace + 1)}]`); } } diff --git a/ts/packages/flow/src/flow-manager/service.ts b/ts/packages/flow/src/flow-manager/service.ts index 7f0ddb58..66c4136f 100644 --- a/ts/packages/flow/src/flow-manager/service.ts +++ b/ts/packages/flow/src/flow-manager/service.ts @@ -14,21 +14,23 @@ * Python reference: trustgraph-flow/trustgraph/flow/service.py */ +import type { + ProcessorConfig, + AsyncProcessorRuntime, + BackendConsumer, + BackendProducer, + RequestResponse, + ConfigRequest, + ConfigResponse, + FlowRequest, + FlowResponse, +} from "@trustgraph/base"; import { makeAsyncProcessor, - type ProcessorConfig, - type AsyncProcessorRuntime, - type BackendConsumer, - type BackendProducer, topics, makeRequestResponse, - type RequestResponse, - type ConfigRequest, - type ConfigResponse, FlowRequest as FlowRequestSchema, FlowResponse as FlowResponseSchema, - type FlowRequest, - type FlowResponse, errorMessage, processorLifecycleError, } from "@trustgraph/base"; diff --git a/ts/packages/flow/src/gateway/dispatch/manager.ts b/ts/packages/flow/src/gateway/dispatch/manager.ts index 428f09c5..780f5011 100644 --- a/ts/packages/flow/src/gateway/dispatch/manager.ts +++ b/ts/packages/flow/src/gateway/dispatch/manager.ts @@ -9,6 +9,15 @@ */ import { Clock, Effect, Exit, HashMap, HashSet, Option, Random, Scope, SynchronizedRef, Tuple } from "effect"; +import type { + EffectRequestResponse, + MessagingDeliveryError, + MessagingLifecycleError, + MessagingTimeoutError, + PubSubBackend, + PubSubError, + RequestResponseFactoryService, +} from "@trustgraph/base"; import { loadMessagingRuntimeConfig, makeNatsBackend, @@ -17,19 +26,14 @@ import { makeRequestResponseFactoryService, messagingDeliveryError, messagingLifecycleError, - type EffectRequestResponse, - type MessagingDeliveryError, - type MessagingLifecycleError, - type MessagingTimeoutError, - type PubSubBackend, - type PubSubError, - type RequestResponseFactoryService, } from "@trustgraph/base"; import type { GatewayConfig } from "../server.js"; +import type { + DispatchSerializationError, +} from "./serialize.js"; import { translateRequestEffect, translateResponseEffect, - type DispatchSerializationError, } from "./serialize.js"; export type EffectResponder = ( diff --git a/ts/packages/flow/src/gateway/dispatch/serialize.ts b/ts/packages/flow/src/gateway/dispatch/serialize.ts index 1ff6b239..30c97146 100644 --- a/ts/packages/flow/src/gateway/dispatch/serialize.ts +++ b/ts/packages/flow/src/gateway/dispatch/serialize.ts @@ -18,6 +18,10 @@ * Python reference: trustgraph-base/trustgraph/messaging/translators/primitives.py */ +import type { + Term, + Triple, +} from "@trustgraph/base"; import { BlankTerm, errorMessage, @@ -26,8 +30,6 @@ import { Term as TermSchema, Triple as TripleSchema, TripleTerm, - type Term, - type Triple, } from "@trustgraph/base"; import { Effect, HashSet, Match } from "effect"; import * as O from "effect/Option"; diff --git a/ts/packages/flow/src/gateway/rpc-server.ts b/ts/packages/flow/src/gateway/rpc-server.ts index 154a5fd7..74157003 100644 --- a/ts/packages/flow/src/gateway/rpc-server.ts +++ b/ts/packages/flow/src/gateway/rpc-server.ts @@ -1,10 +1,12 @@ -import { Cause, Effect, Layer, Queue, Scope } from "effect"; -import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http"; +import type { Cause, Scope } from "effect"; +import { Effect, Layer, Queue, } from "effect"; +import type { HttpServerRequest, HttpServerResponse } from "effect/unstable/http"; import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"; import * as RpcServer from "effect/unstable/rpc/RpcServer"; import { errorMessage } from "@trustgraph/base"; import type { DispatcherManager, DispatcherStreamError } from "./dispatch/manager.js"; -import { DispatchError, DispatchPayload, DispatchStreamChunk, TrustGraphRpcs } from "./rpc-contract.js"; +import type { DispatchPayload, } from "./rpc-contract.js"; +import { DispatchError, DispatchStreamChunk, TrustGraphRpcs } from "./rpc-contract.js"; export interface GatewayRpcServer { readonly httpEffect: Effect.Effect< diff --git a/ts/packages/flow/src/gateway/server.ts b/ts/packages/flow/src/gateway/server.ts index ecc1339d..a7fb9a47 100644 --- a/ts/packages/flow/src/gateway/server.ts +++ b/ts/packages/flow/src/gateway/server.ts @@ -12,17 +12,21 @@ import * as O from "effect/Option"; import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http"; import { HttpApiBuilder } from "effect/unstable/httpapi"; import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"; +import type { + PubSubBackend, +} from "@trustgraph/base"; import { formatPrometheusMetrics, messagingLifecycleError, optionalStringConfig, prometheusContentType, toTgError, - type PubSubBackend, } from "@trustgraph/base"; import { GatewayWorkbenchHttpApi } from "@trustgraph/client/rpc/contract"; -import { makeDispatcherManagerScoped, type DispatcherManager } from "./dispatch/manager.js"; -import { makeGatewayRpcServer, type GatewayRpcServer } from "./rpc-server.js"; +import type { DispatcherManager } from "./dispatch/manager.js"; +import { makeDispatcherManagerScoped, } from "./dispatch/manager.js"; +import type { GatewayRpcServer } from "./rpc-server.js"; +import { makeGatewayRpcServer, } from "./rpc-server.js"; export interface GatewayConfig { port: number; diff --git a/ts/packages/flow/src/librarian/service.ts b/ts/packages/flow/src/librarian/service.ts index 9782ae23..20ea56bb 100644 --- a/ts/packages/flow/src/librarian/service.ts +++ b/ts/packages/flow/src/librarian/service.ts @@ -10,32 +10,36 @@ * Python reference: trustgraph-flow/trustgraph/librarian/service/service.py */ +import type { + ProcessorConfig, + AsyncProcessorRuntime, + BackendConsumer, + BackendProducer, + LibrarianRequest, + LibrarianResponse, + CollectionManagementRequest, + CollectionManagementResponse, + DocumentMetadata, + ProcessingMetadata, +} from "@trustgraph/base"; import { errorMessage, makeAsyncProcessor, makeProcessorProgram, - type ProcessorConfig, - type AsyncProcessorRuntime, - type BackendConsumer, - type BackendProducer, topics, - type LibrarianRequest, - type LibrarianResponse, - type CollectionManagementRequest, - type CollectionManagementResponse, DocumentMetadata as DocumentMetadataSchema, - type DocumentMetadata, ProcessingMetadata as ProcessingMetadataSchema, - type ProcessingMetadata, Triple as TripleSchema, processorLifecycleError, } from "@trustgraph/base"; import type { Message } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { Clock, Config, DateTime, Duration, Effect, Match, Option, Random, SynchronizedRef } from "effect"; +import * as A from "effect/Array"; import * as MutableHashMap from "effect/MutableHashMap"; import * as S from "effect/Schema"; -import { makeCollectionManager, type CollectionManager } from "./collection-manager.js"; +import type { CollectionManager } from "./collection-manager.js"; +import { makeCollectionManager, } from "./collection-manager.js"; import { ensureDirectoryEffect, joinPath, @@ -127,13 +131,10 @@ const decodePersistedLibrarianState = ( ); const randomUuid: Effect.Effect = Effect.gen(function* () { - const bytes: number[] = []; - for (let index = 0; index < 16; index += 1) { - bytes.push(yield* Random.nextIntBetween(0, 255)); - } - - bytes[6] = (bytes[6]! & 0x0f) | 0x40; - bytes[8] = (bytes[8]! & 0x3f) | 0x80; + const raw = yield* Effect.forEach(A.range(0, 15), () => Random.nextIntBetween(0, 255)); + const bytes = A.map(raw, (byte, index) => + index === 6 ? (byte & 0x0f) | 0x40 : index === 8 ? (byte & 0x3f) | 0x80 : byte, + ); const hex = bytes.map((byte) => byte.toString(16).padStart(2, "0")); return [ @@ -760,25 +761,24 @@ export function makeLibrarianService(config: LibrarianServiceConfig): LibrarianS handleLibrarianOperation: function(this: LibrarianService, request: LibrarianRequest): Effect.Effect { - const service = this; return Match.value(request.operation).pipe( - Match.when("add-document", () => service.addDocument(request)), - Match.when("remove-document", () => service.removeDocument(request)), - Match.when("update-document", () => service.updateDocument(request)), - Match.when("list-documents", () => service.listDocuments(request)), + Match.when("add-document", () => this.addDocument(request)), + Match.when("remove-document", () => this.removeDocument(request)), + Match.when("update-document", () => this.updateDocument(request)), + Match.when("list-documents", () => this.listDocuments(request)), Match.when("get-document-metadata", () => getDocumentMetadataEffect(request)), - Match.when("get-document-content", () => service.getDocumentContent(request)), - Match.when("add-child-document", () => service.addChildDocument(request)), + Match.when("get-document-content", () => this.getDocumentContent(request)), + Match.when("add-child-document", () => this.addChildDocument(request)), Match.when("list-children", () => listChildrenEffect(request)), - Match.when("add-processing", () => service.addProcessing(request)), - Match.when("remove-processing", () => service.removeProcessing(request)), - Match.when("list-processing", () => service.listProcessing(request)), - Match.when("begin-upload", () => service.beginUpload(request)), + Match.when("add-processing", () => this.addProcessing(request)), + Match.when("remove-processing", () => this.removeProcessing(request)), + Match.when("list-processing", () => this.listProcessing(request)), + Match.when("begin-upload", () => this.beginUpload(request)), Match.when("upload-chunk", () => uploadChunkEffect(request)), - Match.when("complete-upload", () => service.completeUpload(request)), + Match.when("complete-upload", () => this.completeUpload(request)), Match.when("get-upload-status", () => getUploadStatusEffect(request)), Match.when("abort-upload", () => abortUploadEffect(request)), - Match.when("list-uploads", () => service.listUploads(request)), + Match.when("list-uploads", () => this.listUploads(request)), Match.when("stream-document", () => Effect.fail( librarianServiceError("stream-document", "stream-document must be handled as a streaming operation"), @@ -1427,7 +1427,7 @@ export function makeLibrarianService(config: LibrarianServiceConfig): LibrarianS // ---------- Persistence ---------- persist: Effect.gen(function* () { - const current = service!; + const current = yield* getService; const serviceState = yield* SynchronizedRef.get(current.state); const data = { documents: Object.fromEntries(serviceState.documents), @@ -1448,7 +1448,7 @@ export function makeLibrarianService(config: LibrarianServiceConfig): LibrarianS loadFromDisk: Effect.gen(function* () { - const current = service!; + const current = yield* getService; const parsed = yield* Effect.gen(function* () { const raw = yield* readTextFileEffect(current.persistPath).pipe( Effect.mapError((cause) => librarianServiceError("persist-read", cause)), diff --git a/ts/packages/flow/src/model/text-completion/azure-openai.ts b/ts/packages/flow/src/model/text-completion/azure-openai.ts index 15a6ecf0..01555740 100644 --- a/ts/packages/flow/src/model/text-completion/azure-openai.ts +++ b/ts/packages/flow/src/model/text-completion/azure-openai.ts @@ -10,16 +10,22 @@ import { AzureOpenAI } from "openai"; import { NodeRuntime } from "@effect/platform-node"; +import type { + Llm, + LlmProvider, + ProcessorConfig, + LlmResult, +} from "@trustgraph/base"; import { makeLlmService, makeFlowProcessorProgram, makeLlmSpecs, - type Llm, - type LlmProvider, - type ProcessorConfig, - type LlmResult, } from "@trustgraph/base"; import { Effect, Stream } from "effect"; +import type { + TextCompletionConfigError, + TextCompletionRuntimeError, +} from "./common.ts"; import { llmStreamPart, makeTextCompletionLayer, @@ -27,8 +33,6 @@ import { providerStatusError, requiredString, streamTextCompletionChunks, - type TextCompletionConfigError, - type TextCompletionRuntimeError, } from "./common.ts"; export type AzureOpenAIProcessorConfig = ProcessorConfig & { diff --git a/ts/packages/flow/src/model/text-completion/claude.ts b/ts/packages/flow/src/model/text-completion/claude.ts index b23eb158..3da2a461 100644 --- a/ts/packages/flow/src/model/text-completion/claude.ts +++ b/ts/packages/flow/src/model/text-completion/claude.ts @@ -6,23 +6,27 @@ import { AnthropicClient, AnthropicLanguageModel } from "@effect/ai-anthropic"; import { NodeRuntime } from "@effect/platform-node"; +import type { + Llm, + LlmProvider, + ProcessorConfig, +} from "@trustgraph/base"; import { makeLlmService, makeFlowProcessorProgram, makeLlmSpecs, - type Llm, - type LlmProvider, - type ProcessorConfig, } from "@trustgraph/base"; import { Effect, Layer, Redacted } from "effect"; import { FetchHttpClient } from "effect/unstable/http"; +import type { + TextCompletionConfigError, + TextCompletionRuntimeError, +} from "./common.ts"; import { makeLanguageModelProvider, makeTextCompletionLayer, optionalStringConfig, requiredString, - type TextCompletionConfigError, - type TextCompletionRuntimeError, } from "./common.ts"; export type ClaudeProcessorConfig = ProcessorConfig & { diff --git a/ts/packages/flow/src/model/text-completion/common.ts b/ts/packages/flow/src/model/text-completion/common.ts index 37b8cf66..1ae39541 100644 --- a/ts/packages/flow/src/model/text-completion/common.ts +++ b/ts/packages/flow/src/model/text-completion/common.ts @@ -1,18 +1,22 @@ +import type { + LlmChunk, + LlmResult, + LlmProvider, +} from "@trustgraph/base"; import { Llm, TooManyRequestsError, errorMessage, makeLlmServiceShape, - type LlmChunk, - type LlmResult, - type LlmProvider, } from "@trustgraph/base"; -import { Config, Context, Effect, Layer, Match, Ref, Result, Stream } from "effect"; +import type { Context, } from "effect"; +import { Config, Effect, Layer, Match, Ref, Result, Stream } from "effect"; import * as O from "effect/Option"; import * as Predicate from "effect/Predicate"; import * as S from "effect/Schema"; import type * as Scope from "effect/Scope"; -import { AiError, LanguageModel, Prompt, Response } from "effect/unstable/ai"; +import type { LanguageModel, Prompt, Response } from "effect/unstable/ai"; +import { AiError, } from "effect/unstable/ai"; export class TextCompletionConfigError extends S.TaggedErrorClass()( "TextCompletionConfigError", diff --git a/ts/packages/flow/src/model/text-completion/mistral.ts b/ts/packages/flow/src/model/text-completion/mistral.ts index e8d808fa..8eb3c54f 100644 --- a/ts/packages/flow/src/model/text-completion/mistral.ts +++ b/ts/packages/flow/src/model/text-completion/mistral.ts @@ -8,16 +8,22 @@ import { Mistral } from "@mistralai/mistralai"; import { NodeRuntime } from "@effect/platform-node"; +import type { + Llm, + LlmProvider, + ProcessorConfig, + LlmResult, +} from "@trustgraph/base"; import { makeLlmService, makeFlowProcessorProgram, makeLlmSpecs, - type Llm, - type LlmProvider, - type ProcessorConfig, - type LlmResult, } from "@trustgraph/base"; import { Effect, Stream } from "effect"; +import type { + TextCompletionConfigError, + TextCompletionRuntimeError, +} from "./common.ts"; import { llmStreamPart, makeTextCompletionLayer, @@ -26,8 +32,6 @@ import { requiredString, streamTextCompletionChunks, textFromContent, - type TextCompletionConfigError, - type TextCompletionRuntimeError, } from "./common.ts"; export type MistralProcessorConfig = ProcessorConfig & { diff --git a/ts/packages/flow/src/model/text-completion/ollama.ts b/ts/packages/flow/src/model/text-completion/ollama.ts index 6ecae2e7..dbbbb15a 100644 --- a/ts/packages/flow/src/model/text-completion/ollama.ts +++ b/ts/packages/flow/src/model/text-completion/ollama.ts @@ -8,24 +8,28 @@ import { Ollama } from "ollama"; import { NodeRuntime } from "@effect/platform-node"; +import type { + Llm, + LlmProvider, + ProcessorConfig, + LlmResult, +} from "@trustgraph/base"; import { makeLlmService, makeFlowProcessorProgram, makeLlmSpecs, - type Llm, - type LlmProvider, - type ProcessorConfig, - type LlmResult, } from "@trustgraph/base"; import { Effect, Stream } from "effect"; +import type { + TextCompletionConfigError, + TextCompletionRuntimeError, +} from "./common.ts"; import { llmStreamPart, makeTextCompletionLayer, optionalStringConfig, providerRuntimeError, streamTextCompletionChunks, - type TextCompletionConfigError, - type TextCompletionRuntimeError, } from "./common.ts"; export type OllamaProcessorConfig = ProcessorConfig & { @@ -68,7 +72,7 @@ const makeOllamaProviderFromClient = ( _temperature?: number, ) => { const modelName = model ?? defaultModel; - const fullPrompt = system + "\n\n" + prompt; + const fullPrompt = `${system}\n\n${prompt}`; return Effect.tryPromise({ try: () => @@ -95,7 +99,7 @@ const makeOllamaProviderFromClient = ( _temperature?: number, ) => { const modelName = model ?? defaultModel; - const fullPrompt = system + "\n\n" + prompt; + const fullPrompt = `${system}\n\n${prompt}`; return Stream.fromEffect( Effect.tryPromise({ diff --git a/ts/packages/flow/src/model/text-completion/openai-compatible.ts b/ts/packages/flow/src/model/text-completion/openai-compatible.ts index 9bc2c137..c9ea316f 100644 --- a/ts/packages/flow/src/model/text-completion/openai-compatible.ts +++ b/ts/packages/flow/src/model/text-completion/openai-compatible.ts @@ -11,16 +11,22 @@ import OpenAI from "openai"; import { NodeRuntime } from "@effect/platform-node"; +import type { + Llm, + LlmProvider, + ProcessorConfig, + LlmResult, +} from "@trustgraph/base"; import { makeLlmService, makeFlowProcessorProgram, makeLlmSpecs, - type Llm, - type LlmProvider, - type ProcessorConfig, - type LlmResult, } from "@trustgraph/base"; import { Effect, Stream } from "effect"; +import type { + TextCompletionConfigError, + TextCompletionRuntimeError, +} from "./common.ts"; import { llmStreamPart, makeTextCompletionLayer, @@ -28,8 +34,6 @@ import { providerStatusError, requiredString, streamTextCompletionChunks, - type TextCompletionConfigError, - type TextCompletionRuntimeError, } from "./common.ts"; export type OpenAICompatibleProcessorConfig = ProcessorConfig & { diff --git a/ts/packages/flow/src/model/text-completion/openai.ts b/ts/packages/flow/src/model/text-completion/openai.ts index 182fb797..2e97593c 100644 --- a/ts/packages/flow/src/model/text-completion/openai.ts +++ b/ts/packages/flow/src/model/text-completion/openai.ts @@ -6,16 +6,22 @@ import OpenAI from "openai"; import { NodeRuntime } from "@effect/platform-node"; +import type { + Llm, + LlmProvider, + ProcessorConfig, + LlmResult, +} from "@trustgraph/base"; import { makeLlmService, makeFlowProcessorProgram, makeLlmSpecs, - type Llm, - type LlmProvider, - type ProcessorConfig, - type LlmResult, } from "@trustgraph/base"; import { Effect, Stream } from "effect"; +import type { + TextCompletionConfigError, + TextCompletionRuntimeError, +} from "./common.ts"; import { llmStreamPart, makeTextCompletionLayer, @@ -23,8 +29,6 @@ import { providerStatusError, requiredString, streamTextCompletionChunks, - type TextCompletionConfigError, - type TextCompletionRuntimeError, } from "./common.ts"; export type OpenAIProcessorConfig = ProcessorConfig & { diff --git a/ts/packages/flow/src/prompt/template.ts b/ts/packages/flow/src/prompt/template.ts index ec771277..063083dd 100644 --- a/ts/packages/flow/src/prompt/template.ts +++ b/ts/packages/flow/src/prompt/template.ts @@ -24,19 +24,21 @@ * Python reference: trustgraph-flow/trustgraph/prompt/template/service.py */ +import type { + ProcessorConfig, + EffectConfigHandler, + FlowContext, + FlowProcessorRuntime, + FlowResourceNotFoundError, + MessagingDeliveryError, + PromptRequest, + PromptResponse, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeProducerSpec, - type ProcessorConfig, - type EffectConfigHandler, - type FlowContext, - type FlowProcessorRuntime, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type PromptRequest, - type PromptResponse, - type Spec, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { makeFlowProcessorProgram } from "@trustgraph/base"; diff --git a/ts/packages/flow/src/qdrant/client.ts b/ts/packages/flow/src/qdrant/client.ts index 737dd775..e418bf34 100644 --- a/ts/packages/flow/src/qdrant/client.ts +++ b/ts/packages/flow/src/qdrant/client.ts @@ -1,4 +1,5 @@ -import { QdrantClient, type QdrantClientParams } from "@qdrant/js-client-rest"; +import type { QdrantClientParams } from "@qdrant/js-client-rest"; +import { QdrantClient, } from "@qdrant/js-client-rest"; import { errorMessage } from "@trustgraph/base"; import { Effect } from "effect"; import * as S from "effect/Schema"; diff --git a/ts/packages/flow/src/query/embeddings/qdrant-doc-service.ts b/ts/packages/flow/src/query/embeddings/qdrant-doc-service.ts index 1ad19545..e0e07a22 100644 --- a/ts/packages/flow/src/query/embeddings/qdrant-doc-service.ts +++ b/ts/packages/flow/src/query/embeddings/qdrant-doc-service.ts @@ -7,30 +7,34 @@ * Python reference: trustgraph-flow/trustgraph/query/doc_embeddings/qdrant/service.py */ +import type { + ProcessorConfig, + FlowProcessorRuntime, + FlowProcessorStartEffect, + FlowContext, + FlowResourceNotFoundError, + MessagingDeliveryError, + DocumentEmbeddingsRequest, + DocumentEmbeddingsResponse, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeProducerSpec, processorLifecycleError, - type ProcessorConfig, - type FlowProcessorRuntime, - type FlowProcessorStartEffect, - type FlowContext, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type DocumentEmbeddingsRequest, - type DocumentEmbeddingsResponse, - type Spec, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { makeFlowProcessorProgram } from "@trustgraph/base"; import { Effect } from "effect"; +import type { + QdrantDocQueryConfig, + QdrantDocEmbeddingsQueryError, +} from "./qdrant-doc.js"; import { QdrantDocEmbeddingsQueryLive, QdrantDocEmbeddingsQueryService, makeQdrantDocEmbeddingsQueryServiceEffect, - type QdrantDocQueryConfig, - type QdrantDocEmbeddingsQueryError, } from "./qdrant-doc.js"; const DocumentEmbeddingsResponseProducer = makeProducerSpec("document-embeddings-response"); diff --git a/ts/packages/flow/src/query/embeddings/qdrant-doc.ts b/ts/packages/flow/src/query/embeddings/qdrant-doc.ts index 84640e8b..b988fbb4 100644 --- a/ts/packages/flow/src/query/embeddings/qdrant-doc.ts +++ b/ts/packages/flow/src/query/embeddings/qdrant-doc.ts @@ -11,7 +11,8 @@ import { errorMessage } from "@trustgraph/base"; import { Config, Context, Effect, Layer } from "effect"; import * as O from "effect/Option"; import * as S from "effect/Schema"; -import { makeQdrantClient, type QdrantClientFactory, type QdrantClientLike } from "../../qdrant/client.js"; +import type { QdrantClientFactory, QdrantClientLike } from "../../qdrant/client.js"; +import { makeQdrantClient, } from "../../qdrant/client.js"; export interface QdrantDocQueryConfig { url?: string; diff --git a/ts/packages/flow/src/query/embeddings/qdrant-graph-service.ts b/ts/packages/flow/src/query/embeddings/qdrant-graph-service.ts index ad479145..b16c5aef 100644 --- a/ts/packages/flow/src/query/embeddings/qdrant-graph-service.ts +++ b/ts/packages/flow/src/query/embeddings/qdrant-graph-service.ts @@ -7,30 +7,34 @@ * Python reference: trustgraph-flow/trustgraph/query/graph_embeddings/qdrant/service.py */ +import type { + ProcessorConfig, + FlowProcessorRuntime, + FlowProcessorStartEffect, + FlowContext, + FlowResourceNotFoundError, + MessagingDeliveryError, + GraphEmbeddingsRequest, + GraphEmbeddingsResponse, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeProducerSpec, processorLifecycleError, - type ProcessorConfig, - type FlowProcessorRuntime, - type FlowProcessorStartEffect, - type FlowContext, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type GraphEmbeddingsRequest, - type GraphEmbeddingsResponse, - type Spec, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { makeFlowProcessorProgram } from "@trustgraph/base"; import { Effect } from "effect"; +import type { + QdrantGraphQueryConfig, + QdrantGraphEmbeddingsQueryError, +} from "./qdrant-graph.js"; import { QdrantGraphEmbeddingsQueryLive, QdrantGraphEmbeddingsQueryService, makeQdrantGraphEmbeddingsQueryServiceEffect, - type QdrantGraphQueryConfig, - type QdrantGraphEmbeddingsQueryError, } from "./qdrant-graph.js"; const GraphEmbeddingsResponseProducer = makeProducerSpec("graph-embeddings-response"); diff --git a/ts/packages/flow/src/query/embeddings/qdrant-graph.ts b/ts/packages/flow/src/query/embeddings/qdrant-graph.ts index 811f923f..1e70691c 100644 --- a/ts/packages/flow/src/query/embeddings/qdrant-graph.ts +++ b/ts/packages/flow/src/query/embeddings/qdrant-graph.ts @@ -10,11 +10,13 @@ * Python reference: trustgraph-flow/trustgraph/query/graph_embeddings/qdrant/service.py */ -import { errorMessage, type Term } from "@trustgraph/base"; +import type { Term } from "@trustgraph/base"; +import { errorMessage, } from "@trustgraph/base"; import { Config, Context, Effect, Layer } from "effect"; import * as O from "effect/Option"; import * as S from "effect/Schema"; -import { makeQdrantClient, type QdrantClientFactory, type QdrantClientLike } from "../../qdrant/client.js"; +import type { QdrantClientFactory, QdrantClientLike } from "../../qdrant/client.js"; +import { makeQdrantClient, } from "../../qdrant/client.js"; export interface QdrantGraphQueryConfig { url?: string; diff --git a/ts/packages/flow/src/query/triples/falkordb-service.ts b/ts/packages/flow/src/query/triples/falkordb-service.ts index 3296e467..4007abea 100644 --- a/ts/packages/flow/src/query/triples/falkordb-service.ts +++ b/ts/packages/flow/src/query/triples/falkordb-service.ts @@ -7,30 +7,34 @@ * Python reference: trustgraph-flow/trustgraph/query/triples/falkordb/service.py */ +import type { + ProcessorConfig, + FlowProcessorRuntime, + FlowProcessorStartEffect, + FlowContext, + FlowResourceNotFoundError, + MessagingDeliveryError, + TriplesQueryRequest, + TriplesQueryResponse, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeProducerSpec, processorLifecycleError, - type ProcessorConfig, - type FlowProcessorRuntime, - type FlowProcessorStartEffect, - type FlowContext, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type TriplesQueryRequest, - type TriplesQueryResponse, - type Spec, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { makeFlowProcessorProgram } from "@trustgraph/base"; import { Effect } from "effect"; +import type { + FalkorDBQueryConfig, + FalkorDBTriplesQueryError, +} from "./falkordb.js"; import { FalkorDBTriplesQueryLive, FalkorDBTriplesQueryService, makeFalkorDBTriplesQueryServiceScoped, - type FalkorDBQueryConfig, - type FalkorDBTriplesQueryError, } from "./falkordb.js"; const TriplesResponseProducer = makeProducerSpec("triples-response"); diff --git a/ts/packages/flow/src/query/triples/falkordb.ts b/ts/packages/flow/src/query/triples/falkordb.ts index 90b5804c..c9c9df6d 100644 --- a/ts/packages/flow/src/query/triples/falkordb.ts +++ b/ts/packages/flow/src/query/triples/falkordb.ts @@ -7,7 +7,8 @@ */ import { createClient, Graph } from "falkordb"; -import { errorMessage, type Term, type Triple } from "@trustgraph/base"; +import type { Term, Triple } from "@trustgraph/base"; +import { errorMessage, } from "@trustgraph/base"; import { Config, Context, Effect, Layer, Match } from "effect"; import * as Predicate from "effect/Predicate"; import * as S from "effect/Schema"; diff --git a/ts/packages/flow/src/retrieval/document-rag-service.ts b/ts/packages/flow/src/retrieval/document-rag-service.ts index 87d7d26f..6273baae 100644 --- a/ts/packages/flow/src/retrieval/document-rag-service.ts +++ b/ts/packages/flow/src/retrieval/document-rag-service.ts @@ -8,36 +8,40 @@ */ import {NodeRuntime} from "@effect/platform-node"; +import type { + DocumentEmbeddingsRequest, + DocumentEmbeddingsResponse, + DocumentRagRequest, + DocumentRagResponse, + EmbeddingsRequest, + EmbeddingsResponse, + FlowContext, + FlowProcessorRuntime, + FlowResourceNotFoundError, + MessagingDeliveryError, + ProcessorConfig, + PromptRequest, + PromptResponse, + Spec, + TextCompletionRequest, + TextCompletionResponse, +} from "@trustgraph/base"; import { makeConsumerSpec, makeFlowProcessor, makeProducerSpec, makeRequestResponseSpec, makeFlowProcessorProgram, - type DocumentEmbeddingsRequest, - type DocumentEmbeddingsResponse, - type DocumentRagRequest, - type DocumentRagResponse, - type EmbeddingsRequest, - type EmbeddingsResponse, - type FlowContext, - type FlowProcessorRuntime, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type ProcessorConfig, - type PromptRequest, - type PromptResponse, - type Spec, - type TextCompletionRequest, - type TextCompletionResponse, } from "@trustgraph/base"; import {Effect} from "effect"; +import type { + DocumentRagEngineError, + DocumentRagClients, +} from "./document-rag.js"; import { DocumentRagEngine, - DocumentRagEngineError, DocumentRagLive, makeDocumentRagEngine, - type DocumentRagClients, } from "./document-rag.js"; const DocumentRagResponseProducer = makeProducerSpec("document-rag-response"); diff --git a/ts/packages/flow/src/retrieval/graph-rag-service.ts b/ts/packages/flow/src/retrieval/graph-rag-service.ts index 81912fbd..e0e7230e 100644 --- a/ts/packages/flow/src/retrieval/graph-rag-service.ts +++ b/ts/packages/flow/src/retrieval/graph-rag-service.ts @@ -8,39 +8,43 @@ */ import {NodeRuntime} from "@effect/platform-node"; +import type { + FlowContext, + FlowProcessorRuntime, + FlowResourceNotFoundError, + GraphEmbeddingsRequest, + GraphEmbeddingsResponse, + GraphRagRequest, + GraphRagResponse, + EmbeddingsRequest, + EmbeddingsResponse, + MessagingDeliveryError, + ProcessorConfig, + PromptRequest, + PromptResponse, + Spec, + TextCompletionRequest, + TextCompletionResponse, + TriplesQueryRequest, + TriplesQueryResponse, +} from "@trustgraph/base"; import { makeConsumerSpec, makeFlowProcessor, makeProducerSpec, makeRequestResponseSpec, makeFlowProcessorProgram, - type FlowContext, - type FlowProcessorRuntime, - type FlowResourceNotFoundError, - type GraphEmbeddingsRequest, - type GraphEmbeddingsResponse, - type GraphRagRequest, - type GraphRagResponse, - type EmbeddingsRequest, - type EmbeddingsResponse, - type MessagingDeliveryError, - type ProcessorConfig, - type PromptRequest, - type PromptResponse, - type Spec, - type TextCompletionRequest, - type TextCompletionResponse, - type TriplesQueryRequest, - type TriplesQueryResponse, } from "@trustgraph/base"; import {Effect} from "effect"; +import type { + GraphRagEngineError, + GraphRagClients, + GraphRagConfig, +} from "./graph-rag.js"; import { GraphRagEngine, - GraphRagEngineError, GraphRagLive, makeGraphRagEngine, - type GraphRagClients, - type GraphRagConfig, } from "./graph-rag.js"; const GraphRagResponseProducer = makeProducerSpec("graph-rag-response"); diff --git a/ts/packages/flow/src/storage/embeddings/graph-embeddings-service.ts b/ts/packages/flow/src/storage/embeddings/graph-embeddings-service.ts index a6143f41..c1f0645d 100644 --- a/ts/packages/flow/src/storage/embeddings/graph-embeddings-service.ts +++ b/ts/packages/flow/src/storage/embeddings/graph-embeddings-service.ts @@ -9,33 +9,37 @@ * Python reference: trustgraph-flow/trustgraph/storage/graph_embeddings/qdrant/service.py */ +import type { + ProcessorConfig, + FlowProcessorRuntime, + FlowProcessorStartEffect, + FlowContext, + FlowResourceNotFoundError, + MessagingDeliveryError, + MessagingLifecycleError, + MessagingTimeoutError, + EntityContexts, + EmbeddingsRequest, + EmbeddingsResponse, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, makeRequestResponseSpec, processorLifecycleError, - type ProcessorConfig, - type FlowProcessorRuntime, - type FlowProcessorStartEffect, - type FlowContext, - type FlowResourceNotFoundError, - type MessagingDeliveryError, - type MessagingLifecycleError, - type MessagingTimeoutError, - type EntityContexts, - type EmbeddingsRequest, - type EmbeddingsResponse, - type Spec, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { makeFlowProcessorProgram } from "@trustgraph/base"; import { Effect } from "effect"; +import type { + QdrantGraphEmbeddingsConfig, + QdrantGraphEmbeddingsStoreError, +} from "./qdrant-graph.js"; import { QdrantGraphEmbeddingsStoreLive, QdrantGraphEmbeddingsStoreService, makeQdrantGraphEmbeddingsStoreServiceEffect, - type QdrantGraphEmbeddingsConfig, - type QdrantGraphEmbeddingsStoreError, } from "./qdrant-graph.js"; type GraphEmbeddingsStoreRequirements = QdrantGraphEmbeddingsStoreService; diff --git a/ts/packages/flow/src/storage/embeddings/qdrant-doc.ts b/ts/packages/flow/src/storage/embeddings/qdrant-doc.ts index 40c257c4..637f72d1 100644 --- a/ts/packages/flow/src/storage/embeddings/qdrant-doc.ts +++ b/ts/packages/flow/src/storage/embeddings/qdrant-doc.ts @@ -13,7 +13,8 @@ import { Config, Effect, Random } from "effect"; import * as MutableHashSet from "effect/MutableHashSet"; import * as O from "effect/Option"; import * as S from "effect/Schema"; -import { makeQdrantClient, type QdrantClientFactory, type QdrantClientLike } from "../../qdrant/client.js"; +import type { QdrantClientFactory, QdrantClientLike } from "../../qdrant/client.js"; +import { makeQdrantClient, } from "../../qdrant/client.js"; export interface QdrantDocEmbeddingsConfig { url?: string; diff --git a/ts/packages/flow/src/storage/embeddings/qdrant-graph.ts b/ts/packages/flow/src/storage/embeddings/qdrant-graph.ts index af0c4dac..23e2ca9a 100644 --- a/ts/packages/flow/src/storage/embeddings/qdrant-graph.ts +++ b/ts/packages/flow/src/storage/embeddings/qdrant-graph.ts @@ -8,12 +8,14 @@ * Python reference: trustgraph-flow/trustgraph/storage/graph_embeddings/qdrant/write.py */ -import { errorMessage, type Term } from "@trustgraph/base"; +import type { Term } from "@trustgraph/base"; +import { errorMessage, } from "@trustgraph/base"; import { Config, Context, Effect, Layer, Match, Random } from "effect"; import * as MutableHashSet from "effect/MutableHashSet"; import * as O from "effect/Option"; import * as S from "effect/Schema"; -import { makeQdrantClient, type QdrantClientFactory, type QdrantClientLike } from "../../qdrant/client.js"; +import type { QdrantClientFactory, QdrantClientLike } from "../../qdrant/client.js"; +import { makeQdrantClient, } from "../../qdrant/client.js"; export interface QdrantGraphEmbeddingsConfig { url?: string; diff --git a/ts/packages/flow/src/storage/triples/falkordb-service.ts b/ts/packages/flow/src/storage/triples/falkordb-service.ts index cd783941..296896db 100644 --- a/ts/packages/flow/src/storage/triples/falkordb-service.ts +++ b/ts/packages/flow/src/storage/triples/falkordb-service.ts @@ -8,26 +8,30 @@ * Python reference: trustgraph-flow/trustgraph/storage/triples/falkordb/service.py */ +import type { + ProcessorConfig, + FlowProcessorRuntime, + FlowProcessorStartEffect, + FlowContext, + Triples, + Spec, +} from "@trustgraph/base"; import { makeFlowProcessor, makeConsumerSpec, processorLifecycleError, - type ProcessorConfig, - type FlowProcessorRuntime, - type FlowProcessorStartEffect, - type FlowContext, - type Triples, - type Spec, } from "@trustgraph/base"; import { NodeRuntime } from "@effect/platform-node"; import { makeFlowProcessorProgram } from "@trustgraph/base"; import { Effect } from "effect"; +import type { + FalkorDBConfig, + FalkorDBTriplesStoreError, +} from "./falkordb.js"; import { FalkorDBTriplesStoreLive, FalkorDBTriplesStoreService, makeFalkorDBTriplesStoreServiceScoped, - type FalkorDBConfig, - type FalkorDBTriplesStoreError, } from "./falkordb.js"; const onStoreTriplesMessage = Effect.fn("TriplesStoreService.onMessage")(function* ( diff --git a/ts/packages/flow/src/storage/triples/falkordb.ts b/ts/packages/flow/src/storage/triples/falkordb.ts index 138f995c..1e3f98cd 100644 --- a/ts/packages/flow/src/storage/triples/falkordb.ts +++ b/ts/packages/flow/src/storage/triples/falkordb.ts @@ -8,7 +8,8 @@ */ import { createClient, Graph } from "falkordb"; -import { errorMessage, type Term, type Triple } from "@trustgraph/base"; +import type { Term, Triple } from "@trustgraph/base"; +import { errorMessage, } from "@trustgraph/base"; import { Config, Context, Effect, Layer, Match } from "effect"; import * as S from "effect/Schema"; diff --git a/ts/packages/mcp/package.json b/ts/packages/mcp/package.json index 182ff059..5a5dad7b 100644 --- a/ts/packages/mcp/package.json +++ b/ts/packages/mcp/package.json @@ -8,7 +8,8 @@ "build": "bunx --bun tsc", "dev": "tsc --watch", "clean": "rm -rf dist", - "test": "bunx --bun vitest run --passWithNoTests --exclude=dist/**" + "test": "bunx --bun vitest run --passWithNoTests --exclude=dist/**", + "lint": "bunx --bun biome check src" }, "dependencies": { "@trustgraph/base": "workspace:*", diff --git a/ts/packages/mcp/src/__tests__/server-effect.test.ts b/ts/packages/mcp/src/__tests__/server-effect.test.ts index ce6da511..b2093009 100644 --- a/ts/packages/mcp/src/__tests__/server-effect.test.ts +++ b/ts/packages/mcp/src/__tests__/server-effect.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "@effect/vitest"; -import { DispatchStreamChunk, type BaseApi, type TrustGraphGatewayClient } from "@trustgraph/client"; +import type { BaseApi, TrustGraphGatewayClient } from "@trustgraph/client"; +import { DispatchStreamChunk, } from "@trustgraph/client"; import { Effect, Layer, Stream } from "effect"; import * as S from "effect/Schema"; import { McpServer } from "effect/unstable/ai"; @@ -226,7 +227,7 @@ const makeNativeTestClientEffect = Effect.fn("makeNativeTestClient")(function*( const textContent = (result: McpSchema.CallToolResult): string => { const [content] = result.content; expect(content?.type).toBe("text"); - return "text" in content! ? content.text : ""; + return content !== undefined && "text" in content ? content.text : ""; }; describe("Effect MCP server", () => { diff --git a/ts/packages/mcp/src/server-effect.ts b/ts/packages/mcp/src/server-effect.ts index 360eb9c3..a45eb53d 100644 --- a/ts/packages/mcp/src/server-effect.ts +++ b/ts/packages/mcp/src/server-effect.ts @@ -1,11 +1,13 @@ import {BunHttpServer, BunRuntime} from "@effect/platform-bun"; import {NodeRuntime, NodeStdio} from "@effect/platform-node"; +import type { + BaseApi, + Term as ClientTerm, + TrustGraphGatewayClient, +} from "@trustgraph/client"; import { createTrustGraphSocket, makeTrustGraphGatewayClientScoped, - type BaseApi, - type Term as ClientTerm, - type TrustGraphGatewayClient, } from "@trustgraph/client"; import {Config, Context, Effect, Layer} from "effect"; import * as O from "effect/Option"; diff --git a/ts/packages/workbench/package.json b/ts/packages/workbench/package.json index 9c55696a..93ef6f2f 100644 --- a/ts/packages/workbench/package.json +++ b/ts/packages/workbench/package.json @@ -7,7 +7,8 @@ "dev": "vite", "build": "tsc && vite build", "preview": "vite preview", - "qa:browser": "playwright test" + "qa:browser": "playwright test", + "lint": "bunx --bun biome check src" }, "dependencies": { "@effect/atom-react": "4.0.0-beta.78", diff --git a/ts/packages/workbench/src/atoms/workbench.ts b/ts/packages/workbench/src/atoms/workbench.ts index a5fecec4..fb40752c 100644 --- a/ts/packages/workbench/src/atoms/workbench.ts +++ b/ts/packages/workbench/src/atoms/workbench.ts @@ -1,25 +1,29 @@ import { Clipboard as BrowserClipboard } from "@effect/platform-browser"; import * as BrowserHttpClient from "@effect/platform-browser/BrowserHttpClient"; import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore"; +import type { + GraphRagOptions, + BaseApi, + BeginUploadResponse, + ChunkedUploadDocumentMetadata, + CompleteUploadResponse, + ConnectionState, + DocumentMetadata, + ExplainEvent, + StreamingMetadata, + Term, + Triple, + UploadChunkResponse, +} from "@trustgraph/client"; import { DispatchPayload, GatewayWorkbenchHttpApi, - type GraphRagOptions, makeBaseApi, TrustGraphRpcs, - type BaseApi, - type BeginUploadResponse, - type ChunkedUploadDocumentMetadata, - type CompleteUploadResponse, - type ConnectionState, - type DocumentMetadata, - type ExplainEvent, - type StreamingMetadata, - type Term, - type Triple, - type UploadChunkResponse, } from "@trustgraph/client"; -import { Cause, Clock, Context, Effect, Layer, Match, Metric, Option, Random, Schema as S, Scope, Stream } from "effect"; +import type { Scope, } from "effect"; +import { Cause, Clock, Context, Effect, Layer, Match, Metric, Option, Random, Schema as S, Stream } from "effect"; +import * as A from "effect/Array"; import * as MutableHashMap from "effect/MutableHashMap"; import * as Predicate from "effect/Predicate"; import { HttpClient, HttpClientRequest } from "effect/unstable/http"; @@ -28,7 +32,7 @@ import * as RpcClient from "effect/unstable/rpc/RpcClient"; import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization"; import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"; import * as Atom from "effect/unstable/reactivity/Atom"; -import * as AtomRegistry from "effect/unstable/reactivity/AtomRegistry"; +import type * as AtomRegistry from "effect/unstable/reactivity/AtomRegistry"; import * as AtomHttpApi from "effect/unstable/reactivity/AtomHttpApi"; import * as AtomRpc from "effect/unstable/reactivity/AtomRpc"; import * as Reactivity from "effect/unstable/reactivity/Reactivity"; @@ -1490,14 +1494,15 @@ function updateConversation(get: Atom.FnContext, f: (current: ConversationState) } function updateLastMessage(get: Atom.FnContext, updater: (prev: ChatMessage) => ChatMessage): void { - updateConversation(get, (current) => { - if (current.messages.length === 0) return current; - const last = current.messages[current.messages.length - 1]!; - return { - ...current, - messages: [...current.messages.slice(0, -1), updater(last)], - }; - }); + updateConversation(get, (current) => + A.matchRight(current.messages, { + onEmpty: () => current, + onNonEmpty: (init, last) => ({ + ...current, + messages: [...init, updater(last)], + }), + }), + ); } function refreshConfigAtoms(get: Atom.FnContext): void { diff --git a/ts/packages/workbench/src/components/chat/explain-graph.tsx b/ts/packages/workbench/src/components/chat/explain-graph.tsx index 9c8c84a9..5a578070 100644 --- a/ts/packages/workbench/src/components/chat/explain-graph.tsx +++ b/ts/packages/workbench/src/components/chat/explain-graph.tsx @@ -9,11 +9,13 @@ import { resultError, resultLoading, } from "@/atoms/workbench"; +import type { + GraphNode, + GraphLink, +} from "@/lib/graph-utils"; import { triplesToGraph, localName, - type GraphNode, - type GraphLink, directedGraphLinkProps, DEFAULT_GRAPH_NODE_COLOR, } from "@/lib/graph-utils"; diff --git a/ts/packages/workbench/src/components/error-boundary.tsx b/ts/packages/workbench/src/components/error-boundary.tsx index 36e5d93f..056d9b74 100644 --- a/ts/packages/workbench/src/components/error-boundary.tsx +++ b/ts/packages/workbench/src/components/error-boundary.tsx @@ -1,7 +1,9 @@ import type { ReactNode } from "react"; +import type { + FallbackProps, +} from "react-error-boundary"; import { ErrorBoundary as ReactErrorBoundary, - type FallbackProps, } from "react-error-boundary"; import { AlertTriangle, RefreshCw } from "lucide-react"; import { Effect } from "effect"; diff --git a/ts/packages/workbench/src/components/notification-toasts.tsx b/ts/packages/workbench/src/components/notification-toasts.tsx index e2c0f29c..2422b4fd 100644 --- a/ts/packages/workbench/src/components/notification-toasts.tsx +++ b/ts/packages/workbench/src/components/notification-toasts.tsx @@ -1,7 +1,8 @@ import { useAtomSet, useAtomValue } from "@effect/atom-react"; import { X } from "lucide-react"; import { cn } from "@/lib/utils"; -import { notificationsAtom, removeNotificationAtom, type Notification } from "@/atoms/workbench"; +import type { Notification } from "@/atoms/workbench"; +import { notificationsAtom, removeNotificationAtom, } from "@/atoms/workbench"; const typeStyles: Record = { success: "border-success/40 bg-success/10 text-success", diff --git a/ts/packages/workbench/src/index.css b/ts/packages/workbench/src/index.css index 050c18bf..3ca1d6ae 100644 --- a/ts/packages/workbench/src/index.css +++ b/ts/packages/workbench/src/index.css @@ -134,8 +134,8 @@ .animate-\[glow-drift-2_15s_ease-in-out_infinite\], .animate-\[glow-drift-3_25s_ease-in-out_infinite\], .animate-\[glow-fade-in_1\.2s_ease-out_forwards\] { - animation: none !important; - opacity: 0.7 !important; + animation: none; + opacity: 0.7; } } diff --git a/ts/packages/workbench/src/lib/graph-utils.ts b/ts/packages/workbench/src/lib/graph-utils.ts index a2bdd9ea..c5494ad9 100644 --- a/ts/packages/workbench/src/lib/graph-utils.ts +++ b/ts/packages/workbench/src/lib/graph-utils.ts @@ -123,16 +123,18 @@ export function triplesToGraph(triples: Triple[]): { const nodeMap = new Map(); const links: GraphLink[] = []; - const ensureNode = (uri: string): void => { - if (!nodeMap.has(uri)) { - const type = typeMap.get(uri); - nodeMap.set(uri, { - id: uri, - label: labelMap.get(uri) ?? localName(uri), - color: hashColor(type !== undefined ? localName(type) : uri), - degree: 0, - }); - } + const ensureNode = (uri: string): GraphNode => { + const existing = nodeMap.get(uri); + if (existing !== undefined) return existing; + const type = typeMap.get(uri); + const node: GraphNode = { + id: uri, + label: labelMap.get(uri) ?? localName(uri), + color: hashColor(type !== undefined ? localName(type) : uri), + degree: 0, + }; + nodeMap.set(uri, node); + return node; }; for (const t of triples) { @@ -151,10 +153,8 @@ export function triplesToGraph(triples: Triple[]): { const oIsEntity = isIri(t.o) || t.o.t === "l"; if (!sIsEntity || !oIsEntity) continue; - ensureNode(sVal); - ensureNode(oVal); - nodeMap.get(sVal)!.degree++; - nodeMap.get(oVal)!.degree++; + ensureNode(sVal).degree++; + ensureNode(oVal).degree++; links.push({ source: sVal, diff --git a/ts/packages/workbench/src/lib/utils.ts b/ts/packages/workbench/src/lib/utils.ts index 365058ce..d46b6bfb 100644 --- a/ts/packages/workbench/src/lib/utils.ts +++ b/ts/packages/workbench/src/lib/utils.ts @@ -1,4 +1,5 @@ -import { type ClassValue, clsx } from "clsx"; +import type { ClassValue, } from "clsx"; +import { clsx } from "clsx"; import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { diff --git a/ts/packages/workbench/src/main.tsx b/ts/packages/workbench/src/main.tsx index f188d4d7..5d381e22 100644 --- a/ts/packages/workbench/src/main.tsx +++ b/ts/packages/workbench/src/main.tsx @@ -13,7 +13,13 @@ function AppRoot() { return ; } -ReactDOM.createRoot(document.getElementById("root")!).render( +const rootElement = document.getElementById("root"); +if (rootElement === null) { + // Host boundary: the workbench cannot render without its mount point. + throw new Error("Workbench root element #root not found"); +} + +ReactDOM.createRoot(rootElement).render( diff --git a/ts/packages/workbench/src/pages/chat.tsx b/ts/packages/workbench/src/pages/chat.tsx index 2b949825..401dbf17 100644 --- a/ts/packages/workbench/src/pages/chat.tsx +++ b/ts/packages/workbench/src/pages/chat.tsx @@ -15,6 +15,9 @@ import { } from "lucide-react"; import Markdown from "react-markdown"; import { cn } from "@/lib/utils"; +import type { + ChatMessage, +} from "@/atoms/workbench"; import { agentPhaseExpandedAtom, cancelChatAtom, @@ -27,7 +30,6 @@ import { setConversationInputAtom, settingsAtom, submitMessageAtom, - type ChatMessage, } from "@/atoms/workbench"; import { AutoTextarea } from "@/components/ui/textarea"; import { MessageActions } from "@/components/chat/message-actions"; diff --git a/ts/packages/workbench/src/pages/graph.tsx b/ts/packages/workbench/src/pages/graph.tsx index e587bbdb..80c6f7cf 100644 --- a/ts/packages/workbench/src/pages/graph.tsx +++ b/ts/packages/workbench/src/pages/graph.tsx @@ -19,14 +19,16 @@ import { settingsAtom, } from "@/atoms/workbench"; import type { Triple } from "@trustgraph/client"; +import type { + GraphNode, + GraphLink, +} from "@/lib/graph-utils"; import { localName, triplesToGraph, RDFS_LABEL, RDF_TYPE, termValue, - type GraphNode, - type GraphLink, directedGraphLinkProps, DEFAULT_GRAPH_NODE_COLOR, } from "@/lib/graph-utils"; diff --git a/ts/packages/workbench/src/pages/library.tsx b/ts/packages/workbench/src/pages/library.tsx index eaa0b69d..cf330ee5 100644 --- a/ts/packages/workbench/src/pages/library.tsx +++ b/ts/packages/workbench/src/pages/library.tsx @@ -16,6 +16,9 @@ import { Hash, } from "lucide-react"; import { cn } from "@/lib/utils"; +import type { + UploadForm, +} from "@/atoms/workbench"; import { documentMetadataAtom, encodeJsonUnknownString, @@ -31,7 +34,6 @@ import { submitUploadDocumentAtom, uploadDialogOpenAtom, uploadFormAtom, - type UploadForm, } from "@/atoms/workbench"; import { Dialog } from "@/components/ui/dialog"; import { Badge } from "@/components/ui/badge"; diff --git a/ts/packages/workbench/src/pages/mcp-tools.tsx b/ts/packages/workbench/src/pages/mcp-tools.tsx index 3fe5845b..a1f24055 100644 --- a/ts/packages/workbench/src/pages/mcp-tools.tsx +++ b/ts/packages/workbench/src/pages/mcp-tools.tsx @@ -15,6 +15,10 @@ import { } from "lucide-react"; import { cn } from "@/lib/utils"; import { Dialog } from "@/components/ui/dialog"; +import type { + McpServerEntry, + ToolEntry, +} from "@/atoms/workbench"; import { deleteMcpServerAtom, deleteMcpToolAtom, @@ -31,8 +35,6 @@ import { resultLoading, saveMcpServerAtom, saveMcpToolAtom, - type McpServerEntry, - type ToolEntry, } from "@/atoms/workbench"; const INPUT_CLASS = diff --git a/ts/packages/workbench/src/pages/prompts.tsx b/ts/packages/workbench/src/pages/prompts.tsx index db5cdd30..c869b636 100644 --- a/ts/packages/workbench/src/pages/prompts.tsx +++ b/ts/packages/workbench/src/pages/prompts.tsx @@ -95,7 +95,7 @@ export default function PromptsPage() { )} {activeTab === "templates" && ( -
+
{loading && prompts.length === 0 && (
@@ -203,7 +203,7 @@ export default function PromptsPage() { )} {activeTab === "system" && ( -
+

System Prompt diff --git a/ts/packages/workbench/src/qa/initial-values.ts b/ts/packages/workbench/src/qa/initial-values.ts index 4a32da8b..ce99b489 100644 --- a/ts/packages/workbench/src/qa/initial-values.ts +++ b/ts/packages/workbench/src/qa/initial-values.ts @@ -1,15 +1,18 @@ import type * as Atom from "effect/unstable/reactivity/Atom"; +import type { + FeatureSwitches, + Settings, + WorkbenchApiFactory, +} from "@/atoms/workbench"; import { apiFactoryAtom, DEFAULT_SETTINGS, flowIdAtom, settingsAtom, - type FeatureSwitches, - type Settings, - type WorkbenchApiFactory, } from "@/atoms/workbench"; import type { BaseApi } from "@trustgraph/client"; -import { makeMockBaseApi, qaSettingsFromFixture, type MockWorkbenchFixture } from "@/qa/mock-api"; +import type { MockWorkbenchFixture } from "@/qa/mock-api"; +import { makeMockBaseApi, qaSettingsFromFixture, } from "@/qa/mock-api"; export interface WorkbenchQaWindowConfig { readonly enabled?: boolean; diff --git a/ts/packages/workbench/src/qa/mock-api.ts b/ts/packages/workbench/src/qa/mock-api.ts index d27f52c9..05c8a299 100644 --- a/ts/packages/workbench/src/qa/mock-api.ts +++ b/ts/packages/workbench/src/qa/mock-api.ts @@ -1,4 +1,5 @@ -import { makeBaseApiWithRpc, type BaseApi, type DocumentMetadata, type ProcessingMetadata, type StreamingMetadata, type Triple } from "@trustgraph/client"; +import type { BaseApi, DocumentMetadata, ProcessingMetadata, StreamingMetadata, Triple } from "@trustgraph/client"; +import { makeBaseApiWithRpc, } from "@trustgraph/client"; import { Clock, Effect, Match, Option, Schema as S } from "effect"; type ConfigValues = Record>; diff --git a/ts/scripts/check-effect-laws.ts b/ts/scripts/check-effect-laws.ts new file mode 100644 index 0000000000000000000000000000000000000000..16b84259afecfe5f4d5b231eb8cbee3790424c36 GIT binary patch literal 11793 zcmbtaUvt~I5%04<1x}Z_p%RHodM~XKJLhxkCU;JpiJabp<%ww#l6a;_4MEw~*qZ5w z=qKza>2G%dkd$Pfug!xa62R_a_qYE5_MSiAQP0)kc&tZdH;c;TTB|g=Q92vv#YoR| zRx12bTrS{G^_jjp1JHofP=o+(B&O_@=V%uCbj zsGFpmsz?=43BqNPP1I#%bed$kPsB7REY)?Ar`TPdsTno_;navolblP?Q~EZ70!H}) z`*q8qgc3`!`-lh?Ix=~N6?0w8qKq`7Z}n`>RFlk0WH(DY3!^m6Z_>n+;qO=*ssmzR zh*~*~N);FRoYXtg*nnrdn8#76RbY3d;`}CSzlOlHRu)c*{6>wVBy|?}YM>zAuTqzb zN*JhQbY;!ZWsyK)Xm|?V!S9x(kBq?c5jNL)Lp-Y@7bW4#ujw7 zF$0jn1R&bm*-2)EAkc^Pe_muqNva1+Q|g%-7x_%JeiA+Q=CB)7H0xqpy~f1W>vbYu zprK@@|A2y>RV}}>4xmS9|7xdJ$+m1EH-Koo<@_2 zjt`3>FAiwto94{DpdIWe)oQ+Nb@1*^&9q^60hs}BUadMiZFRT8E}84kHh>&*0H~M> zr^e`B&}uxl+QA)|6pK{%J$+(3kIHHD4LdZw`m~r`>Y}r=s>^WbW6L^!KLXzV_n+V^ zfvhe|gYmwLSv76T#{CEw``?za4~2#ZvvUMqxHc)k1&3<9p*YNOVhGZl7{4HL0%(Jf zP)QGBv%pKxcKC`lr6K>G7s#lum0>8pCh)k|$f=y>5Hz=r z8)De6csCXUaNvrC;CXmEf4u{ESAzW0C&Y#zg4->k2z<8;aH3TiL%6|T-;Q)KFDt>x zz1Xyz>`4j0$``v=M$8+po;|4X45}dE6sxC|<+ecSQZ8jzR;r<))>osI1U>c3;N%lh zCd_YCu#O$o1Dvc?j~b|IcT|>_%2q-|#4@s~W{VP<*`YFfnF+vRL>g;;!K1eALJ{u>K1yU%LE#0xLNnD_(%QjU?7Cua2fsmg!W4WMY|9F-Pzx z=y-U^>xSkU5$#AyQ6dF6A#VBeC^96dlCm{DHa7iXvUg&%J2{=$c z&ao7c4jmGhJc0)9+q=~I6lSZKA7PwSac{(tLp&ukDVl6bh7dTWqNJzZ*@PpIFuFVi z)qH`rU6&uIjJb}|Cu|6jPM3jQd+!$3QsTL9DFz4c4?pgIJNobiUB#EL$A?rwS(oG! zgD%?Ph+6`#9z>~xYG9Z$Fy{A$VQFsPKI?g^i8;I-rHfd{?~(#D0;4B%n&HZkb|2vf zy&3}N?j91f9ag)$;2xu6NBwr+d`k%bHp@v-W^*(|th&rM-+%i?vCe$^R_!1$r+7s> zAi>CA9+Ha2!X)F3n4s13#CokZ<&R*%_lF<2nW@W#QyG#7Bi~h<+u%RoV)h9V2>m*L*JZY<{fzQ7g_j69 zQl`PKEU?E};9I|Nb0T_{@gn2Hi06v>#4#$-Do%#gPwopbK_WBo!`W(AEfbx_&#^9~ zVjU2JBzdt6T4Ae$4ik@y!r(BiugYSf)e2%$UC;S!KO841fJ=-OA2J~WN=+#$6GYPB z2G(nag|?Z1Qr|I5s4*5}g)zK=&0#0dxcUyrt~&5)F;x*W&74Dn5~2joTBw5?9z?cv z+}15z4Fz?K*}cGv5>vOlyyun>S|QC?fFjCfz5yU(@=WI%9aW+cc298MX6NAh8FUVN z+%|~GP;kT`wJ8`GM5a&&L+psY)4(tzqclKiQ&KuE< zOmmbFGfihINSp=ER@0OYGP6AEI=3go;2gJHDucWm!7nLeW4fB-CubamP>-ZZ)wMe_ zc7+|Cx~h+s11HoGc=TqvoaS+lQB^EPWsfab=Kxuq1YHuEkGriXR0hwY;tDd@x{UBy z7C4y3A@?*vQ!vB*Jo*V`V-}`4(w!Q&zhyOm#Lve%eznT_$lOe0L*hQaLt_fXIRao$Sg3 z=gC%}TFyd_Z0_Gq2}!+G@bTM3{)UMfAfb(+C`OxC%R$$9f?1MpoQmeTN%+WS*QRfR z&oRukpT!5$i2PX>C*#j{8smwk45-`+#8=vkZB<=cnQ*=^Q$AX*;`v79?80e1qDv%q zLWT5LkLW&4JqJYEjK#O(;ol@r(Bt-(^XYH@_HiFHVO zLoU57t;$yr8z+vCg@3UBqv8Qh_R}OX+eESxw+OaQ;#hJNdmnRW{5jZz?Yeu(K4@0x zHp4Xk{EnbmT%#REqv^pkNn@)5HVyAw493q6gtY>w3b2x*CG7GI2I3jnR!R&x{p{G= z4tav17Pm&G^jaGuPyz}6~n7R~vHGzdn~!f>f-AxWpF&C4P1j!HuoobV|m8@ZamNL`LJP?LxHtO9{t&Dmo zci1(x@^E7jZfKlFD#Lp-G@MTq;-`D;BN~w92wnr605RG;tV&*wUhSfQ_a<3bO*Z!C5(=XE0#*{>-2?!HQyXg242sCw17 z!tF7^t7b-Tak8a7Wq%-kE#biXBIaWHu#SJ`hv z${g{6*jA!$&rdEvi3X}7fRR>yq6liuL zutH)utXfA|xpP1GAbooUhkkbFJ;eA~X!BwWn$Yo+Du6_<1#3tA=OrSDjlKwp>(SRu zTaUeG>?>IMQ1G>p_?*7g;xOc*F~pFtMBk#(8Hx+LzV~iK(JjvBLk~W_LTFw0+NQ%Z z1{qc-{58l|*9e~!f!iGGfMcTHRprEOmmEdvS#%3+oj@PBvI#78I={`cPx#cYuL6z? zh>!T{1c#(}QDrPiPRzukp8}S=*~4KC4)5-)%L>0(qby0m(nd}1&tegI%PcR*%M~yo z?>Jts`u>r+xK%Z3o4D0QbqpB(o+mg2cjuTy%-Kj<$qS{!; zwu1p|V$f&fAql<|(JEuSv6TeRcOtAS#2bS&gHyJ&`ks*#RLQU+#Z}_1&T*Aw zKNyo88$X>HuJA=>DL3FKmqon=K7qvr;eY=1Z};IUf95Hdn(L*iZLF1A*E#LbTeUhy zaXVa#O?;ggTu5ucU-?!6r%$H!q$=!qJ2$%z*P8*&2<4A<5;d|S;fh#yapO3;a*zy6 zn;M5I@e4ehR!?(S131})6K-GP1x}j-vzXZ+#qNVg9CC<_SmPb_lBut$gu*r3y`~j} zIJy?3pv^^lEf!Ogz=CVIhLaB8AYD># { // 4. Wait for pipeline to complete (PDF decode + chunking + extraction + storage) // This involves multiple LLM calls so give it time - const waitSecs = parseInt(process.env.PIPELINE_WAIT ?? "20", 10); + const waitSecs = Number.parseInt(process.env.PIPELINE_WAIT ?? "20", 10); for (let i = waitSecs; i > 0; i--) { process.stdout.write(`\r Waiting... ${i}s remaining `); await new Promise((r) => setTimeout(r, 1000)); @@ -574,17 +574,16 @@ async function testFullPipeline(): Promise { if (triplesFound && embeddingsFound) { pass("Full pipeline: PDF decoded, triples stored, embeddings stored"); return true; - } else if (triplesFound) { + }if (triplesFound) { pass("Full pipeline: triples stored (embeddings pending)"); return true; - } else if (embeddingsFound) { + }if (embeddingsFound) { pass("Full pipeline: embeddings stored (triples pending)"); return true; - } else { + } // Pipeline triggered but stores not populated yet — partial success pass("Full pipeline: triggered successfully (stores may need more time)"); return true; - } } catch (err) { fail("Full pipeline", err); return false;