@artinet/ask 0.0.9 → 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 +10 -9
- package/dist/src/chat.d.ts +2 -2
- package/dist/src/chat.js +40 -37
- package/dist/src/cli.js +23 -21
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +2 -2
- package/package.json +64 -63
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://artinet.io"><img src="https://img.shields.io/badge/website-artinet.io-black" alt="Website"></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/@artinet/ask"><img src="https://img.shields.io/npm/v/@artinet/ask?color=black" alt="Version"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@artinet/ask"><img src="https://img.shields.io/npm/dt/@artinet/ask?color=black" alt="Downloads"></a>
|
|
6
|
+
<a><img src="https://img.shields.io/badge/License-Apache_2.0-black.svg" alt="License"></a>
|
|
7
|
+
<a href="https://snyk.io/test/npm/@artinet/ask"><img src="https://snyk.io/test/npm/@artinet/ask/badge.svg" alt="Known Vulnerabilities"></a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<h1 align="center"><em>ask</em></h1>
|
|
10
11
|
|
|
11
12
|
A light-weight/minimalist commandline client for connecting to local and remote Agent2Agent (A2A) Servers.
|
|
12
13
|
|
package/dist/src/chat.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function chat(agentCard: AgentCard, client:
|
|
1
|
+
import * as sdk from '@artinet/sdk';
|
|
2
|
+
export declare function chat(agentCard: sdk.A2A.AgentCard, client: sdk.AgentMessenger, taskId?: string, verbose?: boolean, message?: string | undefined): Promise<void>;
|
package/dist/src/chat.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import chalk from
|
|
3
|
-
import prompts from
|
|
4
|
-
import { v4 as uuidv4 } from
|
|
1
|
+
import * as sdk from '@artinet/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import prompts from 'prompts';
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
+
// sdk.applyDefaults();
|
|
5
6
|
function getTaskState(update) {
|
|
6
7
|
const state = update?.status?.state ??
|
|
7
8
|
update?.status?.state ??
|
|
@@ -9,44 +10,44 @@ function getTaskState(update) {
|
|
|
9
10
|
return state;
|
|
10
11
|
}
|
|
11
12
|
function createBanner(kind, state, verbose = false) {
|
|
12
|
-
let banner =
|
|
13
|
+
let banner = '';
|
|
13
14
|
if (verbose) {
|
|
14
15
|
banner =
|
|
15
|
-
chalk.bgWhite(chalk.grey(`📥 Type: ${chalk.bgWhiteBright(chalk.black(kind.toUpperCase().replace(
|
|
16
|
+
chalk.bgWhite(chalk.grey(`📥 Type: ${chalk.bgWhiteBright(chalk.black(kind.toUpperCase().replace('-', ' ')))}`)) + ' ';
|
|
16
17
|
}
|
|
17
18
|
if (state) {
|
|
18
19
|
switch (state) {
|
|
19
|
-
case TaskState.canceled:
|
|
20
|
+
case sdk.A2A.TaskState.canceled:
|
|
20
21
|
banner = chalk.bgYellowBright(`${state.toUpperCase()}`);
|
|
21
22
|
break;
|
|
22
|
-
case TaskState.failed:
|
|
23
|
+
case sdk.A2A.TaskState.failed:
|
|
23
24
|
banner = chalk.bgRed(`${state.toUpperCase()}`);
|
|
24
25
|
break;
|
|
25
|
-
case TaskState.rejected:
|
|
26
|
+
case sdk.A2A.TaskState.rejected:
|
|
26
27
|
banner = chalk.bgRed(`${state.toUpperCase()}`);
|
|
27
28
|
break;
|
|
28
|
-
case TaskState[
|
|
29
|
+
case sdk.A2A.TaskState['auth-required']:
|
|
29
30
|
banner = chalk.bgMagenta(`${state.toUpperCase()}`);
|
|
30
31
|
break;
|
|
31
|
-
case TaskState.unknown:
|
|
32
|
+
case sdk.A2A.TaskState.unknown:
|
|
32
33
|
banner = chalk.bgRedBright(`${state.toUpperCase()}`);
|
|
33
34
|
break;
|
|
34
|
-
case TaskState.submitted:
|
|
35
|
+
case sdk.A2A.TaskState.submitted:
|
|
35
36
|
banner = chalk.bgYellow(chalk.black(`${state.toUpperCase()}`));
|
|
36
37
|
break;
|
|
37
|
-
case TaskState[
|
|
38
|
+
case sdk.A2A.TaskState['input-required']:
|
|
38
39
|
banner = chalk.bgMagenta(chalk.black(`${state.toUpperCase()}`));
|
|
39
40
|
break;
|
|
40
|
-
case TaskState.working:
|
|
41
|
+
case sdk.A2A.TaskState.working:
|
|
41
42
|
banner = chalk.bgBlueBright(`${state.toUpperCase()}`);
|
|
42
43
|
break;
|
|
43
|
-
case TaskState.completed:
|
|
44
|
+
case sdk.A2A.TaskState.completed:
|
|
44
45
|
banner = chalk.bgGreen(`${state.toUpperCase()}`);
|
|
45
46
|
break;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
if (banner.length > 0 && banner[banner.length - 1] !==
|
|
49
|
-
return banner +
|
|
49
|
+
if (banner.length > 0 && banner[banner.length - 1] !== ' ') {
|
|
50
|
+
return banner + ' ';
|
|
50
51
|
}
|
|
51
52
|
return banner;
|
|
52
53
|
}
|
|
@@ -54,9 +55,9 @@ async function sendMessage(client, message, taskId, verbose = false) {
|
|
|
54
55
|
const msg = {
|
|
55
56
|
messageId: uuidv4(),
|
|
56
57
|
taskId: taskId,
|
|
57
|
-
kind:
|
|
58
|
-
role:
|
|
59
|
-
parts: [{ text: message, kind:
|
|
58
|
+
kind: sdk.A2A.Kind.message,
|
|
59
|
+
role: 'user',
|
|
60
|
+
parts: [{ text: message, kind: 'text' }],
|
|
60
61
|
};
|
|
61
62
|
if (verbose) {
|
|
62
63
|
console.log(chalk.bgWhite(chalk.black(`📤 Sending message: ${msg.messageId}`)));
|
|
@@ -65,17 +66,17 @@ async function sendMessage(client, message, taskId, verbose = false) {
|
|
|
65
66
|
message: msg,
|
|
66
67
|
});
|
|
67
68
|
if (!agentResponseSource) {
|
|
68
|
-
console.error(chalk.red(
|
|
69
|
+
console.error(chalk.red('No response from agent'));
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
72
|
const banner = createBanner(agentResponseSource.kind, getTaskState(agentResponseSource), verbose);
|
|
72
|
-
console.log(banner + chalk.gray(
|
|
73
|
+
console.log(banner + chalk.gray('Agent: ') + sdk.extractTextContent(agentResponseSource));
|
|
73
74
|
console.log();
|
|
74
75
|
}
|
|
75
76
|
export async function chat(agentCard, client, taskId = uuidv4(), verbose = false, message = undefined) {
|
|
76
77
|
if (!client) {
|
|
77
|
-
console.error(chalk.red(
|
|
78
|
-
throw new Error(
|
|
78
|
+
console.error(chalk.red('No client provided'));
|
|
79
|
+
throw new Error('chat: no client provided');
|
|
79
80
|
}
|
|
80
81
|
const name = agentCard.name;
|
|
81
82
|
const version = agentCard.version;
|
|
@@ -94,42 +95,44 @@ export async function chat(agentCard, client, taskId = uuidv4(), verbose = false
|
|
|
94
95
|
console.log(chalk.bgGray("Chat started: Type 'exit' to quit.\n"));
|
|
95
96
|
while (true) {
|
|
96
97
|
const response = await prompts({
|
|
97
|
-
type:
|
|
98
|
-
name:
|
|
99
|
-
message:
|
|
98
|
+
type: 'text',
|
|
99
|
+
name: 'message',
|
|
100
|
+
message: 'User:',
|
|
100
101
|
});
|
|
101
|
-
if (!response.message || response.message.trim().toLowerCase() ===
|
|
102
|
+
if (!response.message || response.message.trim().toLowerCase() === 'exit') {
|
|
102
103
|
break;
|
|
103
104
|
}
|
|
104
105
|
const msg = {
|
|
105
106
|
messageId: uuidv4(),
|
|
106
107
|
taskId: taskId,
|
|
107
|
-
kind:
|
|
108
|
-
role:
|
|
109
|
-
parts: [{ text: response.message, kind:
|
|
108
|
+
kind: sdk.A2A.Kind.message,
|
|
109
|
+
role: 'user',
|
|
110
|
+
parts: [{ text: response.message, kind: 'text' }],
|
|
110
111
|
};
|
|
111
112
|
console.log();
|
|
112
113
|
if (verbose) {
|
|
113
114
|
console.log(chalk.bgWhite(chalk.black(`📤 Sending message: ${msg.messageId}`)));
|
|
114
115
|
}
|
|
115
116
|
try {
|
|
116
|
-
const agentResponseSource = client.
|
|
117
|
+
const agentResponseSource = client.sendMessageStream({
|
|
118
|
+
message: msg,
|
|
119
|
+
});
|
|
117
120
|
for await (const update of agentResponseSource) {
|
|
118
121
|
const banner = createBanner(update.kind, getTaskState(update), verbose);
|
|
119
|
-
if ((update.kind ===
|
|
122
|
+
if ((update.kind === 'message' || update.kind === 'task') && !verbose) {
|
|
120
123
|
continue;
|
|
121
124
|
}
|
|
122
|
-
const response =
|
|
125
|
+
const response = sdk.extractTextContent(update) ?? 'No response';
|
|
123
126
|
if (response) {
|
|
124
|
-
console.log(banner + chalk.gray(
|
|
127
|
+
console.log(banner + chalk.gray('Agent: ') + response);
|
|
125
128
|
}
|
|
126
129
|
else if (verbose && banner.length > 0) {
|
|
127
|
-
console.log(banner + chalk.gray(
|
|
130
|
+
console.log(banner + chalk.gray('Status Update: ☑️'));
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
catch (error) {
|
|
132
|
-
console.error(chalk.red(
|
|
135
|
+
console.error(chalk.red('Error sending message: ') + error);
|
|
133
136
|
}
|
|
134
137
|
console.log();
|
|
135
138
|
}
|
package/dist/src/cli.js
CHANGED
|
@@ -4,36 +4,38 @@
|
|
|
4
4
|
* Copyright 2025 The Artinet Project
|
|
5
5
|
* SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
8
|
-
import { Command } from
|
|
9
|
-
import { chat } from
|
|
10
|
-
import chalk from
|
|
7
|
+
import * as sdk from '@artinet/sdk';
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { chat } from './chat.js';
|
|
10
|
+
import chalk from 'chalk';
|
|
11
11
|
const program = new Command();
|
|
12
12
|
program
|
|
13
|
-
.name(
|
|
14
|
-
.description(
|
|
15
|
-
.version(
|
|
16
|
-
.option(
|
|
17
|
-
.option(
|
|
18
|
-
.option(
|
|
19
|
-
.option(
|
|
20
|
-
.option(
|
|
13
|
+
.name('ask')
|
|
14
|
+
.description('A lightweight chat client for connecting to A2A Servers')
|
|
15
|
+
.version('0.1.6')
|
|
16
|
+
.option('-v, --verbose', 'Enable verbose output')
|
|
17
|
+
.option('-t, --task <taskId>', 'Set the task ID')
|
|
18
|
+
.option('-e, --endpoint <endpoint>', 'Set the A2A endpoint (default: http://localhost:3000/a2a)')
|
|
19
|
+
.option('-c, --card', 'Show the agent card')
|
|
20
|
+
.option('-m, --message <message>', 'Send a single message and exit')
|
|
21
21
|
.action(async (options) => {
|
|
22
22
|
let client;
|
|
23
23
|
try {
|
|
24
|
-
client =
|
|
24
|
+
client = await sdk.createMessenger({
|
|
25
|
+
baseUrl: options?.endpoint ?? 'http://localhost:3000/a2a',
|
|
26
|
+
});
|
|
25
27
|
}
|
|
26
28
|
catch (error) {
|
|
27
|
-
console.error(chalk.red(
|
|
29
|
+
console.error(chalk.red('Error creating client:'));
|
|
28
30
|
console.error(error instanceof Error ? error.message : String(error));
|
|
29
31
|
process.exit(1);
|
|
30
32
|
}
|
|
31
33
|
if (!client) {
|
|
32
|
-
console.error(chalk.red(
|
|
34
|
+
console.error(chalk.red('Failed to create client'));
|
|
33
35
|
process.exit(1);
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
console.error(chalk.red(
|
|
37
|
+
let agentCard = await client.getAgentCard().catch((error) => {
|
|
38
|
+
console.error(chalk.red('Error getting agent card:'));
|
|
37
39
|
console.error(error instanceof Error ? error.message : String(error));
|
|
38
40
|
process.exit(1);
|
|
39
41
|
});
|
|
@@ -49,12 +51,12 @@ program.configureHelp({
|
|
|
49
51
|
sortSubcommands: true,
|
|
50
52
|
showGlobalOptions: false,
|
|
51
53
|
});
|
|
52
|
-
program.on(
|
|
53
|
-
console.error(chalk.red(`Unknown command: ${program.args.join(
|
|
54
|
-
console.log(chalk.yellow(
|
|
54
|
+
program.on('command:*', () => {
|
|
55
|
+
console.error(chalk.red(`Unknown command: ${program.args.join(' ')}`));
|
|
56
|
+
console.log(chalk.yellow('See --help for available commands.'));
|
|
55
57
|
process.exit(1);
|
|
56
58
|
});
|
|
57
|
-
program.on(
|
|
59
|
+
program.on('exit', () => {
|
|
58
60
|
console.error(chalk.red(`Exiting...`));
|
|
59
61
|
process.exit(0);
|
|
60
62
|
});
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './chat.js';
|
|
2
|
+
export * from './cli.js';
|
package/dist/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './chat.js';
|
|
2
|
+
export * from './cli.js';
|
package/package.json
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
2
|
+
"name": "@artinet/ask",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "A lightweight command-line chat client for connecting to A2A Servers.",
|
|
5
|
+
"author": "artinet",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/the-artinet-project/artinet"
|
|
10
|
+
},
|
|
11
|
+
"issues": {
|
|
12
|
+
"url": "https://github.com/the-artinet-project/artinetissues"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"package.json",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"bin": {
|
|
21
|
+
"ask": "./dist/src/cli.js"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"ask",
|
|
25
|
+
"artinet",
|
|
26
|
+
"chat",
|
|
27
|
+
"a2a",
|
|
28
|
+
"agent2agent",
|
|
29
|
+
"agent",
|
|
30
|
+
"ai",
|
|
31
|
+
"artificial intelligence"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20.0.0"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"main": "./dist/src/index.js",
|
|
38
|
+
"module": "./dist/src/index.js",
|
|
39
|
+
"types": "./dist/src/index.d.ts",
|
|
40
|
+
"rootDir": ".",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"prepublishOnly": "npm run clean:all && npm i && npm run build",
|
|
43
|
+
"build": "tsc --project tsconfig.json",
|
|
44
|
+
"postbuild": "chmod +x dist/src/cli.js",
|
|
45
|
+
"clean": "rimraf dist",
|
|
46
|
+
"clean:all": "rimraf dist node_modules package-lock.json",
|
|
47
|
+
"dev": "tsx src/cli.ts",
|
|
48
|
+
"dev:server": "tsx src/test-server.ts",
|
|
49
|
+
"ask": "node dist/src/cli.js"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@artinet/sdk": "^0.6.4",
|
|
53
|
+
"chalk": "^5.6.2",
|
|
54
|
+
"commander": "^14.0.1",
|
|
55
|
+
"prompts": "^2.4.2",
|
|
56
|
+
"uuid": "^13.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/node": "^25.0.9",
|
|
60
|
+
"@types/prompts": "^2.4.9",
|
|
61
|
+
"rimraf": "^6.1.2",
|
|
62
|
+
"ts-node": "^10.9.2",
|
|
63
|
+
"tsx": "^4.21.0",
|
|
64
|
+
"typescript": "^5.9.3"
|
|
65
|
+
}
|
|
65
66
|
}
|