@wice24/tars-sdk 0.1.4 → 0.1.6
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 +2 -2
- package/dist/index.d.ts +47 -1
- package/dist/index.js +34 -1
- package/dist/types.d.ts +45 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @wice24/tars-sdk
|
|
2
2
|
|
|
3
|
-
TypeScript client for [TARS](https://github.com/
|
|
3
|
+
TypeScript client for [TARS](https://github.com/LegendariTech/tars) — a
|
|
4
4
|
self-hosted managed-agents platform: server-side agent loops in sandboxes,
|
|
5
5
|
an append-only session event log with SSE streaming + replay, client-executed
|
|
6
6
|
tools, per-end-user MCP credentials, skills, files, and usage metering.
|
|
@@ -22,7 +22,7 @@ const tars = new TarsClient({
|
|
|
22
22
|
const agent = await tars.agents.create({
|
|
23
23
|
name: 'assistant',
|
|
24
24
|
system: 'You are a helpful assistant.',
|
|
25
|
-
model: 'anthropic/claude-sonnet-5',
|
|
25
|
+
model: 'openrouter/anthropic/claude-sonnet-5',
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
const session = await tars.sessions.create({ agentId: agent.id });
|
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;
|
|
@@ -227,6 +268,11 @@ export declare class TarsSession {
|
|
|
227
268
|
file: FileMeta;
|
|
228
269
|
mount_path: string;
|
|
229
270
|
}>;
|
|
271
|
+
/** Abort the in-flight turn, if any. Idempotent. */
|
|
272
|
+
interrupt(): Promise<{
|
|
273
|
+
ok: boolean;
|
|
274
|
+
interrupted: boolean;
|
|
275
|
+
}>;
|
|
230
276
|
destroy(): Promise<{
|
|
231
277
|
ok: boolean;
|
|
232
278
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -144,7 +144,7 @@ export class TarsClient {
|
|
|
144
144
|
return this.request('DELETE', `/v1/mcp-credentials?${params}`);
|
|
145
145
|
},
|
|
146
146
|
};
|
|
147
|
-
// ──
|
|
147
|
+
// ── skills ───────────────────────────────────────────────────
|
|
148
148
|
// Versioned skill bundles (zip with SKILL.md at root), pinned per agent.
|
|
149
149
|
skills = {
|
|
150
150
|
create: (input) => this.request('POST', '/v1/skills', { slug: input.slug, display_title: input.displayTitle }),
|
|
@@ -163,11 +163,39 @@ export class TarsClient {
|
|
|
163
163
|
return res.json();
|
|
164
164
|
},
|
|
165
165
|
};
|
|
166
|
+
// ── api keys / identity ──────────────────────────────────────
|
|
166
167
|
apiKeys = {
|
|
167
168
|
create: (input) => this.request('POST', '/v1/api-keys', { ...(input?.name ? { name: input.name } : {}) }),
|
|
168
169
|
list: async () => (await this.request('GET', '/v1/api-keys')).keys,
|
|
169
170
|
revoke: (id) => this.request('DELETE', `/v1/api-keys/${id}`),
|
|
170
171
|
};
|
|
172
|
+
/** The client behind this key. `role === 'admin'` is what unlocks `admin.*`. */
|
|
173
|
+
me() {
|
|
174
|
+
return this.request('GET', '/v1/me');
|
|
175
|
+
}
|
|
176
|
+
// ── administration (admin-role keys only; 403 admin_required otherwise) ──
|
|
177
|
+
// Tenants, their keys, and platform-wide stats. A created tenant's first
|
|
178
|
+
// key — like any minted key — is returned ONCE and never retrievable again.
|
|
179
|
+
admin = {
|
|
180
|
+
tenants: {
|
|
181
|
+
list: async () => (await this.request('GET', '/v1/admin/tenants')).tenants,
|
|
182
|
+
create: (input) => this.request('POST', '/v1/admin/tenants', {
|
|
183
|
+
name: input.name,
|
|
184
|
+
...(input.role ? { role: input.role } : {}),
|
|
185
|
+
}),
|
|
186
|
+
get: (id) => this.request('GET', `/v1/admin/tenants/${id}`),
|
|
187
|
+
/** Switch a tenant off: its keys stay, every request under them 403s. */
|
|
188
|
+
disable: (id) => this.request('POST', `/v1/admin/tenants/${id}/disable`),
|
|
189
|
+
enable: (id) => this.request('POST', `/v1/admin/tenants/${id}/enable`),
|
|
190
|
+
createApiKey: (id, input) => this.request('POST', `/v1/admin/tenants/${id}/api-keys`, {
|
|
191
|
+
...(input?.name ? { name: input.name } : {}),
|
|
192
|
+
}),
|
|
193
|
+
/** Unlike tenant self-service, this MAY revoke a tenant's last key. */
|
|
194
|
+
revokeApiKey: (id, keyId) => this.request('DELETE', `/v1/admin/tenants/${id}/api-keys/${keyId}`),
|
|
195
|
+
},
|
|
196
|
+
stats: () => this.request('GET', '/v1/admin/stats'),
|
|
197
|
+
};
|
|
198
|
+
// ── completions / providers (any key) ────────────────────────
|
|
171
199
|
// Cheap non-session completion (titles and other one-shots) — routed
|
|
172
200
|
// through the same provider seam as agent turns.
|
|
173
201
|
completions = {
|
|
@@ -188,6 +216,7 @@ export class TarsClient {
|
|
|
188
216
|
const body = await this.request('GET', '/v1/providers');
|
|
189
217
|
return body.providers ?? [];
|
|
190
218
|
}
|
|
219
|
+
// ── usage ────────────────────────────────────────────────────
|
|
191
220
|
usage = {
|
|
192
221
|
// Aggregated token/cost usage for this tenant, with per-model, per-agent,
|
|
193
222
|
// and per-end-user breakdowns. Dates are ISO 8601; sessionId narrows to one
|
|
@@ -411,6 +440,10 @@ export class TarsSession {
|
|
|
411
440
|
const { mount_path } = await this.mountFile(file.id, input.mountPath);
|
|
412
441
|
return { file, mount_path };
|
|
413
442
|
}
|
|
443
|
+
/** Abort the in-flight turn, if any. Idempotent. */
|
|
444
|
+
interrupt() {
|
|
445
|
+
return this.client.sessions.interrupt(this.info.id);
|
|
446
|
+
}
|
|
414
447
|
destroy() {
|
|
415
448
|
return this.client.sessions.destroy(this.info.id);
|
|
416
449
|
}
|
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 — the self-hosted managed-agents platform (sessions, streaming turns, client tools, MCP credentials, skills, files, usage)",
|
|
3
|
+
"version": "0.1.6",
|
|
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
|
".": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/
|
|
31
|
+
"url": "git+https://github.com/LegendariTech/tars.git",
|
|
32
32
|
"directory": "sdk"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|