@zils/sdk 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +35 -2
- package/dist/index.d.ts +16 -0
- package/dist/index.js +61 -0
- package/package.json +23 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zils contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Zils TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node.js 20+. Typed decisions using the existing Zils API and TypeSafe-compatible
|
|
4
|
+
questions. Install it in your application:
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @zils/sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Set the server's `ZILS_API_KEY`, then use either ESM `import` or CommonJS `require`:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { ZilsClient, choice } from '@zils/sdk';
|
|
14
|
+
|
|
15
|
+
const client = new ZilsClient();
|
|
16
|
+
const result = await client.systemOne({
|
|
17
|
+
state: 'Please refund the duplicate charge.',
|
|
18
|
+
questions: {
|
|
19
|
+
team: choice('Which team?', { billing: 'Payments', support: 'Product help' }),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
console.log(result.answers.team.choice);
|
|
23
|
+
console.log(result.usage.billable_input_tokens);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Explicit `apiKey`, `baseURL`, and `defaultModel` override `ZILS_API_KEY`,
|
|
27
|
+
`ZILS_BASE_URL`, and `ZILS_DEFAULT_MODEL`. Defaults are
|
|
28
|
+
`https://training.zils.ai/decision` and `zils-shared`. Timeout is 60,000ms and
|
|
29
|
+
automatic retries are off; a repeated decision can incur another charge.
|
|
30
|
+
Browser use is disabled to avoid exposing API keys. CLI login files are not read.
|
|
31
|
+
|
|
32
|
+
`client.models.list()` returns model cards. `noul`, `choice`, and `score` preserve
|
|
33
|
+
question-specific answer types. `usage.input_tokens` counts model resources;
|
|
34
|
+
optional `usage.billable_input_tokens` is Zils's logical billing count.
|
|
35
|
+
|
|
36
|
+
[Complete guide](https://github.com/ooo-hq/zils-sdk/blob/main/docs/developer-tools.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TypeSafeClient, type TypeSafeClientConfig, type APIPromise, type Questions, type SystemOneRequest, type SystemOneResult as BaseResult, type RequestOptions, type Usage as BaseUsage } from '@typesafe-ai/sdk';
|
|
2
|
+
export { noul, choice, score, APIError, APIConnectionError, APITimeoutError, APIUserAbortError, AuthenticationError, RateLimitError, TypeSafeError as ZilsError, } from '@typesafe-ai/sdk';
|
|
3
|
+
export type { Question, Questions, SystemOneRequest, RequestOptions, RetryPolicy, ModelCard, NoulQuestion, ChoiceQuestion, ScoreQuestion, NoulResponse, ChoiceResponse, ScoreResponse, JsonValue, EntryType, } from '@typesafe-ai/sdk';
|
|
4
|
+
export interface Usage extends BaseUsage {
|
|
5
|
+
/** Logical billing tokens; absent on older runtimes. input_tokens counts resources. */
|
|
6
|
+
readonly billable_input_tokens?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SystemOneResult<Q extends Questions> extends BaseResult<Q> {
|
|
9
|
+
readonly usage: Usage;
|
|
10
|
+
}
|
|
11
|
+
export type ZilsClientConfig = Omit<TypeSafeClientConfig, 'dangerouslyAllowBrowser'>;
|
|
12
|
+
/** Zils defaults over the compatible TypeSafe client; automatic retries are off. */
|
|
13
|
+
export declare class ZilsClient extends TypeSafeClient {
|
|
14
|
+
constructor(config?: ZilsClientConfig);
|
|
15
|
+
systemOne<const Q extends Questions>(request: SystemOneRequest<Q>, options?: RequestOptions): APIPromise<SystemOneResult<Q>>;
|
|
16
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZilsClient = exports.ZilsError = exports.RateLimitError = exports.AuthenticationError = exports.APIUserAbortError = exports.APITimeoutError = exports.APIConnectionError = exports.APIError = exports.score = exports.choice = exports.noul = void 0;
|
|
4
|
+
const sdk_1 = require("@typesafe-ai/sdk");
|
|
5
|
+
var sdk_2 = require("@typesafe-ai/sdk");
|
|
6
|
+
Object.defineProperty(exports, "noul", { enumerable: true, get: function () { return sdk_2.noul; } });
|
|
7
|
+
Object.defineProperty(exports, "choice", { enumerable: true, get: function () { return sdk_2.choice; } });
|
|
8
|
+
Object.defineProperty(exports, "score", { enumerable: true, get: function () { return sdk_2.score; } });
|
|
9
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return sdk_2.APIError; } });
|
|
10
|
+
Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return sdk_2.APIConnectionError; } });
|
|
11
|
+
Object.defineProperty(exports, "APITimeoutError", { enumerable: true, get: function () { return sdk_2.APITimeoutError; } });
|
|
12
|
+
Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return sdk_2.APIUserAbortError; } });
|
|
13
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return sdk_2.AuthenticationError; } });
|
|
14
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return sdk_2.RateLimitError; } });
|
|
15
|
+
Object.defineProperty(exports, "ZilsError", { enumerable: true, get: function () { return sdk_2.TypeSafeError; } });
|
|
16
|
+
const DEFAULT_BASE_URL = 'https://training.zils.ai/decision';
|
|
17
|
+
function env(name) {
|
|
18
|
+
return typeof process === 'undefined' ? undefined : process.env[name]?.trim() || undefined;
|
|
19
|
+
}
|
|
20
|
+
function baseURL(value) {
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = new URL(value);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new Error('Use a valid HTTPS base URL.');
|
|
27
|
+
}
|
|
28
|
+
const loopback = parsed.hostname === 'localhost' || parsed.hostname === '[::1]' || /^127(?:\.\d{1,3}){3}$/.test(parsed.hostname);
|
|
29
|
+
if ((parsed.protocol !== 'https:' && !(parsed.protocol === 'http:' && loopback)) ||
|
|
30
|
+
parsed.username || parsed.password || parsed.search || parsed.hash || /\s/.test(value) || parsed.port === '0') {
|
|
31
|
+
throw new Error('Use an HTTPS base URL without credentials, query, or fragment; HTTP is allowed only on loopback.');
|
|
32
|
+
}
|
|
33
|
+
return parsed.href.replace(/\/+$/, '');
|
|
34
|
+
}
|
|
35
|
+
/** Zils defaults over the compatible TypeSafe client; automatic retries are off. */
|
|
36
|
+
class ZilsClient extends sdk_1.TypeSafeClient {
|
|
37
|
+
constructor(config = {}) {
|
|
38
|
+
const apiKey = config.apiKey ?? env('ZILS_API_KEY') ?? '';
|
|
39
|
+
if (!/^[\x21-\x7E]+$/.test(apiKey))
|
|
40
|
+
throw new Error('Set ZILS_API_KEY to a nonempty API key without whitespace.');
|
|
41
|
+
const model = config.defaultModel ?? env('ZILS_DEFAULT_MODEL') ?? 'zils-shared';
|
|
42
|
+
if (!model.trim() || model.length > 128)
|
|
43
|
+
throw new Error('Model must contain 1–128 characters.');
|
|
44
|
+
const transport = config.fetch ?? globalThis.fetch;
|
|
45
|
+
super({
|
|
46
|
+
...config, apiKey,
|
|
47
|
+
baseURL: baseURL(config.baseURL ?? env('ZILS_BASE_URL') ?? DEFAULT_BASE_URL),
|
|
48
|
+
defaultModel: model,
|
|
49
|
+
timeout: config.timeout ?? 60_000,
|
|
50
|
+
retry: { ...config.retry, maxRetries: config.retry?.maxRetries ?? 0 },
|
|
51
|
+
logLevel: config.logLevel ?? 'off',
|
|
52
|
+
dangerouslyAllowBrowser: false,
|
|
53
|
+
// Decisions are paid requests: never forward them through an HTTP redirect.
|
|
54
|
+
fetch: (url, init) => transport(url, { ...init, redirect: 'error' }),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
systemOne(request, options) {
|
|
58
|
+
return super.systemOne(request, options);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ZilsClient = ZilsClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zils/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed JavaScript and TypeScript client for Zils decisions",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://zils.ai",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/ooo-hq/zils-sdk.git",
|
|
10
|
+
"directory": "packages/typescript"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" } },
|
|
16
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
17
|
+
"engines": { "node": ">=20" },
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"test": "npm run build && tsc -p tsconfig.test.json && node --test test/*.test.mjs",
|
|
21
|
+
"prepack": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": { "@typesafe-ai/sdk": "0.6.0" },
|
|
24
|
+
"devDependencies": { "typescript": "~5.9.3", "@types/node": "^22.0.0" }
|
|
25
|
+
}
|