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)
This commit is contained in:
29
packages/sdk-ts/src/decision.ts
Normal file
29
packages/sdk-ts/src/decision.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user