@apo-ai/sdk 0.2.2 → 0.3.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.
@@ -1,14 +1,3 @@
1
- type ParameterOverrides = Record<string, unknown>;
2
- interface ClientOptions {
3
- parameterOverrides?: ParameterOverrides;
4
- runEvals?: boolean;
5
- }
6
- interface IngestionEvent {
7
- id: string;
8
- timestamp: Date;
9
- type: "run-create" | "call-create" | "call-update" | "score-create";
10
- body: Record<string, unknown>;
11
- }
12
1
  interface CreateTraceParams {
13
2
  id?: string;
14
3
  project: string;
@@ -88,53 +77,28 @@ interface CreateScoreParams {
88
77
  comment?: string;
89
78
  observationId?: string;
90
79
  }
91
- interface ObserveOptions {
92
- /** Unique ID for this observation (trace or span) */
93
- id?: string;
94
- /** Project name for grouping traces */
80
+
81
+ type AgentTaskTraceContext = TraceRunContext & {
82
+ createSpan: (options: Omit<CreateSpanParams, "project" | "run_id">) => string;
83
+ endSpan: (spanId: string, params?: Omit<EndSpanParams, "id">) => void;
84
+ };
85
+ type AgentTaskTraceOptions = {
86
+ client: {
87
+ traceRun<T>(params: TraceRunOptions, fn: (trace: AgentTaskTraceContext) => Promise<T>): Promise<T>;
88
+ };
95
89
  project?: string;
96
- /** Flow name (alternative to project) */
97
90
  flowName?: string;
98
- /** Step name for spans */
99
- stepName?: string;
100
- /** Observation name (defaults to method name if not provided) */
101
- name?: string;
102
- /** User ID for tracking */
103
- userId?: string;
104
- /** Session ID for session tracking */
105
- sessionId?: string;
106
- /** Environment (e.g., "production", "development") */
91
+ version?: string;
107
92
  environment?: string;
108
- /** External ID for linking to external systems */
109
- externalId?: string;
110
- /** Tags for filtering and grouping */
111
93
  tags?: string[];
112
- /** Metadata for additional context */
113
- metadata?: Record<string, unknown>;
114
- /** Model name (for spans) */
115
- model?: string;
116
- /** Explicit input data (overrides automatic extraction) */
117
- input?: Record<string, unknown>;
118
- /** Messages array (for chat completions) */
119
- messages?: Record<string, unknown>[];
120
- /** Observation type (Langfuse-style) */
121
- observationType?: "GENERATION" | "SPAN" | "TOOL" | "CHAIN" | "RETRIEVER" | "EVALUATOR" | "EMBEDDING" | "GUARDRAIL" | "AGENT";
122
- /** Shorthand for observation type */
123
- as?: "tool" | "retriever" | "chain" | "agent" | "guardrail" | "embedding";
124
- /** Observation level */
125
- level?: "DEBUG" | "DEFAULT" | "WARNING" | "ERROR";
126
- /** Whether to capture output (default: true) */
127
- captureOutput?: boolean;
128
- }
129
- interface ObservationContext {
130
- /** Trace ID (run ID) */
131
- traceId: string;
132
- /** Current span ID */
133
- spanId: string;
134
- /** Flow name */
135
- flowName: string;
136
- /** Project name */
137
- projectName: string;
138
- }
94
+ runMetadata?: Record<string, unknown>;
95
+ /**
96
+ * The Task Run ID this trace should claim. Emitted as the
97
+ * `apo.task.run.id` root-span attribute so the backend projector can
98
+ * atomically link this trace to the task run. Omit for local/programmatic
99
+ * runs that don't have a backend task run.
100
+ */
101
+ taskRunId?: string;
102
+ };
139
103
 
140
- export type { CreateSpanParams as C, EndSpanParams as E, IngestionEvent as I, ObservationContext as O, ParameterOverrides as P, TraceRunContext as T, TraceRunOptions as a, ClientOptions as b, CreateScoreParams as c, CreateTraceParams as d, ObserveOptions as e, TraceEventOptions as f, TraceStepOptions as g };
104
+ export type { AgentTaskTraceContext as A, AgentTaskTraceOptions as a };
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
2
  "name": "@apo-ai/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "TypeScript SDK for testing and observing AI agents with Apo",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
6
  "files": [
9
7
  "dist",
10
8
  "LICENSE",
@@ -24,11 +22,6 @@
24
22
  "url": "https://github.com/samikuikka/apo/issues"
25
23
  },
26
24
  "exports": {
27
- ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js",
30
- "default": "./dist/index.js"
31
- },
32
25
  "./otel": {
33
26
  "types": "./dist/otel/index.d.ts",
34
27
  "import": "./dist/otel/index.js",
@@ -76,8 +69,7 @@
76
69
  "@opentelemetry/exporter-trace-otlp-http": "^0.220.0",
77
70
  "@opentelemetry/resources": "^2.9.0",
78
71
  "@opentelemetry/sdk-trace-base": "^2.9.0",
79
- "@opentelemetry/semantic-conventions": "^1.43.0",
80
- "effect": "^3.19.12"
72
+ "@opentelemetry/semantic-conventions": "^1.43.0"
81
73
  },
82
74
  "scripts": {
83
75
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.type-tests.json",
package/dist/index.d.ts DELETED
@@ -1,95 +0,0 @@
1
- export { b as ClientOptions, c as CreateScoreParams, C as CreateSpanParams, d as CreateTraceParams, E as EndSpanParams, I as IngestionEvent, O as ObservationContext, e as ObserveOptions, P as ParameterOverrides, f as TraceEventOptions, T as TraceRunContext, a as TraceRunOptions, g as TraceStepOptions } from './types-C-nrDEVf.js';
2
- import * as effect_Cause from 'effect/Cause';
3
- import * as effect_Types from 'effect/Types';
4
-
5
- type ClientErrorCode = "VALIDATION" | "HTTP" | "NETWORK" | "TIMEOUT" | "DECODE" | "UNKNOWN";
6
- declare const ClientError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
7
- readonly _tag: "ClientError";
8
- } & Readonly<A>;
9
- declare class ClientError extends ClientError_base<{
10
- code: ClientErrorCode;
11
- message: string;
12
- status?: number;
13
- body?: string;
14
- retryable?: boolean;
15
- cause?: unknown;
16
- }> {
17
- }
18
- declare const ConfigurationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
19
- readonly _tag: "ConfigurationError";
20
- } & Readonly<A>;
21
- declare class ConfigurationError extends ConfigurationError_base<{
22
- message: string;
23
- suggestion?: string;
24
- }> {
25
- }
26
-
27
- /**
28
- * Configuration management for apo SDK.
29
- *
30
- * Centralizes environment variable reading so all wrappers use the same logic.
31
- */
32
- interface EnvConfig {
33
- /** Backend endpoint URL */
34
- endpoint: string;
35
- /** Project name for optimization tracking */
36
- project: string;
37
- /**
38
- * Public identifier for the two-key model. this is the
39
- * ``pk-apo-*`` value, used as the Basic-auth username alongside
40
- * ``secretKey``. It is NOT a usable credential on its own — the SDK
41
- * never reads ``NEXT_PUBLIC_APO_PUBLIC_KEY`` because publishing a public
42
- * identifier in a browser bundle creates a misleading direct-browser
43
- * integration. Server-only.
44
- */
45
- publicKey?: string;
46
- /** Secret key for two-key auth (server-only). */
47
- secretKey?: string;
48
- /** Legacy single-key auth token */
49
- apiKey?: string;
50
- }
51
- /**
52
- * Read optimizer configuration from environment variables.
53
- *
54
- * This function centralizes all environment variable reading for the SDK,
55
- * ensuring consistent behavior across all wrapper functions.
56
- *
57
- * **Environment Variables (in order of priority):**
58
- *
59
- * For `endpoint`:
60
- * - `NEXT_PUBLIC_APO_BACKEND_URL` (Next.js public env var)
61
- * - `APO_BACKEND_URL` (standard env var)
62
- * - Falls back to `http://localhost:8000`
63
- *
64
- * For `project`:
65
- * - `APO_PROJECT` (standard env var)
66
- * - `NEXT_PUBLIC_APO_PROJECT` (Next.js public env var)
67
- * - Falls back to `default-project`
68
- *
69
- * For `publicKey`:
70
- * - `APO_PUBLIC_KEY` (server-side public identifier; paired with
71
- * `APO_SECRET_KEY` to form HTTP Basic credentials). Support for `NEXT_PUBLIC_APO_PUBLIC_KEY` was removed:
72
- * the public identifier alone
73
- * does not authorize ingestion, so publishing it as a browser-safe env
74
- * var is actively misleading.
75
- *
76
- * For `secretKey`:
77
- * - `APO_SECRET_KEY` (server-side only)
78
- *
79
- * For `apiKey` (legacy single-key auth):
80
- * - `APO_API_KEY`
81
- *
82
- * @example
83
- * ```ts
84
- * import { readConfig } from "@apo-ai/sdk";
85
- *
86
- * const config = readConfig();
87
- * console.log(config.endpoint); // "http://localhost:8000" or env value
88
- * console.log(config.project); // "default-project" or env value
89
- * ```
90
- *
91
- * @returns Client configuration from environment
92
- */
93
- declare function readConfig(): EnvConfig;
94
-
95
- export { ClientError, type ClientErrorCode, ConfigurationError, type EnvConfig, readConfig };
package/dist/index.js DELETED
@@ -1,39 +0,0 @@
1
- // Auto-generated by `pnpm --filter @apo-ai/sdk build` (tsup.config.ts).
2
- // Do not edit by hand — edit the src/ originals and rebuild.
3
-
4
- // src/errors.ts
5
- import { Data } from "effect";
6
- var ClientError = class extends Data.TaggedError("ClientError") {
7
- };
8
- var ValidationError = class extends Data.TaggedError("ValidationError") {
9
- };
10
- var NetworkError = class extends Data.TaggedError("NetworkError") {
11
- };
12
- var DecodeError = class extends Data.TaggedError("DecodeError") {
13
- };
14
- var TimeoutError = class extends Data.TaggedError("TimeoutError") {
15
- };
16
- var RegisterParametersError = class extends Data.TaggedError(
17
- "RegisterParametersError"
18
- ) {
19
- };
20
- var ConfigurationError = class extends Data.TaggedError("ConfigurationError") {
21
- };
22
- var RenderParameterError = class extends Data.TaggedError("RenderParameterError") {
23
- };
24
-
25
- // src/config.ts
26
- function readConfig() {
27
- const endpoint = process.env.NEXT_PUBLIC_APO_BACKEND_URL ?? process.env.APO_BACKEND_URL ?? "http://localhost:8000";
28
- const project = process.env.APO_PROJECT ?? process.env.NEXT_PUBLIC_APO_PROJECT ?? "default-project";
29
- const publicKey = process.env.APO_PUBLIC_KEY;
30
- const secretKey = process.env.APO_SECRET_KEY;
31
- const apiKey = process.env.APO_API_KEY;
32
- return { endpoint, project, publicKey, secretKey, apiKey };
33
- }
34
- export {
35
- ClientError,
36
- ConfigurationError,
37
- readConfig
38
- };
39
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/config.ts"],"sourcesContent":["import { Data } from \"effect\";\n\nexport type ClientErrorCode =\n | \"VALIDATION\"\n | \"HTTP\"\n | \"NETWORK\"\n | \"TIMEOUT\"\n | \"DECODE\"\n | \"UNKNOWN\";\n\nexport class ClientError extends Data.TaggedError(\"ClientError\")<{\n code: ClientErrorCode;\n message: string;\n status?: number;\n body?: string;\n retryable?: boolean;\n cause?: unknown;\n}> {}\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{}> {}\n\nexport class NetworkError extends Data.TaggedError(\"NetworkError\")<{\n message: string;\n cause?: unknown;\n}> {}\n\nexport class DecodeError extends Data.TaggedError(\"DecodeError\")<{\n message: string;\n cause?: unknown;\n}> {}\n\nexport class TimeoutError extends Data.TaggedError(\"TimeoutError\")<{\n message: string;\n cause?: unknown;\n}> {}\n\nexport class RegisterParametersError extends Data.TaggedError(\n \"RegisterParametersError\"\n)<{\n status: number;\n body: string;\n}> {}\n\nexport class ConfigurationError extends Data.TaggedError(\"ConfigurationError\")<{\n message: string;\n suggestion?: string;\n}> {}\n\nconst asMessage = (e: unknown): string =>\n e instanceof Error\n ? e.message\n : typeof e === \"string\"\n ? e\n : JSON.stringify(e);\n\nexport const normalizeError = (e: unknown): ClientError => {\n if (e instanceof ValidationError) {\n return new ClientError({\n code: \"VALIDATION\",\n message: \"Invalid parameter definitions (flowName mismatch / missing).\",\n cause: e,\n });\n }\n\n if (e instanceof ConfigurationError) {\n return new ClientError({\n code: \"VALIDATION\",\n message: e.message,\n cause: e,\n });\n }\n\n if (e instanceof RegisterParametersError) {\n return new ClientError({\n code: \"HTTP\",\n message: `Parameter registration failed (HTTP ${e.status}).`,\n status: e.status,\n body: e.body,\n retryable: e.status >= 500 || e.status === 429,\n cause: e,\n });\n }\n\n if (e instanceof NetworkError) {\n return new ClientError({\n code: \"NETWORK\",\n message: e.message,\n retryable: true,\n cause: e,\n });\n }\n\n if (e instanceof DecodeError) {\n return new ClientError({\n code: \"DECODE\",\n message: e.message,\n retryable: false,\n cause: e,\n });\n }\n\n if (e instanceof TimeoutError) {\n return new ClientError({\n code: \"TIMEOUT\",\n message: e.message,\n retryable: true,\n cause: e,\n });\n }\n\n return new ClientError({\n code: \"UNKNOWN\",\n message: asMessage(e) || \"Unknown error.\",\n retryable: false,\n cause: e,\n });\n};\n\nexport class RenderParameterError extends Data.TaggedError(\"RenderParameterError\")<{\n message: string;\n}> {}\n","/**\n * Configuration management for apo SDK.\n *\n * Centralizes environment variable reading so all wrappers use the same logic.\n */\n\nexport interface EnvConfig {\n /** Backend endpoint URL */\n endpoint: string;\n /** Project name for optimization tracking */\n project: string;\n /**\n * Public identifier for the two-key model. this is the\n * ``pk-apo-*`` value, used as the Basic-auth username alongside\n * ``secretKey``. It is NOT a usable credential on its own — the SDK\n * never reads ``NEXT_PUBLIC_APO_PUBLIC_KEY`` because publishing a public\n * identifier in a browser bundle creates a misleading direct-browser\n * integration. Server-only.\n */\n publicKey?: string;\n /** Secret key for two-key auth (server-only). */\n secretKey?: string;\n /** Legacy single-key auth token */\n apiKey?: string;\n}\n\n/**\n * Read optimizer configuration from environment variables.\n *\n * This function centralizes all environment variable reading for the SDK,\n * ensuring consistent behavior across all wrapper functions.\n *\n * **Environment Variables (in order of priority):**\n *\n * For `endpoint`:\n * - `NEXT_PUBLIC_APO_BACKEND_URL` (Next.js public env var)\n * - `APO_BACKEND_URL` (standard env var)\n * - Falls back to `http://localhost:8000`\n *\n * For `project`:\n * - `APO_PROJECT` (standard env var)\n * - `NEXT_PUBLIC_APO_PROJECT` (Next.js public env var)\n * - Falls back to `default-project`\n *\n * For `publicKey`:\n * - `APO_PUBLIC_KEY` (server-side public identifier; paired with\n * `APO_SECRET_KEY` to form HTTP Basic credentials). Support for `NEXT_PUBLIC_APO_PUBLIC_KEY` was removed:\n * the public identifier alone\n * does not authorize ingestion, so publishing it as a browser-safe env\n * var is actively misleading.\n *\n * For `secretKey`:\n * - `APO_SECRET_KEY` (server-side only)\n *\n * For `apiKey` (legacy single-key auth):\n * - `APO_API_KEY`\n *\n * @example\n * ```ts\n * import { readConfig } from \"@apo-ai/sdk\";\n *\n * const config = readConfig();\n * console.log(config.endpoint); // \"http://localhost:8000\" or env value\n * console.log(config.project); // \"default-project\" or env value\n * ```\n *\n * @returns Client configuration from environment\n */\nexport function readConfig(): EnvConfig {\n const endpoint =\n process.env.NEXT_PUBLIC_APO_BACKEND_URL ??\n process.env.APO_BACKEND_URL ??\n \"http://localhost:8000\";\n\n const project =\n process.env.APO_PROJECT ??\n process.env.NEXT_PUBLIC_APO_PROJECT ??\n \"default-project\";\n\n const publicKey = process.env.APO_PUBLIC_KEY;\n\n const secretKey = process.env.APO_SECRET_KEY;\n const apiKey = process.env.APO_API_KEY;\n\n return { endpoint, project, publicKey, secretKey, apiKey };\n}\n"],"mappings":";;;;AAAA,SAAS,YAAY;AAUd,IAAM,cAAN,cAA0B,KAAK,YAAY,aAAa,EAO5D;AAAC;AAEG,IAAM,kBAAN,cAA8B,KAAK,YAAY,iBAAiB,EAAM;AAAC;AAEvE,IAAM,eAAN,cAA2B,KAAK,YAAY,cAAc,EAG9D;AAAC;AAEG,IAAM,cAAN,cAA0B,KAAK,YAAY,aAAa,EAG5D;AAAC;AAEG,IAAM,eAAN,cAA2B,KAAK,YAAY,cAAc,EAG9D;AAAC;AAEG,IAAM,0BAAN,cAAsC,KAAK;AAAA,EAChD;AACF,EAGG;AAAC;AAEG,IAAM,qBAAN,cAAiC,KAAK,YAAY,oBAAoB,EAG1E;AAAC;AAwEG,IAAM,uBAAN,cAAmC,KAAK,YAAY,sBAAsB,EAE9E;AAAC;;;ACpDG,SAAS,aAAwB;AACtC,QAAM,WACJ,QAAQ,IAAI,+BACZ,QAAQ,IAAI,mBACZ;AAEF,QAAM,UACJ,QAAQ,IAAI,eACZ,QAAQ,IAAI,2BACZ;AAEF,QAAM,YAAY,QAAQ,IAAI;AAE9B,QAAM,YAAY,QAAQ,IAAI;AAC9B,QAAM,SAAS,QAAQ,IAAI;AAE3B,SAAO,EAAE,UAAU,SAAS,WAAW,WAAW,OAAO;AAC3D;","names":[]}
@@ -1,26 +0,0 @@
1
- import { T as TraceRunContext, C as CreateSpanParams, E as EndSpanParams, a as TraceRunOptions } from './types-C-nrDEVf.js';
2
-
3
- type AgentTaskTraceContext = TraceRunContext & {
4
- createSpan: (options: Omit<CreateSpanParams, "project" | "run_id">) => string;
5
- endSpan: (spanId: string, params?: Omit<EndSpanParams, "id">) => void;
6
- };
7
- type AgentTaskTraceOptions = {
8
- client: {
9
- traceRun<T>(params: TraceRunOptions, fn: (trace: AgentTaskTraceContext) => Promise<T>): Promise<T>;
10
- };
11
- project?: string;
12
- flowName?: string;
13
- version?: string;
14
- environment?: string;
15
- tags?: string[];
16
- runMetadata?: Record<string, unknown>;
17
- /**
18
- * The Task Run ID this trace should claim. Emitted as the
19
- * `apo.task.run.id` root-span attribute so the backend projector can
20
- * atomically link this trace to the task run. Omit for local/programmatic
21
- * runs that don't have a backend task run.
22
- */
23
- taskRunId?: string;
24
- };
25
-
26
- export type { AgentTaskTraceContext as A, AgentTaskTraceOptions as a };