Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions oxlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ export default defineConfig({
"effect/avoid-ts-ignore": "error",
// Effect.all and Effect.forEach default to sequential. Name that choice at the call.
"effect/require-effect-concurrency": "error",
// Effect.ignore followed by Effect.as drops a value the next call puts back.
"effect/no-effect-ignore-then-as": "error",
// yield* ref, deferred, fiber, and latch were removed in Effect v4.
"effect/avoid-yield-ref": "error",
// let inside a Layer or Context.Service factory hides fiber-visible state.
"effect/avoid-mutable-state": "error",
// Context.Tag, Effect.Service, and ServiceMap were removed. Use Context.Service.
"effect/context-tag-extends": "error",
// Option.match that returns [] or [value] is Arr.getSomes or Array.fromOption.
"effect/prefer-array-fromoption-over-option-match-empty": "error",
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Arr from "effect/Array"
import * as Effect from "effect/Effect"
import * as Match from "effect/Match"
import * as Option from "effect/Option"
Expand Down Expand Up @@ -38,11 +39,10 @@ function stringRecord(value: unknown): Record<string, string> {
)

return Object.fromEntries(
Object.entries(record).flatMap(([key, recordValue]) =>
Option.match(stringValue(recordValue), {
onNone: () => [],
onSome: (resolved) => [[key, resolved] as const],
}),
Arr.getSomes(
Object.entries(record).map(([key, recordValue]) =>
Option.map(stringValue(recordValue), (resolved) => [key, resolved] as const),
),
),
)
}
Expand Down
22 changes: 12 additions & 10 deletions packages/api/src/server/background/ai-providers/litellm-models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ReasoningEffort } from "@solzero/shared"
import * as Arr from "effect/Array"
import * as Match from "effect/Match"
import * as Option from "effect/Option"
import * as P from "effect/Predicate"
Expand Down Expand Up @@ -126,11 +127,10 @@ function readAdapter(value: unknown): Option.Option<LitellmAiSdkAdapter> {

function readAdapterOverrides(value: unknown): Record<string, LitellmAiSdkAdapter> {
return Object.fromEntries(
Object.entries(asRecord(value)).flatMap(([modelId, adapter]) =>
Option.match(readAdapter(adapter), {
onNone: () => [],
onSome: (normalized) => [[modelId, normalized] as const],
}),
Arr.getSomes(
Object.entries(asRecord(value)).map(([modelId, adapter]) =>
Option.map(readAdapter(adapter), (normalized) => [modelId, normalized] as const),
),
),
)
}
Expand Down Expand Up @@ -454,11 +454,13 @@ export function normalizeModelInfoResponse(
)

const models = Object.fromEntries(
data.flatMap((entry) =>
Option.match(normalizeModelInfoEntry(entry, config.adapterOverrides, now), {
onNone: () => [],
onSome: (model) => [[model.id, model] as const],
}),
Arr.getSomes(
data.map((entry) =>
Option.map(
normalizeModelInfoEntry(entry, config.adapterOverrides, now),
(model) => [model.id, model] as const,
),
),
),
)

Expand Down
17 changes: 3 additions & 14 deletions packages/api/src/server/background/db/mcpcf.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Arr from "effect/Array"
import * as Effect from "effect/Effect"
import * as Match from "effect/Match"
import * as Option from "effect/Option"
Expand Down Expand Up @@ -601,14 +602,7 @@ export class McpcfRegistryStore {
concurrency: "unbounded",
})

return serverOptions
.flatMap((server) =>
Option.match(server, {
onNone: () => [],
onSome: (record) => [record],
}),
)
.sort((left, right) => left.label.localeCompare(right.label))
return Arr.getSomes(serverOptions).sort((left, right) => left.label.localeCompare(right.label))
})

listAvailableServers = Effect.fn("db.mcpcf.listAvailableServers")(function* (
Expand Down Expand Up @@ -652,12 +646,7 @@ export class McpcfRegistryStore {
concurrency: "unbounded",
})

return serverOptions.flatMap((server) =>
Option.match(server, {
onNone: () => [],
onSome: (record) => [record],
}),
)
return Arr.getSomes(serverOptions)
})

