@zenadmin-ai/sdk 0.3.0 → 0.3.2
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/dist/auth.d.ts +5 -0
- package/dist/client.d.ts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.js +15 -3
- package/dist/types.d.ts +22 -22
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export interface ResolvedCredentials {
|
|
|
8
8
|
source: "option" | "environment" | "file" | null;
|
|
9
9
|
/** The credentials file is readable by other users. */
|
|
10
10
|
insecureFile: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Set when a saved token was not used because it was saved for another API URL (this one): the
|
|
13
|
+
* token is never sent anywhere else.
|
|
14
|
+
*/
|
|
15
|
+
savedTokenUrl?: string;
|
|
11
16
|
}
|
|
12
17
|
/** Only http(s) origins; the agent API path is added by the client. */
|
|
13
18
|
export declare function normaliseApiUrl(value: string): string;
|
package/dist/client.d.ts
CHANGED
package/dist/errors.d.ts
CHANGED
|
@@ -48,6 +48,6 @@ export declare class NetworkError extends ZenAdminError {
|
|
|
48
48
|
}
|
|
49
49
|
/** No token was configured. */
|
|
50
50
|
export declare class NotSignedInError extends ZenAdminError {
|
|
51
|
-
constructor();
|
|
51
|
+
constructor(message?: string);
|
|
52
52
|
}
|
|
53
53
|
export declare function errorFromResponse(status: number, body: unknown, requestId: string | null, retryAfter: string | null): ZenAdminError;
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,15 @@ async function resolveCredentials(options = {}, env = process.env) {
|
|
|
45
45
|
return { token: env.ZENADMIN_TOKEN, apiUrl, source: "environment", insecureFile: false };
|
|
46
46
|
}
|
|
47
47
|
if (stored.creds) {
|
|
48
|
+
let savedFor;
|
|
49
|
+
try {
|
|
50
|
+
savedFor = normaliseApiUrl(stored.creds.api_url || DEFAULT_API_URL);
|
|
51
|
+
} catch {
|
|
52
|
+
savedFor = String(stored.creds.api_url);
|
|
53
|
+
}
|
|
54
|
+
if (savedFor !== apiUrl) {
|
|
55
|
+
return { token: null, apiUrl, source: null, insecureFile: stored.insecure, savedTokenUrl: savedFor };
|
|
56
|
+
}
|
|
48
57
|
return { token: stored.creds.token, apiUrl, source: "file", insecureFile: stored.insecure };
|
|
49
58
|
}
|
|
50
59
|
return { token: null, apiUrl, source: null, insecureFile: false };
|
|
@@ -160,10 +169,10 @@ class NetworkError extends ZenAdminError {
|
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
class NotSignedInError extends ZenAdminError {
|
|
163
|
-
constructor() {
|
|
172
|
+
constructor(message) {
|
|
164
173
|
super({
|
|
165
174
|
code: "NOT_SIGNED_IN",
|
|
166
|
-
message: "No ZenAdmin token. Create one in ZenAdmin (Zen AI > Access tokens), then run `zen login` or set ZENADMIN_TOKEN.",
|
|
175
|
+
message: message ?? "No ZenAdmin token. Create one in ZenAdmin (Zen AI > Access tokens), then run `zen login` or set ZENADMIN_TOKEN.",
|
|
167
176
|
status: 0
|
|
168
177
|
});
|
|
169
178
|
this.name = "NotSignedInError";
|
|
@@ -273,7 +282,7 @@ var isReusable = (operation) => !isSettled(operation) || operation.status === "u
|
|
|
273
282
|
var ReadResultSchema = z.record(z.string(), z.unknown());
|
|
274
283
|
|
|
275
284
|
// packages/sdk/src/client.ts
|
|
276
|
-
var SDK_VERSION = "0.3.
|
|
285
|
+
var SDK_VERSION = "0.3.2";
|
|
277
286
|
var REQUEST_ID = /^[A-Za-z0-9_-]{8,64}$/;
|
|
278
287
|
var RETRY_STATUSES = new Set([429, 502, 503, 504]);
|
|
279
288
|
var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -329,6 +338,9 @@ class ZenAdmin {
|
|
|
329
338
|
}
|
|
330
339
|
static async fromEnvironment(options = {}, env = process.env) {
|
|
331
340
|
const creds = await resolveCredentials({ token: options.token, apiUrl: options.apiUrl }, env);
|
|
341
|
+
if (!creds.token && creds.savedTokenUrl) {
|
|
342
|
+
throw new NotSignedInError(`The token saved by \`zen login\` is for ${creds.savedTokenUrl}, so it is not sent to ${creds.apiUrl}. ` + `Run \`zen login --api-url ${creds.apiUrl}\` to sign in there, or set ZENADMIN_TOKEN.`);
|
|
343
|
+
}
|
|
332
344
|
if (!creds.token)
|
|
333
345
|
throw new NotSignedInError;
|
|
334
346
|
return new ZenAdmin({ ...options, token: creds.token, apiUrl: creds.apiUrl });
|
package/dist/types.d.ts
CHANGED
|
@@ -4,29 +4,29 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
export declare const ChannelSchema: z.ZodEnum<{
|
|
7
|
+
cli: "cli";
|
|
7
8
|
console: "console";
|
|
8
9
|
mcp: "mcp";
|
|
9
|
-
cli: "cli";
|
|
10
10
|
}>;
|
|
11
11
|
export declare const WhoAmISchema: z.ZodObject<{
|
|
12
12
|
company_id: z.ZodString;
|
|
13
13
|
company_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
14
|
user_id: z.ZodString;
|
|
15
15
|
channel: z.ZodEnum<{
|
|
16
|
+
cli: "cli";
|
|
16
17
|
console: "console";
|
|
17
18
|
mcp: "mcp";
|
|
18
|
-
cli: "cli";
|
|
19
19
|
}>;
|
|
20
20
|
token: z.ZodNullable<z.ZodObject<{
|
|
21
21
|
id: z.ZodString;
|
|
22
22
|
kind: z.ZodEnum<{
|
|
23
|
-
personal: "personal";
|
|
24
23
|
automation: "automation";
|
|
25
24
|
connection: "connection";
|
|
25
|
+
personal: "personal";
|
|
26
26
|
}>;
|
|
27
27
|
scopes: z.ZodArray<z.ZodEnum<{
|
|
28
|
-
read: "read";
|
|
29
28
|
propose: "propose";
|
|
29
|
+
read: "read";
|
|
30
30
|
}>>;
|
|
31
31
|
expires_at: z.ZodString;
|
|
32
32
|
}, z.core.$strip>>;
|
|
@@ -34,10 +34,10 @@ export declare const WhoAmISchema: z.ZodObject<{
|
|
|
34
34
|
}, z.core.$strip>;
|
|
35
35
|
export type WhoAmI = z.infer<typeof WhoAmISchema>;
|
|
36
36
|
export declare const ImpactSchema: z.ZodEnum<{
|
|
37
|
-
|
|
37
|
+
high: "high";
|
|
38
38
|
low: "low";
|
|
39
39
|
medium: "medium";
|
|
40
|
-
|
|
40
|
+
none: "none";
|
|
41
41
|
}>;
|
|
42
42
|
/** One tool the caller can use now. Every tool is classified: read or write, impact, scope. */
|
|
43
43
|
export declare const ToolSchema: z.ZodObject<{
|
|
@@ -51,14 +51,14 @@ export declare const ToolSchema: z.ZodObject<{
|
|
|
51
51
|
module: z.ZodString;
|
|
52
52
|
requires_approval: z.ZodBoolean;
|
|
53
53
|
impact: z.ZodEnum<{
|
|
54
|
-
|
|
54
|
+
high: "high";
|
|
55
55
|
low: "low";
|
|
56
56
|
medium: "medium";
|
|
57
|
-
|
|
57
|
+
none: "none";
|
|
58
58
|
}>;
|
|
59
59
|
scope: z.ZodEnum<{
|
|
60
|
-
read: "read";
|
|
61
60
|
propose: "propose";
|
|
61
|
+
read: "read";
|
|
62
62
|
}>;
|
|
63
63
|
input_schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
64
64
|
}, z.core.$strip>;
|
|
@@ -75,39 +75,39 @@ export declare const ToolListSchema: z.ZodObject<{
|
|
|
75
75
|
module: z.ZodString;
|
|
76
76
|
requires_approval: z.ZodBoolean;
|
|
77
77
|
impact: z.ZodEnum<{
|
|
78
|
-
|
|
78
|
+
high: "high";
|
|
79
79
|
low: "low";
|
|
80
80
|
medium: "medium";
|
|
81
|
-
|
|
81
|
+
none: "none";
|
|
82
82
|
}>;
|
|
83
83
|
scope: z.ZodEnum<{
|
|
84
|
-
read: "read";
|
|
85
84
|
propose: "propose";
|
|
85
|
+
read: "read";
|
|
86
86
|
}>;
|
|
87
87
|
input_schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
88
88
|
}, z.core.$strip>>;
|
|
89
89
|
}, z.core.$strip>;
|
|
90
90
|
export declare const OperationStatusSchema: z.ZodEnum<{
|
|
91
|
-
|
|
91
|
+
cancelled: "cancelled";
|
|
92
|
+
expired: "expired";
|
|
93
|
+
failed: "failed";
|
|
92
94
|
pending_approval: "pending_approval";
|
|
93
95
|
running: "running";
|
|
94
96
|
succeeded: "succeeded";
|
|
95
|
-
|
|
96
|
-
cancelled: "cancelled";
|
|
97
|
-
expired: "expired";
|
|
97
|
+
unknown: "unknown";
|
|
98
98
|
}>;
|
|
99
99
|
export type OperationStatus = z.infer<typeof OperationStatusSchema>;
|
|
100
100
|
export declare const OperationSchema: z.ZodObject<{
|
|
101
101
|
id: z.ZodString;
|
|
102
102
|
action: z.ZodString;
|
|
103
103
|
status: z.ZodEnum<{
|
|
104
|
-
|
|
104
|
+
cancelled: "cancelled";
|
|
105
|
+
expired: "expired";
|
|
106
|
+
failed: "failed";
|
|
105
107
|
pending_approval: "pending_approval";
|
|
106
108
|
running: "running";
|
|
107
109
|
succeeded: "succeeded";
|
|
108
|
-
|
|
109
|
-
cancelled: "cancelled";
|
|
110
|
-
expired: "expired";
|
|
110
|
+
unknown: "unknown";
|
|
111
111
|
}>;
|
|
112
112
|
payload_hash: z.ZodString;
|
|
113
113
|
title: z.ZodString;
|
|
@@ -122,9 +122,9 @@ export declare const OperationSchema: z.ZodObject<{
|
|
|
122
122
|
href: z.ZodString;
|
|
123
123
|
}, z.core.$strip>>;
|
|
124
124
|
impact: z.ZodEnum<{
|
|
125
|
+
high: "high";
|
|
125
126
|
low: "low";
|
|
126
127
|
medium: "medium";
|
|
127
|
-
high: "high";
|
|
128
128
|
}>;
|
|
129
129
|
expires_at: z.ZodString;
|
|
130
130
|
result: z.ZodNullable<z.ZodObject<{
|
|
@@ -143,9 +143,9 @@ export declare const OperationSchema: z.ZodObject<{
|
|
|
143
143
|
message: z.ZodString;
|
|
144
144
|
}, z.core.$strip>>;
|
|
145
145
|
channel: z.ZodOptional<z.ZodEnum<{
|
|
146
|
+
cli: "cli";
|
|
146
147
|
console: "console";
|
|
147
148
|
mcp: "mcp";
|
|
148
|
-
cli: "cli";
|
|
149
149
|
}>>;
|
|
150
150
|
approval_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
151
151
|
}, z.core.$strip>;
|