langtrain 0.1.10 → 0.1.11
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 +1 -1
- package/dist/cli.js +105 -0
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +105 -0
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +30 -0
- package/src/cli.ts +129 -1
- package/src/index.ts +1 -1
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/index.d.mts +0 -47
- package/dist/index.d.ts +0 -47
package/package.json
CHANGED
package/src/agent.ts
CHANGED
|
@@ -43,6 +43,20 @@ export class AgentClient {
|
|
|
43
43
|
return response.data.agents;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
async get(agentId: string): Promise<Agent> {
|
|
47
|
+
const response = await this.client.get<Agent>(`/agents/${agentId}`);
|
|
48
|
+
return response.data;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async create(agent: AgentCreate): Promise<Agent> {
|
|
52
|
+
const response = await this.client.post<Agent>('/agents/', agent);
|
|
53
|
+
return response.data;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async delete(agentId: string): Promise<void> {
|
|
57
|
+
await this.client.delete(`/agents/${agentId}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
46
60
|
async execute(agentId: string, input: any, messages: any[] = [], conversationId?: string): Promise<AgentRun> {
|
|
47
61
|
const response = await this.client.post<AgentRun>(`/agents/${agentId}/execute`, {
|
|
48
62
|
input,
|
|
@@ -52,3 +66,19 @@ export class AgentClient {
|
|
|
52
66
|
return response.data;
|
|
53
67
|
}
|
|
54
68
|
}
|
|
69
|
+
|
|
70
|
+
export interface AgentConfig {
|
|
71
|
+
system_prompt?: string;
|
|
72
|
+
temperature?: number;
|
|
73
|
+
max_tokens?: number;
|
|
74
|
+
tools?: string[];
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface AgentCreate {
|
|
79
|
+
workspace_id: string; // UUID
|
|
80
|
+
name: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
model_id?: string; // UUID
|
|
83
|
+
config?: AgentConfig;
|
|
84
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { intro, outro, select, text, spinner, isCancel, cancel, password } from '@clack/prompts';
|
|
3
3
|
import { bgCyan, black, red, green, yellow, gray } from 'kleur/colors';
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import { Langvision, Langtune, AgentClient, Agent } from './index';
|
|
5
|
+
import { Langvision, Langtune, AgentClient, Agent, AgentCreate } from './index';
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import os from 'os';
|
|
@@ -69,6 +69,8 @@ async function main() {
|
|
|
69
69
|
'vision-finetune': (c) => handleVisionFinetune(c.vision),
|
|
70
70
|
'vision-generate': (c) => handleVisionGenerate(c.vision),
|
|
71
71
|
'agent-list': (c) => handleAgentList(c.agent),
|
|
72
|
+
'agent-create': (c) => handleAgentCreate(c.agent),
|
|
73
|
+
'agent-delete': (c) => handleAgentDelete(c.agent),
|
|
72
74
|
'exit': async () => { outro('Goodbye!'); process.exit(0); },
|
|
73
75
|
};
|
|
74
76
|
|
|
@@ -78,6 +80,8 @@ async function main() {
|
|
|
78
80
|
options: [
|
|
79
81
|
{ value: 'group-agents', label: '🤖 Agents (Server)', hint: 'Chat with custom agents' },
|
|
80
82
|
{ value: 'agent-list', label: ' ↳ List & Run Agents' },
|
|
83
|
+
{ value: 'agent-create', label: ' ↳ Create New Agent' },
|
|
84
|
+
{ value: 'agent-delete', label: ' ↳ Delete Agent' },
|
|
81
85
|
|
|
82
86
|
{ value: 'group-tune', label: '🧠 Langtune (LLM)', hint: 'Fine-tuning & Text Generation' },
|
|
83
87
|
{ value: 'tune-finetune', label: ' ↳ Fine-tune Text Model' },
|
|
@@ -140,6 +144,130 @@ async function handleLogin() {
|
|
|
140
144
|
intro(green('API Key updated successfully!'));
|
|
141
145
|
}
|
|
142
146
|
|
|
147
|
+
async function handleAgentCreate(client: AgentClient) {
|
|
148
|
+
const name = await text({
|
|
149
|
+
message: 'Agent Name:',
|
|
150
|
+
placeholder: 'e.g. Support Bot',
|
|
151
|
+
validate(value) {
|
|
152
|
+
if (value.length === 0) return 'Name is required!';
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
if (isCancel(name)) return;
|
|
156
|
+
|
|
157
|
+
const description = await text({
|
|
158
|
+
message: 'Description:',
|
|
159
|
+
placeholder: 'e.g. A helpful support assistant',
|
|
160
|
+
});
|
|
161
|
+
if (isCancel(description)) return;
|
|
162
|
+
|
|
163
|
+
const systemPrompt = await text({
|
|
164
|
+
message: 'System Prompt:',
|
|
165
|
+
placeholder: 'e.g. You are a helpful assistant.',
|
|
166
|
+
initialValue: 'You are a helpful assistant.'
|
|
167
|
+
});
|
|
168
|
+
if (isCancel(systemPrompt)) return;
|
|
169
|
+
|
|
170
|
+
const s = spinner();
|
|
171
|
+
s.start('Creating agent...');
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
// We need a workspace ID. server usually infers it from API key context if not provided?
|
|
175
|
+
// But the schema says workspace_id is required in AgentCreate.
|
|
176
|
+
// The server implementation of create_agent takes AgentCreate which has workspace_id.
|
|
177
|
+
// However, standard users might not know their exact workspace UUID.
|
|
178
|
+
// We might need to fetch it or rely on server to fill it if we made it optional in schema (which we didn't).
|
|
179
|
+
// EDIT: Let's fetch one agent to get the workspace_id or assume one?
|
|
180
|
+
// Better: List agents, get workspace_id from first one. Hacky but works for single-workspace users.
|
|
181
|
+
// Use 'default' or similar if server supports it?
|
|
182
|
+
// Checking agents.py: verify_api_key returns workspace_id.
|
|
183
|
+
// But create_agent payload requires it.
|
|
184
|
+
// I'll try to fetch list first to get workspace ID. If list empty, we are stuck?
|
|
185
|
+
// Wait, list_agents returns `AgentListResponse` which doesn't explicitly return workspace_id at top level, but agents have it.
|
|
186
|
+
// If no agents, we can't guess it.
|
|
187
|
+
// Maybe I should fetch user profile? No endpoint for that in CLI yet.
|
|
188
|
+
// I'll try to pass a placeholder and hope server ignores it if it uses context?
|
|
189
|
+
// Server code: `workspace_id=agent_in.workspace_id`. It uses payload.
|
|
190
|
+
// I might need to ask user for workspace ID or update server to be smarter.
|
|
191
|
+
// For now, I'll attempt to LIST agents to get a workspace ID.
|
|
192
|
+
|
|
193
|
+
const agents = await client.list();
|
|
194
|
+
let workspaceId = "";
|
|
195
|
+
if (agents.length > 0) {
|
|
196
|
+
workspaceId = agents[0].workspace_id;
|
|
197
|
+
} else {
|
|
198
|
+
// Fallback: Ask user or fail?
|
|
199
|
+
// Or maybe decoding JWT/API key client side? No.
|
|
200
|
+
// I'll prompt for it if not found, with a hint.
|
|
201
|
+
s.stop(yellow('Workspace ID needed (no existing agents found).'));
|
|
202
|
+
const wid = await text({
|
|
203
|
+
message: 'Enter Workspace ID (UUID):',
|
|
204
|
+
validate(value) {
|
|
205
|
+
if (value.length === 0) return 'Required';
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
if (isCancel(wid)) return;
|
|
209
|
+
workspaceId = wid as string;
|
|
210
|
+
s.start('Creating agent...');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const agent = await client.create({
|
|
214
|
+
workspace_id: workspaceId,
|
|
215
|
+
name: name as string,
|
|
216
|
+
description: description as string,
|
|
217
|
+
config: {
|
|
218
|
+
system_prompt: systemPrompt as string,
|
|
219
|
+
model: 'gpt-4o' // Default or prompt? simplified
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
s.stop(green(`Agent "${agent.name}" created successfully! ID: ${agent.id}`));
|
|
223
|
+
} catch (e: any) {
|
|
224
|
+
s.stop(red('Failed to create agent.'));
|
|
225
|
+
throw e;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function handleAgentDelete(client: AgentClient) {
|
|
230
|
+
const s = spinner();
|
|
231
|
+
s.start('Fetching agents...');
|
|
232
|
+
const agents = await client.list();
|
|
233
|
+
s.stop(`Found ${agents.length} agents`);
|
|
234
|
+
|
|
235
|
+
if (agents.length === 0) {
|
|
236
|
+
intro(yellow('No agents to delete.'));
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const agentId = await select({
|
|
241
|
+
message: 'Select an agent to DELETE:',
|
|
242
|
+
options: agents.map(a => ({ value: a.id, label: a.name, hint: a.description || 'No description' }))
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
if (isCancel(agentId)) return;
|
|
246
|
+
|
|
247
|
+
const confirm = await select({
|
|
248
|
+
message: `Are you sure you want to delete this agent?`,
|
|
249
|
+
options: [
|
|
250
|
+
{ value: 'yes', label: 'Yes, delete it', hint: 'Cannot be undone' },
|
|
251
|
+
{ value: 'no', label: 'No, keep it' }
|
|
252
|
+
]
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
if (confirm !== 'yes') {
|
|
256
|
+
intro(gray('Deletion cancelled.'));
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const d = spinner();
|
|
261
|
+
d.start('Deleting agent...');
|
|
262
|
+
try {
|
|
263
|
+
await client.delete(agentId as string);
|
|
264
|
+
d.stop(green('Agent deleted successfully.'));
|
|
265
|
+
} catch (e: any) {
|
|
266
|
+
d.stop(red('Failed to delete agent.'));
|
|
267
|
+
throw e;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
143
271
|
async function handleAgentList(client: AgentClient) {
|
|
144
272
|
const s = spinner();
|
|
145
273
|
s.start('Fetching agents...');
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { Langvision } from 'langvision';
|
|
|
4
4
|
export { Langtune } from 'langtune';
|
|
5
5
|
|
|
6
6
|
// Export Agent Client
|
|
7
|
-
export { AgentClient, Agent, AgentRun } from './agent';
|
|
7
|
+
export { AgentClient, Agent, AgentRun, AgentCreate } from './agent';
|
|
8
8
|
|
|
9
9
|
// Export Types with Namespaces to avoid collisions
|
|
10
10
|
import * as Vision from 'langvision';
|
package/dist/cli.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/index.d.mts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as langvision from 'langvision';
|
|
2
|
-
export { langvision as Vision };
|
|
3
|
-
export { Langvision } from 'langvision';
|
|
4
|
-
import * as langtune from 'langtune';
|
|
5
|
-
export { langtune as Text };
|
|
6
|
-
export { Langtune } from 'langtune';
|
|
7
|
-
|
|
8
|
-
interface Agent {
|
|
9
|
-
id: string;
|
|
10
|
-
workspace_id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
model_id?: string;
|
|
14
|
-
config: any;
|
|
15
|
-
is_active: boolean;
|
|
16
|
-
created_at: string;
|
|
17
|
-
updated_at: string;
|
|
18
|
-
}
|
|
19
|
-
interface AgentRun {
|
|
20
|
-
id: string;
|
|
21
|
-
conversation_id: string;
|
|
22
|
-
success: boolean;
|
|
23
|
-
output?: any;
|
|
24
|
-
error?: string;
|
|
25
|
-
latency_ms: number;
|
|
26
|
-
tokens_used: number;
|
|
27
|
-
}
|
|
28
|
-
declare class AgentClient {
|
|
29
|
-
private config;
|
|
30
|
-
private client;
|
|
31
|
-
constructor(config: {
|
|
32
|
-
apiKey: string;
|
|
33
|
-
baseUrl?: string;
|
|
34
|
-
});
|
|
35
|
-
list(workspaceId?: string): Promise<Agent[]>;
|
|
36
|
-
execute(agentId: string, input: any, messages?: any[], conversationId?: string): Promise<AgentRun>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type agent_Agent = Agent;
|
|
40
|
-
type agent_AgentClient = AgentClient;
|
|
41
|
-
declare const agent_AgentClient: typeof AgentClient;
|
|
42
|
-
type agent_AgentRun = AgentRun;
|
|
43
|
-
declare namespace agent {
|
|
44
|
-
export { type agent_Agent as Agent, agent_AgentClient as AgentClient, type agent_AgentRun as AgentRun };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { type Agent, AgentClient, type AgentRun, agent as AgentTypes };
|
package/dist/index.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as langvision from 'langvision';
|
|
2
|
-
export { langvision as Vision };
|
|
3
|
-
export { Langvision } from 'langvision';
|
|
4
|
-
import * as langtune from 'langtune';
|
|
5
|
-
export { langtune as Text };
|
|
6
|
-
export { Langtune } from 'langtune';
|
|
7
|
-
|
|
8
|
-
interface Agent {
|
|
9
|
-
id: string;
|
|
10
|
-
workspace_id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
model_id?: string;
|
|
14
|
-
config: any;
|
|
15
|
-
is_active: boolean;
|
|
16
|
-
created_at: string;
|
|
17
|
-
updated_at: string;
|
|
18
|
-
}
|
|
19
|
-
interface AgentRun {
|
|
20
|
-
id: string;
|
|
21
|
-
conversation_id: string;
|
|
22
|
-
success: boolean;
|
|
23
|
-
output?: any;
|
|
24
|
-
error?: string;
|
|
25
|
-
latency_ms: number;
|
|
26
|
-
tokens_used: number;
|
|
27
|
-
}
|
|
28
|
-
declare class AgentClient {
|
|
29
|
-
private config;
|
|
30
|
-
private client;
|
|
31
|
-
constructor(config: {
|
|
32
|
-
apiKey: string;
|
|
33
|
-
baseUrl?: string;
|
|
34
|
-
});
|
|
35
|
-
list(workspaceId?: string): Promise<Agent[]>;
|
|
36
|
-
execute(agentId: string, input: any, messages?: any[], conversationId?: string): Promise<AgentRun>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type agent_Agent = Agent;
|
|
40
|
-
type agent_AgentClient = AgentClient;
|
|
41
|
-
declare const agent_AgentClient: typeof AgentClient;
|
|
42
|
-
type agent_AgentRun = AgentRun;
|
|
43
|
-
declare namespace agent {
|
|
44
|
-
export { type agent_Agent as Agent, agent_AgentClient as AgentClient, type agent_AgentRun as AgentRun };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { type Agent, AgentClient, type AgentRun, agent as AgentTypes };
|