Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/claude-sdk-cli/src/runAgent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnthropicBeta, type AnyToolDefinition, type IAnthropicAgent, type SdkMessage } from '@shellicar/claude-sdk';
import { AnthropicBeta, type AnyToolDefinition, CacheTtl, type IAnthropicAgent, type SdkMessage } from '@shellicar/claude-sdk';
import { CreateFile } from '@shellicar/claude-sdk-tools/CreateFile';
import { DeleteDirectory } from '@shellicar/claude-sdk-tools/DeleteDirectory';
import { DeleteFile } from '@shellicar/claude-sdk-tools/DeleteFile';
Expand Down Expand Up @@ -29,7 +29,7 @@ export async function runAgent(agent: IAnthropicAgent, prompt: string, layout: A

const cwd = process.cwd();
const model = 'claude-sonnet-4-6';
const cacheTtl = '5m' as const;
const cacheTtl = CacheTtl.OneHour;

const transformToolResult = (toolName: string, output: unknown): unknown => {
const result = refTransform(toolName, output);
Expand All @@ -44,10 +44,10 @@ export async function runAgent(agent: IAnthropicAgent, prompt: string, layout: A

const { port, done } = agent.runAgent({
model,
maxTokens: 8000,
maxTokens: 32000,
messages: [prompt],
systemPrompts,
cacheTtl: '1h',
cacheTtl,
transformToolResult,
pauseAfterCompact: true,
compactInputTokens: 150_000,
Expand Down
28 changes: 3 additions & 25 deletions packages/claude-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import type { AuthCredentials } from './private/Auth/types';
import { calculateCost } from './private/pricing';
import { createAnthropicAgent } from './public/createAnthropicAgent';
import { defineTool } from './public/defineTool';
import { AnthropicBeta } from './public/enums';
import { AnthropicBeta, CacheTtl } from './public/enums';
import { IAnthropicAgent } from './public/interfaces';
import type {
AnthropicAgentOptions,
AnthropicBetaFlags,
AnyToolDefinition,
CacheTtl,
ConsumerMessage,
ILogger,
RunAgentQuery,
Expand All @@ -28,26 +27,5 @@ import type {
} from './public/types';

export type { BetaMessageParam } from '@anthropic-ai/sdk/resources/beta.js';
export type {
AnthropicAgentOptions,
AnthropicBetaFlags,
AnyToolDefinition,
AuthCredentials,
CacheTtl,
ConsumerMessage,
ILogger,
RunAgentQuery,
RunAgentResult,
SdkDone,
SdkError,
SdkMessage,
SdkMessageEnd,
SdkMessageStart,
SdkMessageText,
SdkMessageUsage,
SdkQuerySummary,
SdkToolApprovalRequest,
ToolDefinition,
ToolOperation,
};
export { AnthropicAuth, AnthropicBeta, calculateCost, createAnthropicAgent, defineTool, IAnthropicAgent };
export type { AnthropicAgentOptions, AnthropicBetaFlags, AnyToolDefinition, AuthCredentials, ConsumerMessage, ILogger, RunAgentQuery, RunAgentResult, SdkDone, SdkError, SdkMessage, SdkMessageEnd, SdkMessageStart, SdkMessageText, SdkMessageUsage, SdkQuerySummary, SdkToolApprovalRequest, ToolDefinition, ToolOperation };
export { AnthropicAuth, AnthropicBeta, CacheTtl, calculateCost, createAnthropicAgent, defineTool, IAnthropicAgent };
3 changes: 2 additions & 1 deletion packages/claude-sdk/src/private/AgentRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
import type { MessagePort } from 'node:worker_threads';
import type { Anthropic } from '@anthropic-ai/sdk';
import type { BetaCompactionBlockParam, BetaTextBlockParam, BetaThinkingBlockParam, BetaToolUseBlockParam } from '@anthropic-ai/sdk/resources/beta.mjs';
import { CacheTtl } from '../public/enums';
import type { AnyToolDefinition, ILogger, RunAgentQuery, SdkMessage } from '../public/types';
import { AgentChannel } from './AgentChannel';
import { ApprovalState } from './ApprovalState';
Expand Down Expand Up @@ -79,7 +80,7 @@ export class AgentRun {
return;
}

const cacheTtl = this.#options.cacheTtl ?? '5m';
const cacheTtl = this.#options.cacheTtl ?? CacheTtl.OneHour;
const costUsd = calculateCost(result.usage, this.#options.model, cacheTtl);
const contextWindow = getContextWindow(this.#options.model);
this.#channel.send({ type: 'message_usage', ...result.usage, costUsd, contextWindow } satisfies SdkMessage);
Expand Down
4 changes: 2 additions & 2 deletions packages/claude-sdk/src/private/RequestBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Anthropic } from '@anthropic-ai/sdk';
import type { BetaMessageStreamParams } from '@anthropic-ai/sdk/resources/beta/messages.js';
import type { BetaCacheControlEphemeral, BetaClearThinking20251015Edit, BetaClearToolUses20250919Edit, BetaCompact20260112Edit, BetaContentBlockParam, BetaContextManagementConfig, BetaTextBlockParam, BetaToolUnion } from '@anthropic-ai/sdk/resources/beta.mjs';
import { AnthropicBeta } from '../public/enums';
import { CacheTtl, type RunAgentQuery } from '../public/types';
import { AnthropicBeta, CacheTtl } from '../public/enums';
import type { RunAgentQuery } from '../public/types';
import { AGENT_SDK_PREFIX } from './consts';

export type RequestParams = {
Expand Down
2 changes: 1 addition & 1 deletion packages/claude-sdk/src/private/pricing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type CacheTtl = '5m' | '1h';
import type { CacheTtl } from '../public/enums';

type ModelRates = {
input: number;
Expand Down
5 changes: 5 additions & 0 deletions packages/claude-sdk/src/public/enums.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export enum CacheTtl {
FiveMinutes = '5m',
OneHour = '1h',
}

export enum AnthropicBeta {
/**
* @see https://platform.claude.com/docs/en/build-with-claude/compaction
Expand Down
8 changes: 1 addition & 7 deletions packages/claude-sdk/src/public/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MessagePort } from 'node:worker_threads';
import type { Model } from '@anthropic-ai/sdk/resources/messages';
import type { z } from 'zod';
import type { AnthropicBeta } from './enums';
import type { AnthropicBeta, CacheTtl } from './enums';

export type ToolOperation = 'read' | 'write' | 'delete';

Expand All @@ -25,11 +25,6 @@ export type AnyToolDefinition = {

export type AnthropicBetaFlags = Partial<Record<AnthropicBeta, boolean>>;

export enum CacheTtl {
FiveMinutes = '5m',
OneHour = '1h',
}

export type RunAgentQuery = {
model: Model;
thinking?: boolean;
Expand All @@ -47,7 +42,6 @@ export type RunAgentQuery = {
};

/** Messages sent from the SDK to the consumer via the MessagePort. */

export type SdkMessageStart = { type: 'message_start' };
export type SdkMessageText = { type: 'message_text'; text: string };
export type SdkMessageThinking = { type: 'message_thinking'; text: string };
Expand Down
4 changes: 2 additions & 2 deletions packages/claude-sdk/test/RequestBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { describe, expect, it } from 'vitest';
import type { BetaMessageParam } from '../src/index.js';
import { AGENT_SDK_PREFIX } from '../src/private/consts.js';
import { buildRequestParams } from '../src/private/RequestBuilder.js';
import { AnthropicBeta } from '../src/public/enums.js';
import { type AnyToolDefinition, CacheTtl, type RunAgentQuery } from '../src/public/types.js';
import { AnthropicBeta, CacheTtl } from '../src/public/enums.js';
import type { AnyToolDefinition, RunAgentQuery } from '../src/public/types.js';

// ---------------------------------------------------------------------------
// Helpers
Expand Down
Loading