SwapAI

Effect

Use the configured classifier lifecycle through typed Effects.

Effect support is an optional entry point. Install Effect in the application:

npm install effect

Configured classifier

import { Effect } from "effect";
import {
  classifyConfigured,
  close,
  createClassifierEffect,
  inspect,
} from "@swapai/core/effect";

const program = Effect.gen(function* () {
  const relevance = yield* createClassifierEffect({
    name: "accountant-relevance",
    result: { type: "number", min: 0, max: 1 },
    reference: callGrok,
    facets: ["documentFamily"] as const,
  });

  const score = yield* classifyConfigured(relevance, input, {
    documentFamily: "invoice",
  });
  const status = yield* inspect(relevance);
  yield* close(relevance);

  return { score, status };
});

@swapai/core/effect exports typed wrappers for the whole modern lifecycle:

isTrained(classifier)
classifyConfigured(classifier, input, facets?)
logClassification(classifier, input, result, facets?)
inspect(classifier)
requestTraining(classifier)
retryTraining(classifier, trainingRunId)
promoteCandidate(classifier, trainingRunId)
reconcileTraining(classifier)
erase(classifier)
flush(classifier)
close(classifier)

Synchronous operations use Effect.try; asynchronous operations use Effect.tryPromise. Failures are exposed as SwapAIError instead of defects or hidden rejected promises.

Effect reference compatibility

The legacy init() classifier can accept a reference that has its own typed Effect error and requirements:

import { classifyWithReference } from "@swapai/core/effect";

declare const callReference: (
  input: string,
) => Effect.Effect<number, GrokError, GrokClient>;

const program = classifyWithReference(
  legacyClassifier,
  input,
  callReference,
  { documentFamily: "invoice" },
);
// Effect.Effect<number, SwapAIError | GrokError, GrokClient>

This adapter preserves the reference error, service requirements and interruption. The modern createClassifier() configuration keeps its documented Promise reference contract; wrap your Effect reference at that boundary if you use it there.

The main @swapai/core import does not require Effect at runtime.