listAvailableServersByIds = Effect.fn("db.mcpcf.listAvailableServersByIds")(function* (
Expand Down
9 changes: 2 additions & 7 deletions packages/api/src/server/background/mcpcf/admin-actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Arr from "effect/Array"
import * as Effect from "effect/Effect"
import * as Match from "effect/Match"
import * as Option from "effect/Option"
Expand Down Expand Up @@ -37,13 +38,7 @@ function booleanValue(value: unknown): boolean {
function stringArrayValue(value: unknown): string[] {
return Option.match(Option.filter(Option.some(value), Array.isArray), {
onNone: () => [],
onSome: (items) =>
items.flatMap((item) =>
Option.match(stringValue(item), {
onNone: () => [],
onSome: (resolved) => [resolved],
}),
),
onSome: (items) => Arr.getSomes(items.map((item) => stringValue(item))),
})
}

Expand Down
25 changes: 15 additions & 10 deletions packages/api/src/server/background/observability/span.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Arr from "effect/Array"
import * as Cause from "effect/Cause"
import * as Context from "effect/Context"
import * as Effect from "effect/Effect"
Expand All @@ -16,11 +17,13 @@ export type SpanAttributeInput = Record<string, SpanAttributeValue | null | unde

export function spanAttributeInput(fields: Record<string, unknown>): SpanAttributeInput {
return Object.fromEntries(
Object.entries(fields).flatMap(([key, value]) =>
Option.match(spanAttributeValue(value), {
onNone: (): Array<[string, SpanAttributeValue]> => [],
onSome: (attribute) => [[key, attribute]],
}),
Arr.getSomes(
Object.entries(fields).map(([key, value]) =>
Option.map(spanAttributeValue(value), (attribute): [string, SpanAttributeValue] => [
key,
attribute,
]),
),
),
)
}
Expand All @@ -43,11 +46,13 @@ export function setCloudflareSpanAttributes(

export function toSpanAttributes(fields: SpanAttributeInput): Record<string, SpanAttributeValue> {
return Object.fromEntries(
Object.entries(fields).flatMap(([key, value]) =>
Option.match(spanAttributeValue(value), {
onNone: (): Array<[string, string | number | boolean]> => [],
onSome: (attribute) => [[key, attribute]],
}),
Arr.getSomes(
Object.entries(fields).map(([key, value]) =>
Option.map(spanAttributeValue(value), (attribute): [string, SpanAttributeValue] => [
key,
attribute,
]),
),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Arr from "effect/Array"
import * as Effect from "effect/Effect"
import * as Match from "effect/Match"
import * as Option from "effect/Option"
Expand Down Expand Up @@ -49,9 +50,7 @@ export const resolveSharedProviderOutboundHosts = Effect.fn(
() => CLOUDFLARE_AI_GATEWAY_PROVIDER_NATIVE_HOST,
)

return [litellmHost, cloudflareHost, cloudflareProviderNativeHost].flatMap((host) =>
Option.match(host, { onNone: () => [], onSome: (value) => [value] }),
)
return Arr.getSomes([litellmHost, cloudflareHost, cloudflareProviderNativeHost])
})

export interface SharedProviderCredential {
Expand Down
8 changes: 3 additions & 5 deletions packages/api/src/server/mcp/ai-search-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type Tool,
} from "@modelcontextprotocol/sdk/types.js"
import { runEffectPromise } from "../lib/effect-promise"
import * as Arr from "effect/Array"
import * as Match from "effect/Match"
import * as Option from "effect/Option"
import * as Schema from "effect/Schema"
Expand Down Expand Up @@ -82,11 +83,8 @@ function requireAllSourcesAvailable(
Match.orElse(() => undefined),
)

return requestedSourceIds.flatMap((sourceId) =>
Option.match(Option.fromNullishOr(sourceById.get(sourceId)), {
onNone: () => [],
onSome: (source) => [source],
}),
return Arr.getSomes(
requestedSourceIds.map((sourceId) => Option.fromNullishOr(sourceById.get(sourceId))),
)
}

Expand Down
Loading