npm.io
0.2.1 • Published 4h ago

@aevr/agents-ai-sdk

Licence
MIT
Version
0.2.1
Deps
0
Size
57 kB
Vulns
0
Weekly
0

@aevr/agents-ai-sdk

Vercel AI SDK inference and loop adapters for @aevr/agents.

Status

The public inference adapter is available. Provider-neutral messages, tools, models, and inference results are mapped without adding AI SDK dependencies to the core package.

The adapter targets AI SDK v7 and requires Node.js 22 or newer. Repository development and publication CI use Node.js 24.

Inference gateway

import { AiSdkInferenceGateway } from "@aevr/agents-ai-sdk";
import { openai } from "@ai-sdk/openai";

const gateway = new AiSdkInferenceGateway({
  models: [{ id: "gpt-5", provider: "openai" }],
  resolveModel(modelId) {
    return { model: openai(modelId), provider: "openai" };
  },
});

AiSdkInferenceGateway implements the portable InferenceGateway contract. Applications own provider packages, credentials, and model selection through resolveModel; this package never stores provider keys.

Mappings include:

  • Portable system, user, assistant, tool-call, tool-result, and approval-response messages to AI SDK v7 ModelMessage values.
  • Portable closed JSON Schema tool definitions to AI SDK tools without executing them.
  • Model catalog and model resolver selection.
  • Text, tool calls, finish reason, request/model IDs, provider, and token usage back to portable inference responses.
  • Allowed-provider metadata, temperature, output-token bounds, abort signals, and response schemas.

The gateway performs one model invocation and supports normalized streaming through the portable gateway contract.

Bounded agent loop

AiSdkAgentLoopAdapter implements the portable AgentLoopAdapter contract over any InferenceGateway:

  • Generate or stream mode with one stable invocation ID per model turn.
  • Agent instructions and task fallback prompts without mutating durable input.
  • Active capability schemas and policy-bound RegisteredTool execution.
  • Deeply immutable principal/run context passed to tools.
  • Cumulative model/tool step, token, and cost limits.
  • Run-duration/deadline timeout and caller cancellation propagation.
  • Portable model, tool, approval, completion, and failure events.
  • Approval suspension with a persisted tool result and resume from approval-response messages.
  • Structured RunOutcome JSON when provided, with safe plain-text completion fallback.

The adapter does not persist events, actions, approvals, or checkpoints. Compose it with @aevr/agents-runtime-local so the durable runtime remains the authority for leases, action idempotency, approval records, usage reconciliation, and crash recovery.

When a durable tool returns waiting_approval with output.approvalId, the loop propagates that exact persisted ID into its message and approval.requested event. Legacy tools without a durable ID still receive an adapter-generated ID.

Development

pnpm test
pnpm run typecheck
pnpm run build
npm pack --dry-run

License

MIT

Keywords