@zhanla/sdk-ts 0.3.6 → 0.3.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @zhanla/sdk-ts
2
2
 
3
- `@zhanla/sdk-ts` is the TypeScript SDK for defining bench components in code.
3
+ `@zhanla/sdk-ts` is the TypeScript SDK for defining zhanla components in code.
4
4
 
5
5
  You export component instances from a TypeScript module, then run them with `zhanla` or the bundled `@zhanla/sdk-ts` helper CLI.
6
6
 
package/bin/cli.js CHANGED
@@ -12,7 +12,7 @@
12
12
  import { spawnSync } from "child_process";
13
13
  import { createRequire } from "module";
14
14
 
15
- if (process.env.BENCH_SDK_TS_LOADER_ACTIVE !== "1") {
15
+ if (process.env.ZHANLA_SDK_TS_LOADER_ACTIVE !== "1" && process.env.BENCH_SDK_TS_LOADER_ACTIVE !== "1") {
16
16
  const require = createRequire(import.meta.url);
17
17
  const loaderPath = require.resolve("tsx");
18
18
  const child = spawnSync(
@@ -20,7 +20,7 @@ if (process.env.BENCH_SDK_TS_LOADER_ACTIVE !== "1") {
20
20
  ["--import", loaderPath, new URL(import.meta.url).pathname, ...process.argv.slice(2)],
21
21
  {
22
22
  stdio: "inherit",
23
- env: { ...process.env, BENCH_SDK_TS_LOADER_ACTIVE: "1" },
23
+ env: { ...process.env, ZHANLA_SDK_TS_LOADER_ACTIVE: "1" },
24
24
  },
25
25
  );
26
26
 
@@ -29,14 +29,14 @@ if (process.env.BENCH_SDK_TS_LOADER_ACTIVE !== "1") {
29
29
 
30
30
  const [, , subcommand, ...args] = process.argv;
31
31
 
32
- const INTERNAL_SUBCOMMANDS = ["discover", "run", "eval-only"];
32
+ const INTERNAL_SUBCOMMANDS = ["discover", "run", "eval-only", "version"];
33
33
 
34
34
  if (!subcommand) {
35
35
  console.error("Usage: zhanla-sdk-ts <discover|run|eval-only> <target>");
36
36
  process.exit(1);
37
37
  }
38
38
 
39
- if (INTERNAL_SUBCOMMANDS.includes(subcommand) && process.env.ZHANLA_INTERNAL !== "1") {
39
+ if (INTERNAL_SUBCOMMANDS.includes(subcommand) && !/^[0-9a-f]{64}$/.test(process.env.ZHANLA_INTERNAL ?? "")) {
40
40
  console.error(
41
41
  "Use the `zhanla` CLI for the full experience: https://pypi.org/project/zhanla/"
42
42
  );
package/bin/discover.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * zhanla-sdk-ts discover <file.ts[:ExportName]>
3
+ * zhanla-sdk-ts discover <file.ts[:component-key]>
4
4
  *
5
5
  * Loads a TypeScript module via tsx, walks the transitive closure from a
6
6
  * named root (or all exported roots if no name given), and emits the full
@@ -210,11 +210,20 @@ export function buildDiscoveredManifests({
210
210
  }) {
211
211
  if (symbolName) {
212
212
  const root = allComponents.find(
213
- (c) => symbolByComponent.get(c) === symbolName || c.name === symbolName
213
+ (c) => c.key === symbolName
214
214
  );
215
215
  if (!root) {
216
- const available = allComponents.map((c) => symbolByComponent.get(c) ?? c.name).join(", ");
217
- throw new Error(`Component '${symbolName}' not found in ${filePath}. Available: ${available}`);
216
+ const nameMatches = allComponents.filter(
217
+ (c) => symbolByComponent.get(c) === symbolName || c.name === symbolName
218
+ );
219
+ const available = allComponents.map((c) => c.key).join(", ");
220
+ if (nameMatches.length > 0) {
221
+ const matchingKeys = nameMatches.map((c) => c.key).join(", ");
222
+ throw new Error(
223
+ `Component '${symbolName}' matched a component name/export, but discovery now requires component keys. Use one of: ${matchingKeys}`
224
+ );
225
+ }
226
+ throw new Error(`Component '${symbolName}' not found in ${filePath}. Available keys: ${available}`);
218
227
  }
219
228
  return collectClosureManifests([root], toManifest, filePath, symbolByComponent);
220
229
  }
@@ -2,7 +2,7 @@
2
2
  * In-memory LLM call trace store backed by AsyncLocalStorage.
3
3
  *
4
4
  * The CLI sets a TraceContext before calling a component's runner.
5
- * The bench.wrap() interceptors read the active context and record each LLM call.
5
+ * The zhanla.wrap() interceptors read the active context and record each LLM call.
6
6
  * After execution the CLI flushes the calls and writes them to Supabase.
7
7
  */
8
8
  import { AsyncLocalStorage } from "async_hooks";
@@ -2,7 +2,7 @@
2
2
  * In-memory LLM call trace store backed by AsyncLocalStorage.
3
3
  *
4
4
  * The CLI sets a TraceContext before calling a component's runner.
5
- * The bench.wrap() interceptors read the active context and record each LLM call.
5
+ * The zhanla.wrap() interceptors read the active context and record each LLM call.
6
6
  * After execution the CLI flushes the calls and writes them to Supabase.
7
7
  */
8
8
  import { AsyncLocalStorage } from "async_hooks";
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Core types for the bench TypeScript SDK.
2
+ * Core types for the zhanla TypeScript SDK.
3
3
  * Mirrors the Python SDK's class-based component model.
4
4
  */
5
5
  export type JsonSchemaScalar = {
package/dist/types.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Core types for the bench TypeScript SDK.
2
+ * Core types for the zhanla TypeScript SDK.
3
3
  * Mirrors the Python SDK's class-based component model.
4
4
  */
5
5
  import { parseJsonResponse } from "./json.js";
package/dist/wrap.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * bench.wrap() — observe LLM clients without executing them.
2
+ * zhanla.wrap() — observe LLM clients without executing them.
3
3
  *
4
4
  * Wraps an existing LLM client so every call is recorded in the active
5
- * TraceContext. The underlying client is unchanged; bench only observes.
5
+ * TraceContext. The underlying client is unchanged; zhanla only observes.
6
6
  *
7
7
  * Supported clients:
8
8
  * - Anthropic (from @anthropic-ai/sdk)
@@ -40,7 +40,7 @@ export declare function isGeminiClient(client: unknown): client is {
40
40
  *
41
41
  * @example
42
42
  * import Anthropic from "@anthropic-ai/sdk";
43
- * import bench from "@benchlabs/sdk";
44
- * const client = bench.wrap(new Anthropic());
43
+ * import { wrap } from "@zhanla/sdk-ts";
44
+ * const client = wrap(new Anthropic());
45
45
  */
46
46
  export declare function wrap<T>(client: T): T;
package/dist/wrap.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * bench.wrap() — observe LLM clients without executing them.
2
+ * zhanla.wrap() — observe LLM clients without executing them.
3
3
  *
4
4
  * Wraps an existing LLM client so every call is recorded in the active
5
- * TraceContext. The underlying client is unchanged; bench only observes.
5
+ * TraceContext. The underlying client is unchanged; zhanla only observes.
6
6
  *
7
7
  * Supported clients:
8
8
  * - Anthropic (from @anthropic-ai/sdk)
@@ -11,7 +11,8 @@
11
11
  * - GoogleGenAI (from @google/genai)
12
12
  */
13
13
  import { traceStorage } from "./trace_store.js";
14
- const WRAPPED_CLIENT = Symbol.for("bench.sdk_ts.wrapped_client");
14
+ const WRAPPED_CLIENT = Symbol.for("zhanla.sdk_ts.wrapped_client");
15
+ const WRAPPED_CLIENT_LEGACY = Symbol.for("bench.sdk_ts.wrapped_client");
15
16
  // ---------------------------------------------------------------------------
16
17
  // Serialisation helper
17
18
  // ---------------------------------------------------------------------------
@@ -232,12 +233,15 @@ export function isGeminiClient(client) {
232
233
  *
233
234
  * @example
234
235
  * import Anthropic from "@anthropic-ai/sdk";
235
- * import bench from "@benchlabs/sdk";
236
- * const client = bench.wrap(new Anthropic());
236
+ * import { wrap } from "@zhanla/sdk-ts";
237
+ * const client = wrap(new Anthropic());
237
238
  */
238
239
  export function wrap(client) {
239
- if (client != null && typeof client === "object" && client[WRAPPED_CLIENT] === true) {
240
- return client;
240
+ if (client != null && typeof client === "object") {
241
+ const c = client;
242
+ if (c[WRAPPED_CLIENT] === true || c[WRAPPED_CLIENT_LEGACY] === true) {
243
+ return client;
244
+ }
241
245
  }
242
246
  let wrapped;
243
247
  if (isAnthropicClient(client))
@@ -249,7 +253,7 @@ export function wrap(client) {
249
253
  else if (isGeminiClient(client))
250
254
  wrapped = wrapGemini(client);
251
255
  else {
252
- throw new TypeError(`bench.wrap() does not support ${Object.getPrototypeOf(client)?.constructor?.name ?? typeof client}. ` +
256
+ throw new TypeError(`zhanla.wrap() does not support ${Object.getPrototypeOf(client)?.constructor?.name ?? typeof client}. ` +
253
257
  "Supported clients: Anthropic, OpenAI, OpenRouter (OpenAI client with OpenRouter baseURL), GoogleGenAI.");
254
258
  }
255
259
  if (wrapped != null && typeof wrapped === "object") {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@zhanla/sdk-ts",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "TypeScript SDK for the zhanla CLI — define and run AI components locally",
5
- "homepage": "https://benchmark-black.vercel.app/",
5
+ "homepage": "https://github.com/zhanla-ai",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/zhanla-ai"
@@ -28,7 +28,6 @@
28
28
  "bin"
29
29
  ],
30
30
  "devDependencies": {
31
- "typescript": "^5.4.0",
32
31
  "vitest": "^1.4.0",
33
32
  "@types/node": "^20.0.0"
34
33
  },