histeeria 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 ADDED
@@ -0,0 +1,79 @@
1
+ # Histeeria — TypeScript / Node SDK
2
+
3
+ Observe and score your AI agent's judgement. Wrap any LLM call, send the
4
+ decision, and Histeeria evaluates it asynchronously.
5
+
6
+ - **Zero latency** — `observe()` never blocks; sends run in the background.
7
+ - **Zero dependencies** — uses the platform `fetch` (Node 18+, browsers, edge).
8
+ - **Failure silent** — transport errors are swallowed; your agent keeps running.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install histeeria
14
+ ```
15
+
16
+ ## Quickstart
17
+
18
+ ```typescript
19
+ import { Histeeria } from "histeeria";
20
+
21
+ const h = new Histeeria({ apiKey: "hst_live_xxxx" }); // or set HISTEERIA_API_KEY
22
+
23
+ const response = await yourLLMCall(messages);
24
+
25
+ h.observe({
26
+ input: messages,
27
+ output: response,
28
+ agentId: "agent_001",
29
+ sessionId: "sess_abc",
30
+ domain: "customer_support",
31
+ });
32
+ ```
33
+
34
+ `observe()` returns immediately. In short-lived processes (serverless, scripts),
35
+ call `await h.flush()` before exit to ensure delivery.
36
+
37
+ ## Options
38
+
39
+ | Option | Env var | Default |
40
+ | ----------- | --------------------- | --------------------------- |
41
+ | `apiKey` | `HISTEERIA_API_KEY` | — |
42
+ | `baseUrl` | `HISTEERIA_BASE_URL` | `https://api.histeeria.com` |
43
+ | `timeoutMs` | — | `5000` |
44
+ | `enabled` | — | `true` |
45
+ | `debug` | — | `false` |
46
+
47
+ ## Advanced usage
48
+
49
+ ```typescript
50
+ h.observe({
51
+ input: messages,
52
+ output: response,
53
+ agentId: "agent_001",
54
+ sessionId: "sess_abc",
55
+ domain: "customer_support",
56
+ inputTokens: 1240,
57
+ outputTokens: 340,
58
+ metadata: { userId: "usr_123", channel: "web", resolved: true },
59
+ });
60
+ ```
61
+
62
+ ## Multi-step agents (tracing)
63
+
64
+ ```typescript
65
+ const trace = h.trace({ agentId: "agent_001", sessionId: "sess_abc" });
66
+
67
+ const step1 = await yourLLMCall(messages);
68
+ trace.step("research", { input: messages, output: step1 });
69
+
70
+ const step2 = await yourLLMCall([...step1, ...followup]);
71
+ trace.step("response", { input: step1, output: step2 });
72
+
73
+ trace.complete({ finalOutput: step2, resolved: true });
74
+ await h.flush();
75
+ ```
76
+
77
+ ## License
78
+
79
+ Apache-2.0
package/dist/index.cjs ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Histeeria: () => Histeeria,
24
+ Trace: () => Trace,
25
+ VERSION: () => VERSION,
26
+ default: () => index_default
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var VERSION = "0.1.0";
30
+ var DEFAULT_BASE_URL = "https://api.histeeria.com";
31
+ function resolveEnv(key) {
32
+ if (typeof process !== "undefined" && process.env) {
33
+ return process.env[key];
34
+ }
35
+ return void 0;
36
+ }
37
+ function asString(value) {
38
+ if (typeof value === "string") return value;
39
+ try {
40
+ return JSON.stringify(value);
41
+ } catch {
42
+ return String(value);
43
+ }
44
+ }
45
+ var Trace = class {
46
+ constructor(client, options) {
47
+ this.client = client;
48
+ this.options = options;
49
+ this.steps = [];
50
+ this.completed = false;
51
+ }
52
+ step(name, io = {}) {
53
+ this.steps.push({ name, input: io.input, output: io.output });
54
+ return this;
55
+ }
56
+ complete(opts = {}) {
57
+ if (this.completed) return;
58
+ this.completed = true;
59
+ const metadata = {
60
+ ...this.options.metadata ?? {},
61
+ ...opts.metadata ?? {},
62
+ steps: this.steps
63
+ };
64
+ if (opts.resolved !== void 0) metadata.resolved = opts.resolved;
65
+ const finalOutput = opts.finalOutput !== void 0 ? opts.finalOutput : this.steps.length ? this.steps[this.steps.length - 1].output : "";
66
+ this.client.observe({
67
+ input: { steps: this.steps },
68
+ output: finalOutput ?? "",
69
+ agentId: this.options.agentId,
70
+ sessionId: this.options.sessionId,
71
+ domain: this.options.domain,
72
+ metadata
73
+ });
74
+ }
75
+ };
76
+ var Histeeria = class {
77
+ constructor(options = {}) {
78
+ this.pending = /* @__PURE__ */ new Set();
79
+ this.apiKey = options.apiKey ?? resolveEnv("HISTEERIA_API_KEY") ?? "";
80
+ this.baseUrl = (options.baseUrl ?? resolveEnv("HISTEERIA_BASE_URL") ?? DEFAULT_BASE_URL).replace(
81
+ /\/+$/,
82
+ ""
83
+ );
84
+ this.timeoutMs = options.timeoutMs ?? 5e3;
85
+ this.debug = options.debug ?? false;
86
+ this.enabled = (options.enabled ?? true) && Boolean(this.apiKey);
87
+ if (!this.apiKey && (options.enabled ?? true) && this.debug) {
88
+ console.warn("[histeeria] no API key provided; observations will be dropped.");
89
+ }
90
+ }
91
+ /** Record one agent decision. Returns immediately (fire and forget). */
92
+ observe(params) {
93
+ if (!this.enabled) return;
94
+ const payload = {
95
+ agent_id: params.agentId ?? null,
96
+ session_id: params.sessionId ?? null,
97
+ domain: params.domain ?? null,
98
+ input: params.input,
99
+ output: asString(params.output),
100
+ metadata: params.metadata ?? null,
101
+ input_tokens: params.inputTokens ?? null,
102
+ output_tokens: params.outputTokens ?? null,
103
+ sdk_version: VERSION
104
+ };
105
+ const task = this.send(payload).catch((err) => {
106
+ if (this.debug) console.warn("[histeeria] ingest error:", err);
107
+ });
108
+ this.pending.add(task);
109
+ void task.finally(() => this.pending.delete(task));
110
+ }
111
+ trace(options = {}) {
112
+ return new Trace(this, options);
113
+ }
114
+ /** Await all in-flight sends. Call before a short-lived process exits. */
115
+ async flush() {
116
+ await Promise.allSettled(Array.from(this.pending));
117
+ }
118
+ async send(payload) {
119
+ if (typeof fetch !== "function") {
120
+ if (this.debug) console.warn("[histeeria] global fetch unavailable; skipping send.");
121
+ return;
122
+ }
123
+ const controller = new AbortController();
124
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
125
+ try {
126
+ const res = await fetch(`${this.baseUrl}/v1/ingest`, {
127
+ method: "POST",
128
+ headers: {
129
+ "Content-Type": "application/json",
130
+ Authorization: `Bearer ${this.apiKey}`,
131
+ "User-Agent": `histeeria-js/${VERSION}`
132
+ },
133
+ body: JSON.stringify(payload),
134
+ signal: controller.signal
135
+ });
136
+ if (!res.ok && this.debug) {
137
+ const body = await res.text().catch(() => "");
138
+ console.warn(`[histeeria] ingest failed ${res.status}: ${body}`);
139
+ }
140
+ } finally {
141
+ clearTimeout(timer);
142
+ }
143
+ }
144
+ };
145
+ var index_default = Histeeria;
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ Histeeria,
149
+ Trace,
150
+ VERSION
151
+ });
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Histeeria — TypeScript/Node SDK.
3
+ *
4
+ * Observe and score your AI agent's judgement.
5
+ * - Zero latency: observe() never blocks; sends happen in the background.
6
+ * - Zero dependencies: uses the platform fetch (Node 18+, browsers, edge).
7
+ * - Failure silent: transport errors are swallowed; your agent keeps running.
8
+ */
9
+ declare const VERSION = "0.1.0";
10
+ interface HisteeriaOptions {
11
+ apiKey?: string;
12
+ baseUrl?: string;
13
+ /** Per-request timeout in milliseconds. Default 5000. */
14
+ timeoutMs?: number;
15
+ /** Set false to make the SDK a no-op (useful in tests/local). */
16
+ enabled?: boolean;
17
+ /** Log transport errors to console. Default false. */
18
+ debug?: boolean;
19
+ }
20
+ interface ObserveParams {
21
+ input: unknown;
22
+ output: unknown;
23
+ agentId?: string;
24
+ sessionId?: string;
25
+ domain?: string;
26
+ metadata?: Record<string, unknown>;
27
+ inputTokens?: number;
28
+ outputTokens?: number;
29
+ }
30
+ interface TraceOptions {
31
+ agentId?: string;
32
+ sessionId?: string;
33
+ domain?: string;
34
+ metadata?: Record<string, unknown>;
35
+ }
36
+ declare class Trace {
37
+ private readonly client;
38
+ private readonly options;
39
+ private steps;
40
+ private completed;
41
+ constructor(client: Histeeria, options: TraceOptions);
42
+ step(name: string, io?: {
43
+ input?: unknown;
44
+ output?: unknown;
45
+ }): this;
46
+ complete(opts?: {
47
+ finalOutput?: unknown;
48
+ resolved?: boolean;
49
+ metadata?: Record<string, unknown>;
50
+ }): void;
51
+ }
52
+ declare class Histeeria {
53
+ readonly apiKey: string;
54
+ readonly baseUrl: string;
55
+ readonly timeoutMs: number;
56
+ readonly enabled: boolean;
57
+ private readonly debug;
58
+ private readonly pending;
59
+ constructor(options?: HisteeriaOptions);
60
+ /** Record one agent decision. Returns immediately (fire and forget). */
61
+ observe(params: ObserveParams): void;
62
+ trace(options?: TraceOptions): Trace;
63
+ /** Await all in-flight sends. Call before a short-lived process exits. */
64
+ flush(): Promise<void>;
65
+ private send;
66
+ }
67
+
68
+ export { Histeeria, type HisteeriaOptions, type ObserveParams, Trace, type TraceOptions, VERSION, Histeeria as default };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Histeeria — TypeScript/Node SDK.
3
+ *
4
+ * Observe and score your AI agent's judgement.
5
+ * - Zero latency: observe() never blocks; sends happen in the background.
6
+ * - Zero dependencies: uses the platform fetch (Node 18+, browsers, edge).
7
+ * - Failure silent: transport errors are swallowed; your agent keeps running.
8
+ */
9
+ declare const VERSION = "0.1.0";
10
+ interface HisteeriaOptions {
11
+ apiKey?: string;
12
+ baseUrl?: string;
13
+ /** Per-request timeout in milliseconds. Default 5000. */
14
+ timeoutMs?: number;
15
+ /** Set false to make the SDK a no-op (useful in tests/local). */
16
+ enabled?: boolean;
17
+ /** Log transport errors to console. Default false. */
18
+ debug?: boolean;
19
+ }
20
+ interface ObserveParams {
21
+ input: unknown;
22
+ output: unknown;
23
+ agentId?: string;
24
+ sessionId?: string;
25
+ domain?: string;
26
+ metadata?: Record<string, unknown>;
27
+ inputTokens?: number;
28
+ outputTokens?: number;
29
+ }
30
+ interface TraceOptions {
31
+ agentId?: string;
32
+ sessionId?: string;
33
+ domain?: string;
34
+ metadata?: Record<string, unknown>;
35
+ }
36
+ declare class Trace {
37
+ private readonly client;
38
+ private readonly options;
39
+ private steps;
40
+ private completed;
41
+ constructor(client: Histeeria, options: TraceOptions);
42
+ step(name: string, io?: {
43
+ input?: unknown;
44
+ output?: unknown;
45
+ }): this;
46
+ complete(opts?: {
47
+ finalOutput?: unknown;
48
+ resolved?: boolean;
49
+ metadata?: Record<string, unknown>;
50
+ }): void;
51
+ }
52
+ declare class Histeeria {
53
+ readonly apiKey: string;
54
+ readonly baseUrl: string;
55
+ readonly timeoutMs: number;
56
+ readonly enabled: boolean;
57
+ private readonly debug;
58
+ private readonly pending;
59
+ constructor(options?: HisteeriaOptions);
60
+ /** Record one agent decision. Returns immediately (fire and forget). */
61
+ observe(params: ObserveParams): void;
62
+ trace(options?: TraceOptions): Trace;
63
+ /** Await all in-flight sends. Call before a short-lived process exits. */
64
+ flush(): Promise<void>;
65
+ private send;
66
+ }
67
+
68
+ export { Histeeria, type HisteeriaOptions, type ObserveParams, Trace, type TraceOptions, VERSION, Histeeria as default };
package/dist/index.js ADDED
@@ -0,0 +1,124 @@
1
+ // src/index.ts
2
+ var VERSION = "0.1.0";
3
+ var DEFAULT_BASE_URL = "https://api.histeeria.com";
4
+ function resolveEnv(key) {
5
+ if (typeof process !== "undefined" && process.env) {
6
+ return process.env[key];
7
+ }
8
+ return void 0;
9
+ }
10
+ function asString(value) {
11
+ if (typeof value === "string") return value;
12
+ try {
13
+ return JSON.stringify(value);
14
+ } catch {
15
+ return String(value);
16
+ }
17
+ }
18
+ var Trace = class {
19
+ constructor(client, options) {
20
+ this.client = client;
21
+ this.options = options;
22
+ this.steps = [];
23
+ this.completed = false;
24
+ }
25
+ step(name, io = {}) {
26
+ this.steps.push({ name, input: io.input, output: io.output });
27
+ return this;
28
+ }
29
+ complete(opts = {}) {
30
+ if (this.completed) return;
31
+ this.completed = true;
32
+ const metadata = {
33
+ ...this.options.metadata ?? {},
34
+ ...opts.metadata ?? {},
35
+ steps: this.steps
36
+ };
37
+ if (opts.resolved !== void 0) metadata.resolved = opts.resolved;
38
+ const finalOutput = opts.finalOutput !== void 0 ? opts.finalOutput : this.steps.length ? this.steps[this.steps.length - 1].output : "";
39
+ this.client.observe({
40
+ input: { steps: this.steps },
41
+ output: finalOutput ?? "",
42
+ agentId: this.options.agentId,
43
+ sessionId: this.options.sessionId,
44
+ domain: this.options.domain,
45
+ metadata
46
+ });
47
+ }
48
+ };
49
+ var Histeeria = class {
50
+ constructor(options = {}) {
51
+ this.pending = /* @__PURE__ */ new Set();
52
+ this.apiKey = options.apiKey ?? resolveEnv("HISTEERIA_API_KEY") ?? "";
53
+ this.baseUrl = (options.baseUrl ?? resolveEnv("HISTEERIA_BASE_URL") ?? DEFAULT_BASE_URL).replace(
54
+ /\/+$/,
55
+ ""
56
+ );
57
+ this.timeoutMs = options.timeoutMs ?? 5e3;
58
+ this.debug = options.debug ?? false;
59
+ this.enabled = (options.enabled ?? true) && Boolean(this.apiKey);
60
+ if (!this.apiKey && (options.enabled ?? true) && this.debug) {
61
+ console.warn("[histeeria] no API key provided; observations will be dropped.");
62
+ }
63
+ }
64
+ /** Record one agent decision. Returns immediately (fire and forget). */
65
+ observe(params) {
66
+ if (!this.enabled) return;
67
+ const payload = {
68
+ agent_id: params.agentId ?? null,
69
+ session_id: params.sessionId ?? null,
70
+ domain: params.domain ?? null,
71
+ input: params.input,
72
+ output: asString(params.output),
73
+ metadata: params.metadata ?? null,
74
+ input_tokens: params.inputTokens ?? null,
75
+ output_tokens: params.outputTokens ?? null,
76
+ sdk_version: VERSION
77
+ };
78
+ const task = this.send(payload).catch((err) => {
79
+ if (this.debug) console.warn("[histeeria] ingest error:", err);
80
+ });
81
+ this.pending.add(task);
82
+ void task.finally(() => this.pending.delete(task));
83
+ }
84
+ trace(options = {}) {
85
+ return new Trace(this, options);
86
+ }
87
+ /** Await all in-flight sends. Call before a short-lived process exits. */
88
+ async flush() {
89
+ await Promise.allSettled(Array.from(this.pending));
90
+ }
91
+ async send(payload) {
92
+ if (typeof fetch !== "function") {
93
+ if (this.debug) console.warn("[histeeria] global fetch unavailable; skipping send.");
94
+ return;
95
+ }
96
+ const controller = new AbortController();
97
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
98
+ try {
99
+ const res = await fetch(`${this.baseUrl}/v1/ingest`, {
100
+ method: "POST",
101
+ headers: {
102
+ "Content-Type": "application/json",
103
+ Authorization: `Bearer ${this.apiKey}`,
104
+ "User-Agent": `histeeria-js/${VERSION}`
105
+ },
106
+ body: JSON.stringify(payload),
107
+ signal: controller.signal
108
+ });
109
+ if (!res.ok && this.debug) {
110
+ const body = await res.text().catch(() => "");
111
+ console.warn(`[histeeria] ingest failed ${res.status}: ${body}`);
112
+ }
113
+ } finally {
114
+ clearTimeout(timer);
115
+ }
116
+ }
117
+ };
118
+ var index_default = Histeeria;
119
+ export {
120
+ Histeeria,
121
+ Trace,
122
+ VERSION,
123
+ index_default as default
124
+ };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "histeeria",
3
+ "version": "0.1.0",
4
+ "description": "Histeeria SDK — observe and score your AI agent's judgement. Zero latency, zero dependencies.",
5
+ "license": "Apache-2.0",
6
+ "author": "Histeeria",
7
+ "homepage": "https://histeeria.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/histeeria/histeeria-sdk.git",
11
+ "directory": "typescript"
12
+ },
13
+ "keywords": [
14
+ "llm",
15
+ "agents",
16
+ "observability",
17
+ "evaluation",
18
+ "ai",
19
+ "monitoring"
20
+ ],
21
+ "type": "module",
22
+ "main": "./dist/index.cjs",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "require": "./dist/index.cjs"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "provenance": true
41
+ },
42
+ "scripts": {
43
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
44
+ "typecheck": "tsc --noEmit",
45
+ "test": "node --import tsx --test test/*.test.ts",
46
+ "prepublishOnly": "npm run build"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^20.11.0",
50
+ "tsup": "^8.0.0",
51
+ "tsx": "^4.7.0",
52
+ "typescript": "^5.4.0"
53
+ }
54
+ }