Files
agentlens/packages/sdk-ts/src/decision.ts
Vectry 6bed493275 feat: TypeScript SDK (agentlens-sdk) and OpenCode plugin (opencode-agentlens)
- packages/sdk-ts: BatchTransport, TraceBuilder, models, decision helpers
  Zero external deps, native fetch, ESM+CJS output
- packages/opencode-plugin: OpenCode plugin with hooks for:
  - Session lifecycle (create/idle/error/delete/diff)
  - Tool execution capture (before/after -> TOOL_CALL spans + TOOL_SELECTION decisions)
  - LLM call tracking (chat.message -> LLM_CALL spans with model/provider)
  - Permission flow (permission.ask -> ESCALATION decisions)
  - File edit events
  - Model cost estimation (Claude, GPT-4o, o3-mini pricing)
2026-02-10 03:08:51 +00:00

30 lines
826 B
TypeScript

import type { DecisionPointPayload, DecisionType, JsonValue } from "./models.js";
import { generateId, nowISO } from "./models.js";
export interface CreateDecisionInput {
type: DecisionType;
chosen: JsonValue;
alternatives?: JsonValue[];
reasoning?: string;
contextSnapshot?: JsonValue;
durationMs?: number;
costUsd?: number;
parentSpanId?: string;
timestamp?: string;
}
export function createDecision(input: CreateDecisionInput): DecisionPointPayload {
return {
id: generateId(),
type: input.type,
chosen: input.chosen,
alternatives: input.alternatives ?? [],
reasoning: input.reasoning,
contextSnapshot: input.contextSnapshot,
durationMs: input.durationMs,
costUsd: input.costUsd,
parentSpanId: input.parentSpanId,
timestamp: input.timestamp ?? nowISO(),
};
}