raysurfer 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # RaySurfer TypeScript SDK
2
+
3
+ TypeScript SDK for RaySurfer - code block caching and retrieval for AI agents with Claude Agent SDK integration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install raysurfer
9
+ # or
10
+ bun add raysurfer
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ### Basic Client (Store/Retrieve Code Blocks)
16
+
17
+ ```typescript
18
+ import { RaySurfer } from "raysurfer";
19
+
20
+ const client = new RaySurfer({ apiKey: "rs_..." });
21
+
22
+ // Store a code block
23
+ const result = await client.storeCodeBlock({
24
+ name: "GitHub User Fetcher",
25
+ source: "async function fetchUser(username) { ... }",
26
+ entrypoint: "fetchUser",
27
+ language: "typescript",
28
+ });
29
+
30
+ // Retrieve code blocks for a task
31
+ const response = await client.retrieve({ task: "Fetch GitHub user data" });
32
+ for (const match of response.codeBlocks) {
33
+ console.log(match.codeBlock.name, match.verdictScore);
34
+ }
35
+ ```
36
+
37
+ ### Claude Agent SDK Integration
38
+
39
+ ```typescript
40
+ import { RaysurferClient } from "raysurfer";
41
+
42
+ const client = new RaysurferClient({
43
+ raysurferApiKey: "rs_...",
44
+ model: "claude-sonnet-4-5",
45
+ systemPrompt: "You are a helpful assistant.",
46
+ allowedTools: ["Read", "Write", "Bash"],
47
+ });
48
+
49
+ // Pre-fetches code files, downloads to sandbox, injects into prompt
50
+ for await (const message of client.query("Fetch user data from GitHub API")) {
51
+ if (message.type === "assistant") {
52
+ console.log(message.content);
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## How It Works
58
+
59
+ 1. **On `query()`**: RaysurferClient calls the backend to get relevant code files
60
+ 2. **Downloads to sandbox**: Files are written to `~/.raysurfer/sandbox/`
61
+ 3. **Injects into prompt**: Code snippets are added to the system prompt
62
+ 4. **Agent executes**: Agent can run the code using the Bash tool within the sandbox
63
+ 5. **Caches results**: On success, generated code is stored back to the cache
64
+
65
+ ## RaysurferAgentOptions
66
+
67
+ ```typescript
68
+ interface RaysurferAgentOptions {
69
+ // Raysurfer-specific
70
+ raysurferApiKey?: string;
71
+ raysurferBaseUrl?: string;
72
+ prefetchCount?: number; // default: 5
73
+ minVerdictScore?: number; // default: 0.3
74
+ preferComplete?: boolean; // default: true
75
+ sandboxDir?: string; // default: ~/.raysurfer/sandbox
76
+ cleanupSandbox?: boolean; // default: true
77
+ cleanupOnError?: boolean; // default: false
78
+
79
+ // Standard Claude Agent SDK options
80
+ model?: string; // default: "claude-sonnet-4-5"
81
+ workingDirectory?: string;
82
+ systemPrompt?: string;
83
+ permissionMode?: "default" | "acceptEdits" | "plan" | "bypassPermissions";
84
+ maxBudgetUsd?: number;
85
+ allowedTools?: string[];
86
+ disallowedTools?: string[];
87
+ maxTurns?: number;
88
+ env?: Record<string, string>;
89
+ mcpServers?: Record<string, unknown>;
90
+ }
91
+ ```
92
+
93
+ ## API Reference
94
+
95
+ ### RaySurfer Client
96
+
97
+ ```typescript
98
+ const client = new RaySurfer({ apiKey: "rs_..." });
99
+
100
+ // Store
101
+ await client.storeCodeBlock({ name, source, entrypoint, language, ... });
102
+ await client.storeExecution({ codeBlockId, triggeringTask, inputData, outputData, ... });
103
+ await client.submitExecutionResult(task, filesWritten, succeeded);
104
+
105
+ // Retrieve
106
+ await client.retrieve({ task, topK, minVerdictScore });
107
+ await client.retrieveBest({ task, topK, minVerdictScore });
108
+ await client.getFewShotExamples(task, k);
109
+ await client.getTaskPatterns({ task, codeBlockId, minThumbsUp, topK });
110
+ await client.getCodeFiles({ task, topK, minVerdictScore, preferComplete });
111
+ ```
112
+
113
+ ## License
114
+
115
+ MIT
@@ -0,0 +1,98 @@
1
+ /**
2
+ * RaySurfer SDK client
3
+ */
4
+ import type { AgentReview, AgentVerdict, ExecutionState, FewShotExample, FileWritten, GetCodeFilesResponse, RetrieveBestResponse, RetrieveCodeBlockResponse, StoreCodeBlockResponse, StoreExecutionResponse, SubmitExecutionResultResponse, TaskPattern } from "./types";
5
+ export interface RaySurferOptions {
6
+ apiKey?: string;
7
+ baseUrl?: string;
8
+ timeout?: number;
9
+ }
10
+ export interface StoreCodeBlockParams {
11
+ name: string;
12
+ source: string;
13
+ entrypoint: string;
14
+ language: string;
15
+ description?: string;
16
+ inputSchema?: Record<string, unknown>;
17
+ outputSchema?: Record<string, unknown>;
18
+ languageVersion?: string;
19
+ dependencies?: string[];
20
+ tags?: string[];
21
+ capabilities?: string[];
22
+ exampleQueries?: string[];
23
+ }
24
+ export interface StoreExecutionParams {
25
+ codeBlockId: string;
26
+ triggeringTask: string;
27
+ inputData: Record<string, unknown>;
28
+ outputData: unknown;
29
+ executionState?: ExecutionState;
30
+ durationMs?: number;
31
+ errorMessage?: string;
32
+ errorType?: string;
33
+ verdict?: AgentVerdict;
34
+ review?: AgentReview;
35
+ }
36
+ export interface RetrieveParams {
37
+ task: string;
38
+ topK?: number;
39
+ minVerdictScore?: number;
40
+ }
41
+ export interface GetCodeFilesParams {
42
+ task: string;
43
+ topK?: number;
44
+ minVerdictScore?: number;
45
+ preferComplete?: boolean;
46
+ }
47
+ export interface GetTaskPatternsParams {
48
+ task?: string;
49
+ codeBlockId?: string;
50
+ minThumbsUp?: number;
51
+ topK?: number;
52
+ }
53
+ /**
54
+ * Async client for RaySurfer API
55
+ */
56
+ export declare class RaySurfer {
57
+ private apiKey?;
58
+ private baseUrl;
59
+ private timeout;
60
+ constructor(options?: RaySurferOptions);
61
+ private request;
62
+ /** Store a new code block */
63
+ storeCodeBlock(params: StoreCodeBlockParams): Promise<StoreCodeBlockResponse>;
64
+ /** Store an execution record */
65
+ storeExecution(params: StoreExecutionParams): Promise<StoreExecutionResponse>;
66
+ /**
67
+ * Submit raw execution result - backend handles all processing.
68
+ *
69
+ * This is the simplified API for agent integrations. Just send:
70
+ * - The task that was executed
71
+ * - Files that were written during execution
72
+ * - Whether the task succeeded
73
+ *
74
+ * Backend handles: entrypoint detection, tag extraction, language detection,
75
+ * deduplication, quality checks, and storage.
76
+ */
77
+ submitExecutionResult(task: string, filesWritten: FileWritten[], succeeded: boolean): Promise<SubmitExecutionResultResponse>;
78
+ /** Retrieve code blocks by task description (semantic search) */
79
+ retrieve(params: RetrieveParams): Promise<RetrieveCodeBlockResponse>;
80
+ /** Get the single best code block for a task using verdict-aware scoring */
81
+ retrieveBest(params: RetrieveParams): Promise<RetrieveBestResponse>;
82
+ /** Retrieve few-shot examples for code generation */
83
+ getFewShotExamples(task: string, k?: number): Promise<FewShotExample[]>;
84
+ /** Retrieve proven task->code mappings */
85
+ getTaskPatterns(params: GetTaskPatternsParams): Promise<TaskPattern[]>;
86
+ /**
87
+ * Get code files for a task, ready to download to sandbox.
88
+ *
89
+ * Returns code blocks with full source code, optimized for:
90
+ * - High verdict scores (proven to work)
91
+ * - More complete implementations (prefer longer source)
92
+ * - Task relevance (semantic similarity)
93
+ */
94
+ getCodeFiles(params: GetCodeFilesParams): Promise<GetCodeFilesResponse>;
95
+ private parseCodeBlock;
96
+ }
97
+ export default RaySurfer;
98
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EAOZ,cAAc,EACd,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,6BAA6B,EAC7B,WAAW,EACZ,MAAM,SAAS,CAAC;AAIjB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAA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+ constructor(message: string);
7
+ }
8
+ /** API returned an error response */
9
+ export declare class APIError extends RaySurferError {
10
+ statusCode?: number;
11
+ constructor(message: string, statusCode?: number);
12
+ }
13
+ /** Authentication failed */
14
+ export declare class AuthenticationError extends RaySurferError {
15
+ constructor(message?: string);
16
+ }
17
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mCAAmC;AACnC,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,qCAAqC;AACrC,qBAAa,QAAS,SAAQ,cAAc;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;gBAER,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAKjD;AAED,4BAA4B;AAC5B,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,GAAE,MAA0B;CAIhD"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * RaySurfer TypeScript SDK
3
+ *
4
+ * Store and retrieve code blocks for AI agents with semantic search
5
+ * and verdict-aware scoring.
6
+ *
7
+ * Includes Claude Agent SDK integration via RaysurferClient.
8
+ */
9
+ export { RaySurfer, default as RaySurferDefault } from "./client";
10
+ export type { RaySurferOptions, StoreCodeBlockParams, StoreExecutionParams, RetrieveParams, GetCodeFilesParams, GetTaskPatternsParams, } from "./client";
11
+ export { RaysurferClient } from "./sdk-client";
12
+ export type { RaysurferAgentOptions } from "./sdk-client";
13
+ export { ExecutionState, AgentVerdict } from "./types";
14
+ export type { CodeBlock, ExecutionIO, AgentReview, ExecutionRecord, BestMatch, AlternativeCandidate, FewShotExample, TaskPattern, FileWritten, StoreCodeBlockResponse, StoreExecutionResponse, CodeBlockMatch, RetrieveCodeBlockResponse, RetrieveBestResponse, SubmitExecutionResultRequest, SubmitExecutionResultResponse, CodeFile, GetCodeFilesResponse, } from "./types";
15
+ export { RaySurferError, APIError, AuthenticationError } from "./errors";
16
+ export declare const VERSION = "0.2.0";
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,SAAS,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAClE,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,YAAY,EACV,SAAS,EACT,WAAW,EACX,WAAW,EACX,eAAe,EACf,SAAS,EACT,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,yBAAyB,EACzB,oBAAoB,EACpB,4BAA4B,EAC5B,6BAA6B,EAC7B,QAAQ,EACR,oBAAoB,GACrB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEzE,eAAO,MAAM,OAAO,UAAU,CAAC"}