@agentforge-io/sdk-console 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/README.md +150 -2
- package/dist/client.d.ts +43 -0
- package/dist/client.js +58 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.js +93 -0
- package/dist/http.d.ts +70 -0
- package/dist/http.js +288 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +55 -0
- package/dist/resources/agents.d.ts +40 -0
- package/dist/resources/agents.js +67 -0
- package/dist/resources/apps.d.ts +16 -0
- package/dist/resources/apps.js +26 -0
- package/dist/resources/auth.d.ts +29 -0
- package/dist/resources/auth.js +57 -0
- package/dist/resources/connectors.d.ts +25 -0
- package/dist/resources/connectors.js +47 -0
- package/dist/resources/marketplace.d.ts +10 -0
- package/dist/resources/marketplace.js +14 -0
- package/dist/resources/members.d.ts +62 -0
- package/dist/resources/members.js +85 -0
- package/dist/resources/playground.d.ts +22 -0
- package/dist/resources/playground.js +32 -0
- package/dist/resources/teams.d.ts +49 -0
- package/dist/resources/teams.js +78 -0
- package/dist/resources/templates.d.ts +115 -0
- package/dist/resources/templates.js +187 -0
- package/dist/resources/tenants.d.ts +12 -0
- package/dist/resources/tenants.js +25 -0
- package/dist/resources/tools.d.ts +13 -0
- package/dist/resources/tools.js +17 -0
- package/dist/resources/variables.d.ts +28 -0
- package/dist/resources/variables.js +43 -0
- package/dist/token-store.d.ts +23 -0
- package/dist/token-store.js +27 -0
- package/dist/types.d.ts +1009 -0
- package/dist/types.js +19 -0
- package/package.json +44 -4
package/dist/http.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// HTTP core: injectable fetch, bearer auth from a TokenStore, single-flight
|
|
3
|
+
// refresh on 401 + retry once, typed errors. Runs unchanged in React Native,
|
|
4
|
+
// browsers and Node: only `fetch`, `AbortController` and `setTimeout` are used
|
|
5
|
+
// (no Buffer / crypto / fs, and no URLSearchParams: RN's polyfill lacks most methods).
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.HttpCore = void 0;
|
|
8
|
+
exports.buildQuery = buildQuery;
|
|
9
|
+
exports.seg = seg;
|
|
10
|
+
const errors_1 = require("./errors");
|
|
11
|
+
const DEFAULT_TIMEOUT_MS = 30000;
|
|
12
|
+
/** Join a query object: skips null/undefined, arrays become `a,b`. */
|
|
13
|
+
function buildQuery(query) {
|
|
14
|
+
if (!query)
|
|
15
|
+
return '';
|
|
16
|
+
// Hand-built (no URLSearchParams): React Native's polyfill lacks set/get/append.
|
|
17
|
+
const parts = [];
|
|
18
|
+
for (const [key, value] of Object.entries(query)) {
|
|
19
|
+
if (value === undefined || value === null)
|
|
20
|
+
continue;
|
|
21
|
+
let str;
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
if (!value.length)
|
|
24
|
+
continue;
|
|
25
|
+
str = value.join(',');
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
str = String(value);
|
|
29
|
+
}
|
|
30
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(str)}`);
|
|
31
|
+
}
|
|
32
|
+
return parts.length ? `?${parts.join('&')}` : '';
|
|
33
|
+
}
|
|
34
|
+
function seg(value) {
|
|
35
|
+
return encodeURIComponent(value);
|
|
36
|
+
}
|
|
37
|
+
class HttpCore {
|
|
38
|
+
constructor(opts) {
|
|
39
|
+
this.refreshing = null;
|
|
40
|
+
this.signingOut = null;
|
|
41
|
+
/** Bumped whenever the session is replaced or wiped; a refresh that started under an older epoch is stale. */
|
|
42
|
+
this.epoch = 0;
|
|
43
|
+
if (!opts.baseURL)
|
|
44
|
+
throw new Error('baseURL is required');
|
|
45
|
+
if (!opts.tokenStore)
|
|
46
|
+
throw new Error('tokenStore is required');
|
|
47
|
+
this.opts = opts;
|
|
48
|
+
this.baseURL = opts.baseURL.replace(/\/+$/, '');
|
|
49
|
+
this.store = opts.tokenStore;
|
|
50
|
+
}
|
|
51
|
+
/** Authenticated (or `auth: false`) JSON request. Resolves `undefined` on 204 / empty body. */
|
|
52
|
+
async request(method, path, options = {}) {
|
|
53
|
+
return this.send(method, path, options, false, 0);
|
|
54
|
+
}
|
|
55
|
+
/** Persist a session obtained from login / register / invite accept. */
|
|
56
|
+
async setSession(tokens) {
|
|
57
|
+
this.epoch++;
|
|
58
|
+
await this.store.setTokens({ accessToken: tokens.accessToken, refreshToken: tokens.refreshToken });
|
|
59
|
+
}
|
|
60
|
+
/** Invalidate any in-flight refresh without touching the store (call before
|
|
61
|
+
* an auth call that will replace or wipe the session). */
|
|
62
|
+
beginSessionChange() {
|
|
63
|
+
this.epoch++;
|
|
64
|
+
}
|
|
65
|
+
/** Wipe the session without firing `onSignedOut` (explicit logout). */
|
|
66
|
+
async clearSession() {
|
|
67
|
+
this.epoch++;
|
|
68
|
+
await this.store.clear();
|
|
69
|
+
}
|
|
70
|
+
/** Force a refresh now (shares the in-flight one). Throws if it does not succeed. */
|
|
71
|
+
async refreshNow() {
|
|
72
|
+
const result = await this.refreshSingleFlight();
|
|
73
|
+
if (result.outcome === 'ok')
|
|
74
|
+
return result.tokens;
|
|
75
|
+
if (result.outcome === 'rejected')
|
|
76
|
+
await this.signOut('refresh_rejected');
|
|
77
|
+
if (result.outcome === 'stale') {
|
|
78
|
+
// A newer session (or a sign-out) won: hand back the live pair if there is one.
|
|
79
|
+
const accessToken = await this.store.getAccessToken();
|
|
80
|
+
const refreshToken = await this.store.getRefreshToken();
|
|
81
|
+
if (accessToken && refreshToken)
|
|
82
|
+
return { accessToken, refreshToken };
|
|
83
|
+
}
|
|
84
|
+
throw result.error;
|
|
85
|
+
}
|
|
86
|
+
// ─── internals ──────────────────────────────────────────────────────────
|
|
87
|
+
async send(method, path, options, retriedAuth, rateLimitAttempt) {
|
|
88
|
+
const authed = options.auth !== false;
|
|
89
|
+
const tokenAtSend = authed ? await this.store.getAccessToken() : null;
|
|
90
|
+
const res = await this.rawFetch(method, path, options, tokenAtSend);
|
|
91
|
+
const maxRetries = this.opts.maxRateLimitRetries ?? 2;
|
|
92
|
+
if (res.status === 429 && method === 'GET' && rateLimitAttempt < maxRetries) {
|
|
93
|
+
const header = res.headers.get('retry-after');
|
|
94
|
+
const seconds = header ? parseInt(header, 10) : NaN;
|
|
95
|
+
// Clamp so a misconfigured upstream cannot park the UI for minutes.
|
|
96
|
+
const waitMs = Number.isFinite(seconds)
|
|
97
|
+
? Math.min(Math.max(seconds * 1000, 500), 10000)
|
|
98
|
+
: 800 * Math.pow(3, rateLimitAttempt);
|
|
99
|
+
await (this.opts.sleep ?? defaultSleep)(waitMs);
|
|
100
|
+
return this.send(method, path, options, retriedAuth, rateLimitAttempt + 1);
|
|
101
|
+
}
|
|
102
|
+
if (res.status === 401 && authed && !retriedAuth) {
|
|
103
|
+
if (await this.recoverFrom401(tokenAtSend)) {
|
|
104
|
+
return this.send(method, path, options, true, rateLimitAttempt);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (res.status === 204)
|
|
108
|
+
return undefined;
|
|
109
|
+
const text = res.text;
|
|
110
|
+
if (!res.ok)
|
|
111
|
+
throw (0, errors_1.errorFromResponse)(res.status, res.statusText, text);
|
|
112
|
+
if (!text)
|
|
113
|
+
return undefined;
|
|
114
|
+
try {
|
|
115
|
+
return JSON.parse(text);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
throw new errors_1.ApiError({ status: res.status, message: 'Invalid JSON in response', details: text });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** @returns true when the request should be replayed once. */
|
|
122
|
+
async recoverFrom401(tokenAtSend) {
|
|
123
|
+
// The session was replaced while this request was in flight (a new
|
|
124
|
+
// sign-in, or another call already refreshed): replay under the new one.
|
|
125
|
+
const current = await this.store.getAccessToken();
|
|
126
|
+
if (current && current !== tokenAtSend)
|
|
127
|
+
return true;
|
|
128
|
+
const refreshToken = await this.store.getRefreshToken();
|
|
129
|
+
// Never signed in: a plain 401, nothing to tear down.
|
|
130
|
+
if (!tokenAtSend && !refreshToken)
|
|
131
|
+
return false;
|
|
132
|
+
const result = await this.refreshSingleFlight();
|
|
133
|
+
if (result.outcome === 'ok')
|
|
134
|
+
return true;
|
|
135
|
+
if (result.outcome === 'unavailable')
|
|
136
|
+
return false; // keep the session; surface the 401
|
|
137
|
+
if (result.outcome === 'stale') {
|
|
138
|
+
// Signed out meanwhile: no replay. Replace by a new sign-in: replay under it.
|
|
139
|
+
const live = await this.store.getAccessToken();
|
|
140
|
+
return !!live && live !== tokenAtSend;
|
|
141
|
+
}
|
|
142
|
+
// Rejected: lose the race gracefully if a newer sign-in landed meanwhile.
|
|
143
|
+
const latest = await this.store.getAccessToken();
|
|
144
|
+
if (latest && latest !== tokenAtSend)
|
|
145
|
+
return true;
|
|
146
|
+
await this.signOut(refreshToken ? 'refresh_rejected' : 'no_refresh_token');
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
/** Idempotent: waiters of the same failed refresh all land here, but only
|
|
150
|
+
* one tears the session down and fires the callback. */
|
|
151
|
+
signOut(reason) {
|
|
152
|
+
if (this.signingOut)
|
|
153
|
+
return this.signingOut;
|
|
154
|
+
const run = (async () => {
|
|
155
|
+
const hadSession = !!((await this.store.getAccessToken()) || (await this.store.getRefreshToken()));
|
|
156
|
+
await this.store.clear();
|
|
157
|
+
if (hadSession)
|
|
158
|
+
this.opts.onSignedOut?.(reason);
|
|
159
|
+
})().finally(() => {
|
|
160
|
+
this.signingOut = null;
|
|
161
|
+
});
|
|
162
|
+
this.signingOut = run;
|
|
163
|
+
return run;
|
|
164
|
+
}
|
|
165
|
+
/** One /auth/refresh at a time: a burst of 401s awaits the same promise.
|
|
166
|
+
* The refresh token rotates on use, so a second concurrent call would be
|
|
167
|
+
* read as token reuse by the server and revoke the family. */
|
|
168
|
+
refreshSingleFlight() {
|
|
169
|
+
if (this.refreshing)
|
|
170
|
+
return this.refreshing;
|
|
171
|
+
const promise = this.doRefresh().finally(() => {
|
|
172
|
+
this.refreshing = null;
|
|
173
|
+
});
|
|
174
|
+
this.refreshing = promise;
|
|
175
|
+
return promise;
|
|
176
|
+
}
|
|
177
|
+
async doRefresh() {
|
|
178
|
+
const refreshToken = await this.store.getRefreshToken();
|
|
179
|
+
if (!refreshToken) {
|
|
180
|
+
return {
|
|
181
|
+
outcome: 'rejected',
|
|
182
|
+
error: new errors_1.ApiError({ status: 401, message: 'No refresh token', code: 'no_refresh_token' }),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const epoch = this.epoch;
|
|
186
|
+
const stale = () => ({
|
|
187
|
+
outcome: 'stale',
|
|
188
|
+
error: new errors_1.ApiError({ status: 401, message: 'Session changed during refresh', code: 'session_changed' }),
|
|
189
|
+
});
|
|
190
|
+
let res;
|
|
191
|
+
try {
|
|
192
|
+
res = await this.rawFetch('POST', '/auth/refresh', { body: { refreshToken } }, null);
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
// Offline / timeout: the session may still be fine. Do not sign out.
|
|
196
|
+
return this.epoch !== epoch ? stale() : { outcome: 'unavailable', error: err };
|
|
197
|
+
}
|
|
198
|
+
if (this.epoch !== epoch)
|
|
199
|
+
return stale();
|
|
200
|
+
const text = res.text;
|
|
201
|
+
if (!res.ok) {
|
|
202
|
+
const error = (0, errors_1.errorFromResponse)(res.status, res.statusText, text);
|
|
203
|
+
// Only an explicit rejection of the token ends the session. 404/408/410/
|
|
204
|
+
// other 4xx (proxy, tunnel, deploy gaps), 429, 5xx: unavailable.
|
|
205
|
+
const rejected = res.status === 400 || res.status === 401 || res.status === 403;
|
|
206
|
+
return { outcome: rejected ? 'rejected' : 'unavailable', error };
|
|
207
|
+
}
|
|
208
|
+
let parsed;
|
|
209
|
+
try {
|
|
210
|
+
parsed = text ? JSON.parse(text) : undefined;
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
parsed = undefined;
|
|
214
|
+
}
|
|
215
|
+
if (!parsed?.accessToken || !parsed.refreshToken) {
|
|
216
|
+
return {
|
|
217
|
+
outcome: 'unavailable',
|
|
218
|
+
error: new errors_1.ApiError({ status: res.status, message: 'Malformed refresh response' }),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const tokens = { accessToken: parsed.accessToken, refreshToken: parsed.refreshToken };
|
|
222
|
+
if (this.epoch !== epoch)
|
|
223
|
+
return stale();
|
|
224
|
+
await this.store.setTokens(tokens);
|
|
225
|
+
return { outcome: 'ok', tokens };
|
|
226
|
+
}
|
|
227
|
+
async rawFetch(method, path, options, accessToken) {
|
|
228
|
+
const fetchImpl = this.opts.fetch ?? globalThis.fetch;
|
|
229
|
+
if (!fetchImpl)
|
|
230
|
+
throw new Error('No fetch available: pass `fetch` in the client options');
|
|
231
|
+
const headers = { Accept: 'application/json', ...this.opts.defaultHeaders };
|
|
232
|
+
if (options.body !== undefined)
|
|
233
|
+
headers['Content-Type'] = 'application/json';
|
|
234
|
+
if (accessToken)
|
|
235
|
+
headers.Authorization = `Bearer ${accessToken}`;
|
|
236
|
+
Object.assign(headers, options.headers);
|
|
237
|
+
const timeoutMs = this.opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
238
|
+
const controller = timeoutMs > 0 && typeof AbortController !== 'undefined' ? new AbortController() : undefined;
|
|
239
|
+
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : undefined;
|
|
240
|
+
try {
|
|
241
|
+
const res = await fetchImpl(`${this.baseURL}${path}${buildQuery(options.query)}`, {
|
|
242
|
+
method,
|
|
243
|
+
headers,
|
|
244
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
245
|
+
signal: controller?.signal,
|
|
246
|
+
});
|
|
247
|
+
// The deadline also covers the body: a stalled stream must not hang forever.
|
|
248
|
+
const text = res.status === 204 ? '' : await readBody(res, controller?.signal);
|
|
249
|
+
return { status: res.status, statusText: res.statusText, ok: res.ok, headers: res.headers, text };
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
const aborted = controller?.signal.aborted === true;
|
|
253
|
+
throw new errors_1.ApiError({
|
|
254
|
+
status: 0,
|
|
255
|
+
code: aborted ? 'timeout' : 'network_error',
|
|
256
|
+
message: aborted ? `Request timed out after ${timeoutMs}ms` : err instanceof Error ? err.message : 'Network request failed',
|
|
257
|
+
cause: err,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
if (timer)
|
|
262
|
+
clearTimeout(timer);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.HttpCore = HttpCore;
|
|
267
|
+
function defaultSleep(ms) {
|
|
268
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
269
|
+
}
|
|
270
|
+
/** Read the body, rejecting if `signal` aborts first (RN / mocks may not tie the stream to the signal). */
|
|
271
|
+
function readBody(res, signal) {
|
|
272
|
+
const read = res.text().catch(() => '');
|
|
273
|
+
if (!signal)
|
|
274
|
+
return read;
|
|
275
|
+
return new Promise((resolve, reject) => {
|
|
276
|
+
const onAbort = () => reject(new Error('aborted'));
|
|
277
|
+
if (signal.aborted)
|
|
278
|
+
return onAbort();
|
|
279
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
280
|
+
read.then((t) => {
|
|
281
|
+
signal.removeEventListener('abort', onAbort);
|
|
282
|
+
resolve(t);
|
|
283
|
+
}, (e) => {
|
|
284
|
+
signal.removeEventListener('abort', onAbort);
|
|
285
|
+
reject(e);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { ConsoleClient, TenantScope } from './client';
|
|
2
|
+
export { ApiError, isApiError } from './errors';
|
|
3
|
+
export { MemoryTokenStore } from './token-store';
|
|
4
|
+
export type { AuthTokens, MaybePromise, TokenStore } from './token-store';
|
|
5
|
+
export type { ConsoleClientOptions, FetchLike, QueryValue, RequestOptions, SignedOutReason } from './http';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export { AgentsResource, ChatTokensResource } from './resources/agents';
|
|
8
|
+
export { AppsResource } from './resources/apps';
|
|
9
|
+
export { AuthResource } from './resources/auth';
|
|
10
|
+
export { ConnectorsResource } from './resources/connectors';
|
|
11
|
+
export { InvitesResource, MembersResource, PublicInvitesResource } from './resources/members';
|
|
12
|
+
export { MarketplaceResource } from './resources/marketplace';
|
|
13
|
+
export { PlaygroundResource } from './resources/playground';
|
|
14
|
+
export { TeamHumanMembersResource, TeamsResource } from './resources/teams';
|
|
15
|
+
export { TemplatesResource, TenantTemplatesResource } from './resources/templates';
|
|
16
|
+
export { TenantsResource } from './resources/tenants';
|
|
17
|
+
export { ToolsResource } from './resources/tools';
|
|
18
|
+
export { VariablesResource } from './resources/variables';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.VariablesResource = exports.ToolsResource = exports.TenantsResource = exports.TenantTemplatesResource = exports.TemplatesResource = exports.TeamsResource = exports.TeamHumanMembersResource = exports.PlaygroundResource = exports.MarketplaceResource = exports.PublicInvitesResource = exports.MembersResource = exports.InvitesResource = exports.ConnectorsResource = exports.AuthResource = exports.AppsResource = exports.ChatTokensResource = exports.AgentsResource = exports.MemoryTokenStore = exports.isApiError = exports.ApiError = exports.TenantScope = exports.ConsoleClient = void 0;
|
|
18
|
+
var client_1 = require("./client");
|
|
19
|
+
Object.defineProperty(exports, "ConsoleClient", { enumerable: true, get: function () { return client_1.ConsoleClient; } });
|
|
20
|
+
Object.defineProperty(exports, "TenantScope", { enumerable: true, get: function () { return client_1.TenantScope; } });
|
|
21
|
+
var errors_1 = require("./errors");
|
|
22
|
+
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return errors_1.ApiError; } });
|
|
23
|
+
Object.defineProperty(exports, "isApiError", { enumerable: true, get: function () { return errors_1.isApiError; } });
|
|
24
|
+
var token_store_1 = require("./token-store");
|
|
25
|
+
Object.defineProperty(exports, "MemoryTokenStore", { enumerable: true, get: function () { return token_store_1.MemoryTokenStore; } });
|
|
26
|
+
__exportStar(require("./types"), exports);
|
|
27
|
+
var agents_1 = require("./resources/agents");
|
|
28
|
+
Object.defineProperty(exports, "AgentsResource", { enumerable: true, get: function () { return agents_1.AgentsResource; } });
|
|
29
|
+
Object.defineProperty(exports, "ChatTokensResource", { enumerable: true, get: function () { return agents_1.ChatTokensResource; } });
|
|
30
|
+
var apps_1 = require("./resources/apps");
|
|
31
|
+
Object.defineProperty(exports, "AppsResource", { enumerable: true, get: function () { return apps_1.AppsResource; } });
|
|
32
|
+
var auth_1 = require("./resources/auth");
|
|
33
|
+
Object.defineProperty(exports, "AuthResource", { enumerable: true, get: function () { return auth_1.AuthResource; } });
|
|
34
|
+
var connectors_1 = require("./resources/connectors");
|
|
35
|
+
Object.defineProperty(exports, "ConnectorsResource", { enumerable: true, get: function () { return connectors_1.ConnectorsResource; } });
|
|
36
|
+
var members_1 = require("./resources/members");
|
|
37
|
+
Object.defineProperty(exports, "InvitesResource", { enumerable: true, get: function () { return members_1.InvitesResource; } });
|
|
38
|
+
Object.defineProperty(exports, "MembersResource", { enumerable: true, get: function () { return members_1.MembersResource; } });
|
|
39
|
+
Object.defineProperty(exports, "PublicInvitesResource", { enumerable: true, get: function () { return members_1.PublicInvitesResource; } });
|
|
40
|
+
var marketplace_1 = require("./resources/marketplace");
|
|
41
|
+
Object.defineProperty(exports, "MarketplaceResource", { enumerable: true, get: function () { return marketplace_1.MarketplaceResource; } });
|
|
42
|
+
var playground_1 = require("./resources/playground");
|
|
43
|
+
Object.defineProperty(exports, "PlaygroundResource", { enumerable: true, get: function () { return playground_1.PlaygroundResource; } });
|
|
44
|
+
var teams_1 = require("./resources/teams");
|
|
45
|
+
Object.defineProperty(exports, "TeamHumanMembersResource", { enumerable: true, get: function () { return teams_1.TeamHumanMembersResource; } });
|
|
46
|
+
Object.defineProperty(exports, "TeamsResource", { enumerable: true, get: function () { return teams_1.TeamsResource; } });
|
|
47
|
+
var templates_1 = require("./resources/templates");
|
|
48
|
+
Object.defineProperty(exports, "TemplatesResource", { enumerable: true, get: function () { return templates_1.TemplatesResource; } });
|
|
49
|
+
Object.defineProperty(exports, "TenantTemplatesResource", { enumerable: true, get: function () { return templates_1.TenantTemplatesResource; } });
|
|
50
|
+
var tenants_1 = require("./resources/tenants");
|
|
51
|
+
Object.defineProperty(exports, "TenantsResource", { enumerable: true, get: function () { return tenants_1.TenantsResource; } });
|
|
52
|
+
var tools_1 = require("./resources/tools");
|
|
53
|
+
Object.defineProperty(exports, "ToolsResource", { enumerable: true, get: function () { return tools_1.ToolsResource; } });
|
|
54
|
+
var variables_1 = require("./resources/variables");
|
|
55
|
+
Object.defineProperty(exports, "VariablesResource", { enumerable: true, get: function () { return variables_1.VariablesResource; } });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { HttpCore } from '../http';
|
|
2
|
+
import type { Agent, AgentInput, AgentList, AgentParentTeam, ChatToken, ChatTokenInput, ListAgentsInput } from '../types';
|
|
3
|
+
export declare class AgentsResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
private readonly tenantId;
|
|
6
|
+
/** Public chat-widget tokens of an agent. */
|
|
7
|
+
readonly chatTokens: ChatTokensResource;
|
|
8
|
+
constructor(http: HttpCore, tenantId: string);
|
|
9
|
+
private get base();
|
|
10
|
+
/** `GET /admin/tenants/:tenantId/agents` */
|
|
11
|
+
list(input?: ListAgentsInput): Promise<AgentList>;
|
|
12
|
+
/** `POST .../agents` */
|
|
13
|
+
create(input: AgentInput): Promise<Agent>;
|
|
14
|
+
/** `GET .../agents/:agentId` */
|
|
15
|
+
get(agentId: string): Promise<Agent>;
|
|
16
|
+
/** `PATCH .../agents/:agentId` */
|
|
17
|
+
update(agentId: string, patch: Partial<AgentInput>): Promise<Agent>;
|
|
18
|
+
/** `DELETE .../agents/:agentId` (deactivates). */
|
|
19
|
+
delete(agentId: string): Promise<void>;
|
|
20
|
+
/** `GET .../agents/:agentId/parent-team` */
|
|
21
|
+
parentTeam(agentId: string): Promise<AgentParentTeam>;
|
|
22
|
+
}
|
|
23
|
+
export declare class ChatTokensResource {
|
|
24
|
+
private readonly http;
|
|
25
|
+
private readonly tenantId;
|
|
26
|
+
constructor(http: HttpCore, tenantId: string);
|
|
27
|
+
private base;
|
|
28
|
+
/** `GET .../agents/:agentId/chat-tokens` */
|
|
29
|
+
list(agentId: string): Promise<{
|
|
30
|
+
items: ChatToken[];
|
|
31
|
+
}>;
|
|
32
|
+
/** `POST .../agents/:agentId/chat-tokens` */
|
|
33
|
+
create(agentId: string, input: ChatTokenInput): Promise<ChatToken>;
|
|
34
|
+
/** `PATCH .../chat-tokens/:token` */
|
|
35
|
+
update(agentId: string, token: string, patch: Partial<ChatTokenInput> & {
|
|
36
|
+
isActive?: boolean;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
/** `DELETE .../chat-tokens/:token` */
|
|
39
|
+
revoke(agentId: string, token: string): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// agents of one workspace (`forTenant(id).agents`). `delete` deactivates
|
|
3
|
+
// (`isActive: false`); history is kept.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ChatTokensResource = exports.AgentsResource = void 0;
|
|
6
|
+
const http_1 = require("../http");
|
|
7
|
+
class AgentsResource {
|
|
8
|
+
constructor(http, tenantId) {
|
|
9
|
+
this.http = http;
|
|
10
|
+
this.tenantId = tenantId;
|
|
11
|
+
this.chatTokens = new ChatTokensResource(http, tenantId);
|
|
12
|
+
}
|
|
13
|
+
get base() {
|
|
14
|
+
return `/admin/tenants/${(0, http_1.seg)(this.tenantId)}/agents`;
|
|
15
|
+
}
|
|
16
|
+
/** `GET /admin/tenants/:tenantId/agents` */
|
|
17
|
+
async list(input = {}) {
|
|
18
|
+
return this.http.request('GET', this.base, { query: { ...input } });
|
|
19
|
+
}
|
|
20
|
+
/** `POST .../agents` */
|
|
21
|
+
async create(input) {
|
|
22
|
+
return this.http.request('POST', this.base, { body: input });
|
|
23
|
+
}
|
|
24
|
+
/** `GET .../agents/:agentId` */
|
|
25
|
+
async get(agentId) {
|
|
26
|
+
return this.http.request('GET', `${this.base}/${(0, http_1.seg)(agentId)}`);
|
|
27
|
+
}
|
|
28
|
+
/** `PATCH .../agents/:agentId` */
|
|
29
|
+
async update(agentId, patch) {
|
|
30
|
+
return this.http.request('PATCH', `${this.base}/${(0, http_1.seg)(agentId)}`, { body: patch });
|
|
31
|
+
}
|
|
32
|
+
/** `DELETE .../agents/:agentId` (deactivates). */
|
|
33
|
+
async delete(agentId) {
|
|
34
|
+
await this.http.request('DELETE', `${this.base}/${(0, http_1.seg)(agentId)}`);
|
|
35
|
+
}
|
|
36
|
+
/** `GET .../agents/:agentId/parent-team` */
|
|
37
|
+
async parentTeam(agentId) {
|
|
38
|
+
return this.http.request('GET', `${this.base}/${(0, http_1.seg)(agentId)}/parent-team`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.AgentsResource = AgentsResource;
|
|
42
|
+
class ChatTokensResource {
|
|
43
|
+
constructor(http, tenantId) {
|
|
44
|
+
this.http = http;
|
|
45
|
+
this.tenantId = tenantId;
|
|
46
|
+
}
|
|
47
|
+
base(agentId) {
|
|
48
|
+
return `/admin/tenants/${(0, http_1.seg)(this.tenantId)}/agents/${(0, http_1.seg)(agentId)}/chat-tokens`;
|
|
49
|
+
}
|
|
50
|
+
/** `GET .../agents/:agentId/chat-tokens` */
|
|
51
|
+
async list(agentId) {
|
|
52
|
+
return this.http.request('GET', this.base(agentId));
|
|
53
|
+
}
|
|
54
|
+
/** `POST .../agents/:agentId/chat-tokens` */
|
|
55
|
+
async create(agentId, input) {
|
|
56
|
+
return this.http.request('POST', this.base(agentId), { body: input });
|
|
57
|
+
}
|
|
58
|
+
/** `PATCH .../chat-tokens/:token` */
|
|
59
|
+
async update(agentId, token, patch) {
|
|
60
|
+
await this.http.request('PATCH', `${this.base(agentId)}/${(0, http_1.seg)(token)}`, { body: patch });
|
|
61
|
+
}
|
|
62
|
+
/** `DELETE .../chat-tokens/:token` */
|
|
63
|
+
async revoke(agentId, token) {
|
|
64
|
+
await this.http.request('DELETE', `${this.base(agentId)}/${(0, http_1.seg)(token)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ChatTokensResource = ChatTokensResource;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HttpCore } from '../http';
|
|
2
|
+
import type { AppSummary, UpdateAppInput } from '../types';
|
|
3
|
+
export declare class AppsResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
private readonly tenantId;
|
|
6
|
+
constructor(http: HttpCore, tenantId: string);
|
|
7
|
+
/** `GET /apps?tenantId=` */
|
|
8
|
+
list(): Promise<{
|
|
9
|
+
items: AppSummary[];
|
|
10
|
+
}>;
|
|
11
|
+
/** `GET /apps/:id?tenantId=` */
|
|
12
|
+
get(appId: string): Promise<AppSummary>;
|
|
13
|
+
/** `PATCH /apps/:id?tenantId=`: branding fields (workspace admin) and `templatePolicy`
|
|
14
|
+
* (workspace owner only; null clears; 400 `invalid_template_policy` if malformed). */
|
|
15
|
+
update(appId: string, patch: UpdateAppInput): Promise<AppSummary>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// apps: the platform Apps (publishers) a workspace owns. Read + edit.
|
|
3
|
+
// `forTenant(id).apps`.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.AppsResource = void 0;
|
|
6
|
+
const http_1 = require("../http");
|
|
7
|
+
class AppsResource {
|
|
8
|
+
constructor(http, tenantId) {
|
|
9
|
+
this.http = http;
|
|
10
|
+
this.tenantId = tenantId;
|
|
11
|
+
}
|
|
12
|
+
/** `GET /apps?tenantId=` */
|
|
13
|
+
async list() {
|
|
14
|
+
return this.http.request('GET', '/apps', { query: { tenantId: this.tenantId } });
|
|
15
|
+
}
|
|
16
|
+
/** `GET /apps/:id?tenantId=` */
|
|
17
|
+
async get(appId) {
|
|
18
|
+
return this.http.request('GET', `/apps/${(0, http_1.seg)(appId)}`, { query: { tenantId: this.tenantId } });
|
|
19
|
+
}
|
|
20
|
+
/** `PATCH /apps/:id?tenantId=`: branding fields (workspace admin) and `templatePolicy`
|
|
21
|
+
* (workspace owner only; null clears; 400 `invalid_template_policy` if malformed). */
|
|
22
|
+
async update(appId, patch) {
|
|
23
|
+
return this.http.request('PATCH', `/apps/${(0, http_1.seg)(appId)}`, { query: { tenantId: this.tenantId }, body: patch });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.AppsResource = AppsResource;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HttpCore } from '../http';
|
|
2
|
+
import type { AuthResult, AuthStrategies, AuthUser, LoginInput, RegisterInput } from '../types';
|
|
3
|
+
export declare class AuthResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpCore);
|
|
6
|
+
/** `POST /auth/register`. Stores the session. */
|
|
7
|
+
register(input: RegisterInput): Promise<AuthResult>;
|
|
8
|
+
/** `POST /auth/login`. Stores the session. 403 `captcha_failed` when the
|
|
9
|
+
* server enforces Turnstile and no `captchaToken` was sent. */
|
|
10
|
+
login(input: LoginInput): Promise<AuthResult>;
|
|
11
|
+
/** `POST /auth/refresh` with the stored refresh token (single-flight with
|
|
12
|
+
* the automatic refresh). Rotates and stores the new pair. Not needed in
|
|
13
|
+
* normal use: a 401 refreshes by itself. */
|
|
14
|
+
refresh(): Promise<{
|
|
15
|
+
accessToken: string;
|
|
16
|
+
refreshToken: string;
|
|
17
|
+
}>;
|
|
18
|
+
/** `POST /auth/logout` (a stateless no-op server-side), then wipes the
|
|
19
|
+
* stored tokens even if the call fails. Does not fire `onSignedOut`. */
|
|
20
|
+
logout(): Promise<void>;
|
|
21
|
+
/** `GET /auth/me` */
|
|
22
|
+
me(): Promise<AuthUser>;
|
|
23
|
+
/** `POST /auth/me/onboarding/complete` (idempotent). */
|
|
24
|
+
completeOnboarding(): Promise<void>;
|
|
25
|
+
/** `POST /auth/me/onboarding/reopen` (idempotent). */
|
|
26
|
+
reopenOnboarding(): Promise<void>;
|
|
27
|
+
/** `GET /auth/strategies` (public): which sign-in methods the server has configured. */
|
|
28
|
+
strategies(): Promise<AuthStrategies>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// auth: dashboard-session auth. Tokens go through the TokenStore; callers never
|
|
3
|
+
// touch them. Routes: apps/server identity AuthController / OAuthController.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.AuthResource = void 0;
|
|
6
|
+
class AuthResource {
|
|
7
|
+
constructor(http) {
|
|
8
|
+
this.http = http;
|
|
9
|
+
}
|
|
10
|
+
/** `POST /auth/register`. Stores the session. */
|
|
11
|
+
async register(input) {
|
|
12
|
+
const res = await this.http.request('POST', '/auth/register', { body: input, auth: false });
|
|
13
|
+
await this.http.setSession(res);
|
|
14
|
+
return res;
|
|
15
|
+
}
|
|
16
|
+
/** `POST /auth/login`. Stores the session. 403 `captcha_failed` when the
|
|
17
|
+
* server enforces Turnstile and no `captchaToken` was sent. */
|
|
18
|
+
async login(input) {
|
|
19
|
+
const res = await this.http.request('POST', '/auth/login', { body: input, auth: false });
|
|
20
|
+
await this.http.setSession(res);
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
23
|
+
/** `POST /auth/refresh` with the stored refresh token (single-flight with
|
|
24
|
+
* the automatic refresh). Rotates and stores the new pair. Not needed in
|
|
25
|
+
* normal use: a 401 refreshes by itself. */
|
|
26
|
+
async refresh() {
|
|
27
|
+
return this.http.refreshNow();
|
|
28
|
+
}
|
|
29
|
+
/** `POST /auth/logout` (a stateless no-op server-side), then wipes the
|
|
30
|
+
* stored tokens even if the call fails. Does not fire `onSignedOut`. */
|
|
31
|
+
async logout() {
|
|
32
|
+
this.http.beginSessionChange();
|
|
33
|
+
try {
|
|
34
|
+
await this.http.request('POST', '/auth/logout');
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
await this.http.clearSession();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** `GET /auth/me` */
|
|
41
|
+
async me() {
|
|
42
|
+
return this.http.request('GET', '/auth/me');
|
|
43
|
+
}
|
|
44
|
+
/** `POST /auth/me/onboarding/complete` (idempotent). */
|
|
45
|
+
async completeOnboarding() {
|
|
46
|
+
await this.http.request('POST', '/auth/me/onboarding/complete');
|
|
47
|
+
}
|
|
48
|
+
/** `POST /auth/me/onboarding/reopen` (idempotent). */
|
|
49
|
+
async reopenOnboarding() {
|
|
50
|
+
await this.http.request('POST', '/auth/me/onboarding/reopen');
|
|
51
|
+
}
|
|
52
|
+
/** `GET /auth/strategies` (public): which sign-in methods the server has configured. */
|
|
53
|
+
async strategies() {
|
|
54
|
+
return this.http.request('GET', '/auth/strategies', { auth: false });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.AuthResource = AuthResource;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HttpCore } from '../http';
|
|
2
|
+
import type { AuthorizeConnectorInput, ConnectorFacets, ConnectorStatus, ListConnectorsInput } from '../types';
|
|
3
|
+
export declare class ConnectorsResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
private readonly tenantId;
|
|
6
|
+
constructor(http: HttpCore, tenantId: string);
|
|
7
|
+
private get tenantHeader();
|
|
8
|
+
/** `GET /connectors/oauth/directory` */
|
|
9
|
+
directory(input?: ListConnectorsInput): Promise<{
|
|
10
|
+
items: ConnectorStatus[];
|
|
11
|
+
}>;
|
|
12
|
+
/** `GET /connectors/oauth/directory/facets` */
|
|
13
|
+
facets(): Promise<ConnectorFacets>;
|
|
14
|
+
/** `POST /connectors/oauth/:id/authorize?tenantId=&postAuthRedirect=`:
|
|
15
|
+
* returns the provider consent URL to open in a browser; the grant is
|
|
16
|
+
* stored for this workspace. Owner/admin only. */
|
|
17
|
+
authorize(connectorId: string, input: AuthorizeConnectorInput): Promise<{
|
|
18
|
+
url: string;
|
|
19
|
+
}>;
|
|
20
|
+
/** `POST /connectors/oauth/:id/api-key?tenantId=` for `authKind: 'api_key'`
|
|
21
|
+
* connectors. The server pings the provider first (401 on a bad key). */
|
|
22
|
+
saveApiKey(connectorId: string, apiKey: string): Promise<{
|
|
23
|
+
connectorId: string;
|
|
24
|
+
}>;
|
|
25
|
+
}
|