@effect-uai/typesafe-ai

中文文档
0.19.1发布于 2026/11/15MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2.6万

TypeSafe AI provider for @effect-uai/core (Jev System One decision model).

原始使用文档
文档目录8 节
  1. Install
  2. Wire it up
  3. Decide
  4. Models
  5. What the input schema is for
  6. About the scores
  7. Errors
  8. See also

@effect-uai/typesafe-ai

TypeSafe AI provider for @effect-uai/core. Serves the DecisionModel capability with Jev, a System One model that answers typed questions about an input with probabilities instead of generating text.

Experimental. This class of model is new and the shape may change.

Install

pnpm add @effect-uai/core @effect-uai/typesafe-ai effect

Wire it up

import { Config, Effect, Layer } from "effect"
import { FetchHttpClient } from "effect/http"
import { layer as jevLayer } from "@effect-uai/typesafe-ai/Jev"

const provider = Layer.unwrap(
  Effect.gen(function* () {
    const apiKey = yield* Config.Redacted("TYPESAFE_AI_API_KEY")
    return jevLayer({ apiKey })
  }),
)

const mainLayer = provider.pipe(Layer.provide(FetchHttpClient.layer))

One layer, two tags: Jev for its own reported confidence, DecisionModel for provider-portable code.

Decide

import { Schema } from "effect"
import * as Decision from "@effect-uai/core/Decision"
import { decide } from "@effect-uai/core/DecisionModel"

const triage = Decision.make({
  inputSchema: Schema.Struct({ message: Schema.String }),
  decisions: {
    department: Decision.classify({
      instructions: "Which team should handle this?",
      criteria: {
        billing: "Payments, invoicing, refunds",
        technical: "Bugs, outages, integrations",
      },
    }),
    severity: Decision.rate({
      instructions: "How severe is the reported issue?",
      criteria: ["Cosmetic", "Degraded", "Blocking"],
    }),
    urgent: Decision.probability({ instructions: "Does this convey urgency?" }),
  },
})

const program = Effect.gen(function* () {
  const { answers } = yield* decide(triage, {
    model: "jev-latest",
    input: { message: "Payouts have been failing for 3 days." },
  })

  answers.department.labels.billing // number
  answers.urgent.probability // number
  answers.severity.legend[Decision.topLevel(answers.severity)] // "Degraded"

  const leader = Decision.ranked(answers.department)[0]
  return leader === undefined || leader.probability < 0.5 ? "escalate" : leader.label
})

Every decision in a definition is answered in one call, and the encoded input is billed once, so batch them rather than calling per question.

Models

jev-latest (default), jev-preview, jev-1.13.0. 64k tokens per request, of which roughly 32k for the encoded input plus the longest single decision. Text only.

What the input schema is for

inputSchema encodes the input on the way out. A schema that omits a field keeps it from the model, which is the supported way to hold irrelevant or sensitive context out of a request. The vendor documents large irrelevant input as a distractor, so projecting deliberately is worth doing.

About the scores

Probabilities sum to 1 within floating-point error and are comparable within one answer. Jev's own confidence is available on the Jev tag; it is not on the common answer because its formula is undocumented and it is absent on probability decisions. Decision.confidence and Decision.margin are computed from the distribution, documented, and defined for every kind. Gate on the top probability and margin, not on confidence: normalised entropy shrinks as the label count grows, so a threshold tuned on two labels quietly demands far more mass on four.

Known weak spots per the vendor's own jaggedness notes: counting and arithmetic, date ordering, multi-hop reasoning, and rubric scores are weakly calibrated so expectedLevel should not be read back as a magnitude. Input is not treated as hostile, so an injected instruction in the input can steer an answer.

Errors

StatusAiError
401AuthFailed{subtype:"auth"}
402AuthFailed{subtype:"billing"}
403AuthFailed{subtype:"permission"}
408 / 504Timeout
413ContextLengthExceeded
422InvalidRequest
429RateLimited
5xxUnavailable

An input the schema cannot encode is InvalidRequest with param: "input". An answer whose shape does not match the decision that asked for it is GenerationFailed.

See also

版本与发布记录

@effect-uai/typesafe-ai 共发布 8 个版本,首次发布于 2026/09/19;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.19.1latest2026/11/15今天
0.20.0-dev-20261110202152dev2026/11/115 天前
0.19.02026/11/105 天前
0.19.0-dev-202611100659302026/11/105 天前
0.19.0-dev-202611091839592026/11/106 天前
0.18.02026/10/061 个月前

关于 @effect-uai/typesafe-ai 的常见问题

@effect-uai/typesafe-ai 是什么?

TypeSafe AI provider for @effect-uai/core (Jev System One decision model).

如何安装 @effect-uai/typesafe-ai?

在项目目录运行 npm install @effect-uai/typesafe-ai,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:effect(>=4.0.1 <5.0.0)、@effect-uai/core(>=0.17.0 <1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@effect-uai/typesafe-ai 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@effect-uai/typesafe-ai 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@effect-uai/typesafe-ai 可以商用吗?

@effect-uai/typesafe-ai 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@effect-uai/typesafe-ai 的下载量有多少?

根据 npm 官方下载统计,@effect-uai/typesafe-ai 在 2026/10/13 – 2026/11/11 这 30 天内被下载 25,756 次,日均约 859 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@effect-uai/typesafe-ai 还在维护吗?

最新版本 0.19.1 发布于 2026/11/15(今天);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/09/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。