@wice24/tars-sdk 0.1.3 → 0.1.5
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/index.d.ts +49 -1
- package/dist/index.js +36 -0
- package/dist/types.d.ts +45 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Agent, AgentVersion, ClientTool, CreateAgentInput, FileMeta, McpCredentialInput, McpCredentialStatus, SessionEvent, SessionInfo, SessionListItem, UpdateAgentInput, UploadFileInput, UsageSummary, SessionUsageRow, DailyUsageRow, McpServer, Skill, SkillVersion, ApiKeyInfo } from './types.js';
|
|
1
|
+
import type { Agent, AgentVersion, ClientTool, CreateAgentInput, FileMeta, McpCredentialInput, McpCredentialStatus, SessionEvent, SessionInfo, SessionListItem, UpdateAgentInput, UploadFileInput, UsageSummary, SessionUsageRow, DailyUsageRow, McpServer, Skill, SkillVersion, ApiKeyInfo, ClientIdentity, ClientRole, PlatformStats, Tenant } from './types.js';
|
|
2
2
|
type ToolHandler = (input: any) => unknown | Promise<unknown>;
|
|
3
3
|
export * from './types.js';
|
|
4
4
|
export declare class TarsApiError extends Error {
|
|
@@ -135,6 +135,47 @@ export declare class TarsClient {
|
|
|
135
135
|
ok: boolean;
|
|
136
136
|
}>;
|
|
137
137
|
};
|
|
138
|
+
/** The client behind this key. `role === 'admin'` is what unlocks `admin.*`. */
|
|
139
|
+
me(): Promise<ClientIdentity>;
|
|
140
|
+
readonly admin: {
|
|
141
|
+
tenants: {
|
|
142
|
+
list: () => Promise<Tenant[]>;
|
|
143
|
+
create: (input: {
|
|
144
|
+
name: string;
|
|
145
|
+
role?: ClientRole;
|
|
146
|
+
}) => Promise<{
|
|
147
|
+
tenant: Tenant;
|
|
148
|
+
key: {
|
|
149
|
+
key: string;
|
|
150
|
+
key_prefix: string;
|
|
151
|
+
};
|
|
152
|
+
}>;
|
|
153
|
+
get: (id: string) => Promise<{
|
|
154
|
+
tenant: Tenant;
|
|
155
|
+
keys: ApiKeyInfo[];
|
|
156
|
+
}>;
|
|
157
|
+
/** Switch a tenant off: its keys stay, every request under them 403s. */
|
|
158
|
+
disable: (id: string) => Promise<{
|
|
159
|
+
ok: boolean;
|
|
160
|
+
}>;
|
|
161
|
+
enable: (id: string) => Promise<{
|
|
162
|
+
ok: boolean;
|
|
163
|
+
}>;
|
|
164
|
+
createApiKey: (id: string, input?: {
|
|
165
|
+
name?: string;
|
|
166
|
+
}) => Promise<{
|
|
167
|
+
id: string;
|
|
168
|
+
key: string;
|
|
169
|
+
key_prefix: string;
|
|
170
|
+
name: string | null;
|
|
171
|
+
}>;
|
|
172
|
+
/** Unlike tenant self-service, this MAY revoke a tenant's last key. */
|
|
173
|
+
revokeApiKey: (id: string, keyId: string) => Promise<{
|
|
174
|
+
ok: boolean;
|
|
175
|
+
}>;
|
|
176
|
+
};
|
|
177
|
+
stats: () => Promise<PlatformStats>;
|
|
178
|
+
};
|
|
138
179
|
readonly completions: {
|
|
139
180
|
create: (input: {
|
|
140
181
|
prompt: string;
|
|
@@ -149,6 +190,13 @@ export declare class TarsClient {
|
|
|
149
190
|
};
|
|
150
191
|
}>;
|
|
151
192
|
};
|
|
193
|
+
/**
|
|
194
|
+
* Which model providers this instance is keyed for (`anthropic`, `openai`,
|
|
195
|
+
* `openrouter`, `custom`). Ask before OFFERING models: a picker listing GPT
|
|
196
|
+
* models on an instance with no OpenAI key produces turns that all fail at
|
|
197
|
+
* the provider call.
|
|
198
|
+
*/
|
|
199
|
+
providers(): Promise<string[]>;
|
|
152
200
|
readonly usage: {
|
|
153
201
|
get: (filter?: {
|
|
154
202
|
from?: string | Date;
|
package/dist/index.js
CHANGED
|
@@ -168,6 +168,32 @@ export class TarsClient {
|
|
|
168
168
|
list: async () => (await this.request('GET', '/v1/api-keys')).keys,
|
|
169
169
|
revoke: (id) => this.request('DELETE', `/v1/api-keys/${id}`),
|
|
170
170
|
};
|
|
171
|
+
/** The client behind this key. `role === 'admin'` is what unlocks `admin.*`. */
|
|
172
|
+
me() {
|
|
173
|
+
return this.request('GET', '/v1/me');
|
|
174
|
+
}
|
|
175
|
+
// ── administration (admin-role keys only; 403 admin_required otherwise) ──
|
|
176
|
+
// Tenants, their keys, and platform-wide stats. A created tenant's first
|
|
177
|
+
// key — like any minted key — is returned ONCE and never retrievable again.
|
|
178
|
+
admin = {
|
|
179
|
+
tenants: {
|
|
180
|
+
list: async () => (await this.request('GET', '/v1/admin/tenants')).tenants,
|
|
181
|
+
create: (input) => this.request('POST', '/v1/admin/tenants', {
|
|
182
|
+
name: input.name,
|
|
183
|
+
...(input.role ? { role: input.role } : {}),
|
|
184
|
+
}),
|
|
185
|
+
get: (id) => this.request('GET', `/v1/admin/tenants/${id}`),
|
|
186
|
+
/** Switch a tenant off: its keys stay, every request under them 403s. */
|
|
187
|
+
disable: (id) => this.request('POST', `/v1/admin/tenants/${id}/disable`),
|
|
188
|
+
enable: (id) => this.request('POST', `/v1/admin/tenants/${id}/enable`),
|
|
189
|
+
createApiKey: (id, input) => this.request('POST', `/v1/admin/tenants/${id}/api-keys`, {
|
|
190
|
+
...(input?.name ? { name: input.name } : {}),
|
|
191
|
+
}),
|
|
192
|
+
/** Unlike tenant self-service, this MAY revoke a tenant's last key. */
|
|
193
|
+
revokeApiKey: (id, keyId) => this.request('DELETE', `/v1/admin/tenants/${id}/api-keys/${keyId}`),
|
|
194
|
+
},
|
|
195
|
+
stats: () => this.request('GET', '/v1/admin/stats'),
|
|
196
|
+
};
|
|
171
197
|
// Cheap non-session completion (titles and other one-shots) — routed
|
|
172
198
|
// through the same provider seam as agent turns.
|
|
173
199
|
completions = {
|
|
@@ -178,6 +204,16 @@ export class TarsClient {
|
|
|
178
204
|
...(input.maxTokens ? { max_tokens: input.maxTokens } : {}),
|
|
179
205
|
}),
|
|
180
206
|
};
|
|
207
|
+
/**
|
|
208
|
+
* Which model providers this instance is keyed for (`anthropic`, `openai`,
|
|
209
|
+
* `openrouter`, `custom`). Ask before OFFERING models: a picker listing GPT
|
|
210
|
+
* models on an instance with no OpenAI key produces turns that all fail at
|
|
211
|
+
* the provider call.
|
|
212
|
+
*/
|
|
213
|
+
async providers() {
|
|
214
|
+
const body = await this.request('GET', '/v1/providers');
|
|
215
|
+
return body.providers ?? [];
|
|
216
|
+
}
|
|
181
217
|
usage = {
|
|
182
218
|
// Aggregated token/cost usage for this tenant, with per-model, per-agent,
|
|
183
219
|
// and per-end-user breakdowns. Dates are ISO 8601; sessionId narrows to one
|
package/dist/types.d.ts
CHANGED
|
@@ -136,6 +136,51 @@ export interface ApiKeyInfo {
|
|
|
136
136
|
created_at: string;
|
|
137
137
|
revoked_at: string | null;
|
|
138
138
|
}
|
|
139
|
+
/** `admin` keys may call `client.admin.*`; everything else is a `tenant`. */
|
|
140
|
+
export type ClientRole = 'tenant' | 'admin';
|
|
141
|
+
/** The client behind an API key (GET /v1/me). */
|
|
142
|
+
export interface ClientIdentity {
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
role: ClientRole;
|
|
146
|
+
}
|
|
147
|
+
/** All-time counters for one tenant, as the admin console lists them. */
|
|
148
|
+
export interface TenantStats {
|
|
149
|
+
active_keys: number;
|
|
150
|
+
agents: number;
|
|
151
|
+
sessions: number;
|
|
152
|
+
running_sessions: number;
|
|
153
|
+
turns: number;
|
|
154
|
+
input_tokens: number;
|
|
155
|
+
output_tokens: number;
|
|
156
|
+
cost_usd: number | null;
|
|
157
|
+
}
|
|
158
|
+
export interface Tenant {
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
role: ClientRole;
|
|
162
|
+
/** Set = switched off: every request under the tenant's keys is a 403. */
|
|
163
|
+
disabled_at: string | null;
|
|
164
|
+
created_at: string;
|
|
165
|
+
stats: TenantStats;
|
|
166
|
+
}
|
|
167
|
+
export interface UsageTotals {
|
|
168
|
+
sessions: number;
|
|
169
|
+
turns: number;
|
|
170
|
+
input_tokens: number;
|
|
171
|
+
output_tokens: number;
|
|
172
|
+
cost_usd: number | null;
|
|
173
|
+
}
|
|
174
|
+
export interface PlatformStats {
|
|
175
|
+
tenants: {
|
|
176
|
+
total: number;
|
|
177
|
+
active: number;
|
|
178
|
+
disabled: number;
|
|
179
|
+
admins: number;
|
|
180
|
+
};
|
|
181
|
+
all_time: UsageTotals;
|
|
182
|
+
last_30d: UsageTotals;
|
|
183
|
+
}
|
|
139
184
|
export type McpCredentialInput = {
|
|
140
185
|
type: 'bearer';
|
|
141
186
|
token: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wice24/tars-sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Client SDK for TARS
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Client SDK for TARS — the self-hosted managed-agents platform (sessions, streaming turns, client tools, MCP credentials, skills, files, usage, tenant administration)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|