@noetaris/harness-openai
v0.4.0
Published
OpenAI adapter for @noetaris/harness
Downloads
41
Readme
@noetaris/harness-openai
OpenAI adapter for @noetaris/harness.
Status: not yet released. Implementation tracked in F21.
Overview
@noetaris/harness-openai provides an OpenAI class that implements the LLM and ObserverAware interfaces from @noetaris/harness. It handles translation between the harness message format and the OpenAI chat.completions.create format, and emits telemetry events (token usage, model ID) through an attached Observer.
Installation
pnpm add @noetaris/harness-openaiPeer dependencies:
pnpm add @noetaris/harness @noetaris/harness-typesRequires Node.js ≥ 22.
Usage
import { OpenAI } from '@noetaris/harness-openai'
const llm = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
// Wire into a harness provider slot
h.provide('model', runtime())
const agent = createAgent(h, { prompts: { system: '...' } })
const run = agent.run(initialState, { model: llm })API
OpenAI
Implements LLM and ObserverAware.
invoke(messages, options?)— translates harnessMessage[]andTool[]to OpenAI format, callschat.completions.create(), and maps the response back toLLMResponse(includingtool_callsextraction).bindObserver(observer)— attaches anObserver; after eachinvoke, emits an"llm.response"event with{ tokens: { input, output }, modelId }fromusagein the response.
MockOpenAI
A deterministic test double for use in tests and demos without a real API key.
Related Packages
@noetaris/harness— core execution engine@noetaris/harness-types— shared LLM type contract@noetaris/harness-anthropic— Anthropic Claude adapter@noetaris/harness-google— Google Gemini adapter@noetaris/harness-otel— OpenTelemetry observer bridge
License
MIT
