@almyty/agents 0.1.0 → 0.1.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/index.js CHANGED
@@ -11,8 +11,7 @@
11
11
  * Reads credentials from ~/.almyty/credentials.json (created by
12
12
  * `npx @almyty/auth login`).
13
13
  */
14
- import { AlmytyClient } from './client.js';
15
- import { resolveCredentialsOrExit } from './credentials.js';
14
+ import { AlmytyClient, resolveCredentialsOrExit } from '@almyty/client';
16
15
  const VERSION = '0.1.0';
17
16
  function printHelp() {
18
17
  console.log(`
@@ -31,6 +30,7 @@ Commands:
31
30
 
32
31
  Run options:
33
32
  --input '<json>' Input payload (workflow: object; autonomous: string or object)
33
+ --resume <conversation-id> Resume a previous conversation
34
34
  --max-steps <n> Autonomous: max steps (default 50)
35
35
  --max-cost-cents <n> Autonomous: max cost in cents (default 100)
36
36
  --max-duration-ms <ms> Autonomous: max wall time in ms (default 3600000)
@@ -188,7 +188,9 @@ async function cmdRun(args) {
188
188
  limits.maxCostCents = Number(args.flags['max-cost-cents']);
189
189
  if (args.flags['max-duration-ms'])
190
190
  limits.maxDurationMs = Number(args.flags['max-duration-ms']);
191
- const runStub = await client.startAgentRun(agent.id, rawInput ?? '', limits);
191
+ if (typeof args.flags.resume === 'string')
192
+ limits.conversationId = args.flags.resume;
193
+ const runStub = await client.startRun(agent.id, rawInput ?? '', limits);
192
194
  if (!args.flags.watch) {
193
195
  if (args.flags.json) {
194
196
  console.log(JSON.stringify(runStub, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almyty/agents",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "List, run, and manage almyty agents from the command line",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,7 +11,7 @@
11
11
  "dist"
12
12
  ],
13
13
  "scripts": {
14
- "build": "tsc",
14
+ "build": "tsc && chmod +x dist/index.js",
15
15
  "dev": "tsx src/index.ts",
16
16
  "test": "vitest run",
17
17
  "test:watch": "vitest",
@@ -24,6 +24,9 @@
24
24
  ],
25
25
  "author": "almyty",
26
26
  "license": "BSL-1.1",
27
+ "dependencies": {
28
+ "@almyty/client": "^0.1.0"
29
+ },
27
30
  "devDependencies": {
28
31
  "@types/node": "^25.4.0",
29
32
  "tsx": "^4.7.0",
package/dist/client.d.ts DELETED
@@ -1,50 +0,0 @@
1
- /**
2
- * Tiny HTTP client for the almyty REST API, scoped to the surface
3
- * needed by @almyty/agents (list / get / invoke / runs).
4
- */
5
- export interface AgentInfo {
6
- id: string;
7
- name: string;
8
- description?: string;
9
- mode?: 'workflow' | 'autonomous';
10
- status?: string;
11
- }
12
- export interface AgentRun {
13
- id: string;
14
- status: string;
15
- output?: any;
16
- error?: string;
17
- steps?: any[];
18
- totalCost?: number;
19
- totalTokens?: number;
20
- }
21
- export declare class AlmytyClient {
22
- private readonly baseUrl;
23
- private readonly token;
24
- constructor(baseUrl: string, token: string);
25
- private request;
26
- listAgents(): Promise<AgentInfo[]>;
27
- findAgentByNameOrId(nameOrId: string): Promise<AgentInfo | null>;
28
- invokeAgent(agentId: string, input: Record<string, any>): Promise<any>;
29
- startAgentRun(agentId: string, input: any, limits?: {
30
- maxSteps?: number;
31
- maxCostCents?: number;
32
- maxDurationMs?: number;
33
- }): Promise<AgentRun>;
34
- getRun(agentId: string, runId: string): Promise<AgentRun>;
35
- listRuns(agentId: string, page?: number, limit?: number): Promise<{
36
- data: AgentRun[];
37
- total: number;
38
- }>;
39
- sendRunInput(agentId: string, runId: string, input: string): Promise<void>;
40
- cancelRun(agentId: string, runId: string): Promise<void>;
41
- /**
42
- * Poll a run until it reaches a terminal status (or waiting_input).
43
- * Calls onStep whenever new steps appear so callers can stream output.
44
- */
45
- pollRun(agentId: string, runId: string, options?: {
46
- intervalMs?: number;
47
- timeoutMs?: number;
48
- onStep?: (run: AgentRun) => void;
49
- }): Promise<AgentRun>;
50
- }
package/dist/client.js DELETED
@@ -1,121 +0,0 @@
1
- /**
2
- * Tiny HTTP client for the almyty REST API, scoped to the surface
3
- * needed by @almyty/agents (list / get / invoke / runs).
4
- */
5
- const TERMINAL_STATUSES = new Set(['completed', 'failed', 'cancelled', 'timeout']);
6
- export class AlmytyClient {
7
- baseUrl;
8
- token;
9
- constructor(baseUrl, token) {
10
- this.baseUrl = baseUrl.replace(/\/$/, '');
11
- this.token = token;
12
- }
13
- async request(path, init = {}) {
14
- const url = `${this.baseUrl}${path}`;
15
- const headers = {
16
- Authorization: `Bearer ${this.token}`,
17
- 'Content-Type': 'application/json',
18
- ...(init.headers || {}),
19
- };
20
- const res = await fetch(url, { ...init, headers });
21
- if (!res.ok) {
22
- if (res.status === 401) {
23
- throw new Error('Authentication failed. Run: npx @almyty/auth login');
24
- }
25
- const text = await res.text().catch(() => '');
26
- throw new Error(`API error ${res.status}: ${text}`);
27
- }
28
- if (res.status === 204)
29
- return null;
30
- return res.json();
31
- }
32
- async listAgents() {
33
- const data = await this.request('/agents');
34
- const agents = data?.data?.data || data?.data || data || [];
35
- return agents.map((a) => ({
36
- id: a.id,
37
- name: a.name,
38
- description: a.description,
39
- mode: a.mode,
40
- status: a.status,
41
- }));
42
- }
43
- async findAgentByNameOrId(nameOrId) {
44
- const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
45
- if (uuidRegex.test(nameOrId)) {
46
- try {
47
- const data = await this.request(`/agents/${nameOrId}`);
48
- const a = data?.data ?? data;
49
- if (a?.id) {
50
- return { id: a.id, name: a.name, description: a.description, mode: a.mode, status: a.status };
51
- }
52
- }
53
- catch {
54
- // fall through to name search
55
- }
56
- }
57
- const all = await this.listAgents();
58
- const lower = nameOrId.toLowerCase();
59
- return (all.find((a) => a.name === nameOrId) ||
60
- all.find((a) => a.name.toLowerCase() === lower) ||
61
- all.find((a) => a.name.toLowerCase().replace(/\s+/g, '-') === lower) ||
62
- null);
63
- }
64
- async invokeAgent(agentId, input) {
65
- const data = await this.request(`/agents/${agentId}/invoke`, {
66
- method: 'POST',
67
- body: JSON.stringify({ input }),
68
- });
69
- return data?.data ?? data;
70
- }
71
- async startAgentRun(agentId, input, limits) {
72
- const data = await this.request(`/agents/${agentId}/runs`, {
73
- method: 'POST',
74
- body: JSON.stringify({ input, ...(limits || {}) }),
75
- });
76
- const run = data?.data ?? data;
77
- return { id: run.id, status: run.status };
78
- }
79
- async getRun(agentId, runId) {
80
- const data = await this.request(`/agents/${agentId}/runs/${runId}`);
81
- return (data?.data ?? data);
82
- }
83
- async listRuns(agentId, page = 1, limit = 20) {
84
- const data = await this.request(`/agents/${agentId}/runs?page=${page}&limit=${limit}`);
85
- return {
86
- data: data?.data ?? [],
87
- total: data?.pagination?.total ?? 0,
88
- };
89
- }
90
- async sendRunInput(agentId, runId, input) {
91
- await this.request(`/agents/${agentId}/runs/${runId}/input`, {
92
- method: 'POST',
93
- body: JSON.stringify({ input }),
94
- });
95
- }
96
- async cancelRun(agentId, runId) {
97
- await this.request(`/agents/${agentId}/runs/${runId}/cancel`, { method: 'POST' });
98
- }
99
- /**
100
- * Poll a run until it reaches a terminal status (or waiting_input).
101
- * Calls onStep whenever new steps appear so callers can stream output.
102
- */
103
- async pollRun(agentId, runId, options = {}) {
104
- const intervalMs = options.intervalMs ?? 1500;
105
- const timeoutMs = options.timeoutMs ?? 5 * 60_000;
106
- const deadline = Date.now() + timeoutMs;
107
- let lastStepCount = -1;
108
- while (Date.now() < deadline) {
109
- const run = await this.getRun(agentId, runId);
110
- if (Array.isArray(run.steps) && run.steps.length !== lastStepCount) {
111
- lastStepCount = run.steps.length;
112
- options.onStep?.(run);
113
- }
114
- if (run.status && (TERMINAL_STATUSES.has(run.status) || run.status === 'waiting_input')) {
115
- return run;
116
- }
117
- await new Promise((r) => setTimeout(r, intervalMs));
118
- }
119
- throw new Error(`Run ${runId} did not finish within ${Math.round(timeoutMs / 1000)}s`);
120
- }
121
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Read shared almyty credentials from ~/.almyty/credentials.json.
3
- *
4
- * Identical to packages/auth-cli/src/credentials.ts (intentional copy
5
- * to keep each CLI package self-contained — these few helpers don't
6
- * justify a workspace dependency).
7
- */
8
- export declare const CREDENTIALS_FILE: string;
9
- export interface StoredCredentials {
10
- url: string;
11
- token: string;
12
- email?: string;
13
- frontendUrl?: string;
14
- }
15
- export declare function loadCredentials(): StoredCredentials | null;
16
- export declare function resolveCredentialsOrExit(): StoredCredentials;
@@ -1,34 +0,0 @@
1
- /**
2
- * Read shared almyty credentials from ~/.almyty/credentials.json.
3
- *
4
- * Identical to packages/auth-cli/src/credentials.ts (intentional copy
5
- * to keep each CLI package self-contained — these few helpers don't
6
- * justify a workspace dependency).
7
- */
8
- import { readFileSync, existsSync } from 'fs';
9
- import { homedir } from 'os';
10
- import { join } from 'path';
11
- export const CREDENTIALS_FILE = join(homedir(), '.almyty', 'credentials.json');
12
- export function loadCredentials() {
13
- try {
14
- if (!existsSync(CREDENTIALS_FILE))
15
- return null;
16
- return JSON.parse(readFileSync(CREDENTIALS_FILE, 'utf-8'));
17
- }
18
- catch {
19
- return null;
20
- }
21
- }
22
- export function resolveCredentialsOrExit() {
23
- const envToken = process.env.ALMYTY_TOKEN;
24
- const envUrl = process.env.ALMYTY_URL || 'https://api.almyty.com';
25
- if (envToken)
26
- return { url: envUrl, token: envToken };
27
- const stored = loadCredentials();
28
- if (stored?.token)
29
- return stored;
30
- console.error('Not authenticated. Run one of:');
31
- console.error(' npx @almyty/auth login');
32
- console.error(' export ALMYTY_TOKEN=<your-token>');
33
- process.exit(1);
34
- }