@fractalresearch/loop 0.1.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 +61 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +71 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @fractalresearch/loop
|
|
2
|
+
|
|
3
|
+
Fractal Loop SDK — Auto-instrument your AI application for recursive self-improvement.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @fractalresearch/loop
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { initialize } from "@fractalresearch/loop";
|
|
13
|
+
|
|
14
|
+
// Call once at app startup, before any AI calls
|
|
15
|
+
initialize({
|
|
16
|
+
apiKey: process.env.FRACTAL_API_KEY!,
|
|
17
|
+
appName: "my-ai-app",
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
That's it. The SDK automatically instruments OpenAI, Anthropic, Cohere, and other LLM providers. Traces are sent to the Fractal platform where they're analyzed for improvement opportunities.
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
| Option | Type | Default | Description |
|
|
26
|
+
|--------|------|---------|-------------|
|
|
27
|
+
| `apiKey` | string | required | Your Fractal API key (`fr_live_...`) |
|
|
28
|
+
| `baseUrl` | string | `https://fractalresearch.ai` | Fractal platform URL |
|
|
29
|
+
| `appName` | string | `fractal-loop-app` | Your application name |
|
|
30
|
+
| `disableBatch` | boolean | `false` | Disable span batching (for testing) |
|
|
31
|
+
|
|
32
|
+
## How It Works
|
|
33
|
+
|
|
34
|
+
1. **Instrument** — The SDK hooks into your LLM client libraries and captures every call as an OpenTelemetry span
|
|
35
|
+
2. **Collect** — Spans are batched and sent to the Fractal `/api/v1/traces` endpoint
|
|
36
|
+
3. **Analyze** — Fractal uses Claude to analyze trace patterns against your improvement target
|
|
37
|
+
4. **Improve** — Fractal creates GitHub PRs with suggested code changes
|
|
38
|
+
|
|
39
|
+
## Supported Providers
|
|
40
|
+
|
|
41
|
+
- OpenAI
|
|
42
|
+
- Anthropic
|
|
43
|
+
- Cohere
|
|
44
|
+
- Azure OpenAI
|
|
45
|
+
- Amazon Bedrock
|
|
46
|
+
- Google Vertex AI
|
|
47
|
+
- Replicate
|
|
48
|
+
- HuggingFace
|
|
49
|
+
|
|
50
|
+
## Local Development
|
|
51
|
+
|
|
52
|
+
If running Fractal locally:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
initialize({
|
|
56
|
+
apiKey: "your-key",
|
|
57
|
+
baseUrl: "http://localhost:3000",
|
|
58
|
+
appName: "my-app",
|
|
59
|
+
disableBatch: true, // Send spans immediately
|
|
60
|
+
});
|
|
61
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface LoopConfig {
|
|
2
|
+
/** Your Fractal API key (fr_live_...) */
|
|
3
|
+
apiKey: string;
|
|
4
|
+
/** Base URL of the Fractal platform (default: https://fractalresearch.ai) */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Name of your application */
|
|
7
|
+
appName?: string;
|
|
8
|
+
/** Disable batching for testing (default: false) */
|
|
9
|
+
disableBatch?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Initialize the Fractal Loop SDK.
|
|
13
|
+
*
|
|
14
|
+
* Call this once at the entry point of your application, before any
|
|
15
|
+
* AI/LLM calls are made. The SDK auto-instruments OpenAI, Anthropic,
|
|
16
|
+
* Cohere, and other supported providers via Traceloop.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { initialize } from "@fractalresearch/loop";
|
|
21
|
+
*
|
|
22
|
+
* initialize({
|
|
23
|
+
* apiKey: process.env.FRACTAL_API_KEY!,
|
|
24
|
+
* appName: "my-ai-app",
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function initialize(config: LoopConfig): void;
|
|
29
|
+
declare const _default: {
|
|
30
|
+
initialize: typeof initialize;
|
|
31
|
+
};
|
|
32
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.initialize = initialize;
|
|
37
|
+
const traceloop = __importStar(require("@traceloop/node-server-sdk"));
|
|
38
|
+
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
39
|
+
/**
|
|
40
|
+
* Initialize the Fractal Loop SDK.
|
|
41
|
+
*
|
|
42
|
+
* Call this once at the entry point of your application, before any
|
|
43
|
+
* AI/LLM calls are made. The SDK auto-instruments OpenAI, Anthropic,
|
|
44
|
+
* Cohere, and other supported providers via Traceloop.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { initialize } from "@fractalresearch/loop";
|
|
49
|
+
*
|
|
50
|
+
* initialize({
|
|
51
|
+
* apiKey: process.env.FRACTAL_API_KEY!,
|
|
52
|
+
* appName: "my-ai-app",
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function initialize(config) {
|
|
57
|
+
const baseUrl = config.baseUrl || "https://fractalresearch.ai";
|
|
58
|
+
const endpoint = `${baseUrl}/api/v1/traces`;
|
|
59
|
+
const exporter = new exporter_trace_otlp_http_1.OTLPTraceExporter({
|
|
60
|
+
url: endpoint,
|
|
61
|
+
headers: {
|
|
62
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
traceloop.initialize({
|
|
66
|
+
appName: config.appName || "fractal-loop-app",
|
|
67
|
+
disableBatch: config.disableBatch ?? false,
|
|
68
|
+
exporter: exporter,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.default = { initialize };
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fractalresearch/loop",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fractal Loop SDK - Auto-instrument your AI application for recursive improvement",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@traceloop/node-server-sdk": "^0.26.0",
|
|
13
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
|
|
14
|
+
"@opentelemetry/sdk-trace-base": "^1.30.0",
|
|
15
|
+
"@opentelemetry/sdk-trace-node": "^1.30.0",
|
|
16
|
+
"@opentelemetry/resources": "^1.30.0",
|
|
17
|
+
"@opentelemetry/semantic-conventions": "^1.28.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.5.0"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT"
|
|
26
|
+
}
|