Skip to content

Commit c07bd01

Browse files
committed
++ genesis commit
0 parents  commit c07bd01

22 files changed

+4009
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "deps/a2a"]
2+
path = deps/a2a
3+
url = https://github.com/google/A2A.git

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Changelog
2+
3+
All notable changes to the @artinet/sdk package will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- Fixed TypeScript errors related to the eventsource-parser package imports
13+
- Updated imports to use the correct types from eventsource-parser v1.1.1
14+
- Properly typed the EventSourceMessage as ParsedEvent
15+
- Refactored createParser implementation to match the package's API
16+
- Fixed streaming response handler to use the correct event type checking
17+
18+
### Changed
19+
20+
- Updated tsconfig.json to add isolatedModules: true for better compatibility with ts-jest
21+
- Modified package.json test scripts to include NODE_OPTIONS=--experimental-vm-modules flag to support ES modules in Jest tests
22+
23+
### Improved
24+
25+
- Expanded test suite to achieve 95% code coverage
26+
- Added tests for all client methods
27+
- Added robust error handling tests
28+
- Added tests for streaming functionality
29+
- Added tests for push notification configuration
30+
- Added tests for edge cases in agent card fetching and capability detection
31+
32+
## [0.1.0] - 2023-04-23
33+
34+
### Added
35+
36+
- Initial release of the @artinet/sdk package
37+
- Implementation of the Agent2Agent (A2A) Protocol client
38+
- Support for sending tasks, retrieving statuses, and canceling operations
39+
- Support for streaming responses and push notifications
40+
- Comprehensive test suite and documentation
41+
42+
[Unreleased]: https://github.com/artinet/sdk/compare/v0.1.0...HEAD
43+
[0.1.0]: https://github.com/artinet/sdk/releases/tag/v0.1.0

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Artinet
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Artinet SDK
2+
3+
A TypeScript client library for the [Agent2Agent (A2A) Protocol](https://github.com/google/A2A) - an open protocol for communication between AI agents.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @artinet/sdk
9+
```
10+
11+
## Features
12+
13+
- Full implementation of the A2A Protocol using the official Google schema
14+
- TypeScript types for all protocol structures
15+
- Streaming support for real-time updates
16+
- Push notification capabilities
17+
- Built-in error handling
18+
- Flexible authentication mechanisms
19+
20+
## Usage
21+
22+
### Basic Usage
23+
24+
```typescript
25+
import { A2AClient, Message, Part, TaskSendParams } from "@artinet/sdk";
26+
27+
// Create a new client instance
28+
const client = new A2AClient("https://your-a2a-server.com");
29+
30+
// Get the agent card to discover capabilities
31+
const agentCard = await client.agentCard();
32+
console.log(`Connected to agent: ${agentCard.name}`);
33+
34+
// Check if the server supports streaming
35+
const supportsStreaming = await client.supports("streaming");
36+
37+
// Create a message to send
38+
const message: Message = {
39+
role: "user",
40+
parts: [
41+
{
42+
type: "text",
43+
text: "Hello! Can you help me with a question?",
44+
},
45+
],
46+
};
47+
48+
// Send a task
49+
const task = await client.sendTask({
50+
id: "task-123",
51+
message,
52+
});
53+
54+
console.log(`Task status: ${task?.status.state}`);
55+
```
56+
57+
### Streaming Updates
58+
59+
```typescript
60+
import { A2AClient, Message } from "@artinet/sdk";
61+
62+
const client = new A2AClient("https://your-a2a-server.com");
63+
64+
// Check if the server supports streaming
65+
if (await client.supports("streaming")) {
66+
const message = {
67+
role: "user",
68+
parts: [{ type: "text", text: "Tell me a story about space exploration" }],
69+
};
70+
71+
// Send a task and subscribe to updates
72+
const stream = client.sendTaskSubscribe({
73+
id: "streaming-task-123",
74+
message,
75+
});
76+
77+
// Process the updates as they arrive
78+
for await (const update of stream) {
79+
if ("status" in update) {
80+
console.log(`Task status: ${update.status.state}`);
81+
82+
// Display agent's response when available
83+
if (update.status.message) {
84+
const textParts = update.status.message.parts
85+
.filter((part) => part.type === "text")
86+
.map((part) => (part as any).text);
87+
88+
console.log("Agent response:", textParts.join("\n"));
89+
}
90+
} else if ("artifact" in update) {
91+
console.log("Received artifact:", update.artifact.name);
92+
}
93+
}
94+
}
95+
```
96+
97+
### Authentication
98+
99+
```typescript
100+
import { A2AClient } from "@artinet/sdk";
101+
102+
// Add authentication headers
103+
const client = new A2AClient("https://your-a2a-server.com");
104+
client.addHeader("Authorization", "Bearer your-token-here");
105+
106+
// Or set multiple headers at once
107+
client.setHeaders({
108+
Authorization: "Bearer your-token-here",
109+
"X-Custom-Header": "custom-value",
110+
});
111+
```
112+
113+
## Logging
114+
115+
The SDK uses [pino](https://github.com/pinojs/pino), a fast and low overhead logging library:
116+
117+
```typescript
118+
import { logger, configureLogger, LogLevel } from "@artinet/sdk";
119+
120+
// Configure the logger
121+
configureLogger({
122+
level: "debug", // Options: 'silent', 'error', 'warn', 'info', 'debug', 'trace'
123+
name: "MyApplication" // Optional custom logger name
124+
});
125+
126+
// Use the logger directly
127+
logger.info("Connection established");
128+
logger.error({ err: new Error("Failed to connect") }, "Connection error");
129+
logger.debug({ data: { id: 123, status: "active" } }, "Task details");
130+
131+
// In production, set a more restrictive level
132+
configureLogger({ level: "error" });
133+
// Or disable completely
134+
configureLogger({ level: "silent" });
135+
```
136+
137+
The default log level is 'error', which means only error messages and above are shown.
138+
139+
For more advanced configurations, you can access the pino logger instance directly:
140+
141+
```typescript
142+
import { logger } from "@artinet/sdk";
143+
import { pino } from "pino";
144+
145+
// Create a custom child logger
146+
const customLogger = logger.child({ module: "TaskProcessor" });
147+
customLogger.info("Processing started");
148+
```
149+
150+
## API Reference
151+
152+
### Classes
153+
154+
- `A2AClient` - Main client for interacting with A2A servers
155+
- `RpcError` - Error class for handling A2A protocol errors
156+
157+
### Utilities
158+
159+
- `logger` - Pino logger instance for SDK operations
160+
- `configureLogger()` - Utility function to configure the logger
161+
162+
## Contributing
163+
164+
Contributions are welcome! Please feel free to submit a Pull Request.
165+
166+
## License
167+
168+
This project is licensed under the MIT License - see the LICENSE file for details.
169+
170+
## Acknowledgements
171+
172+
This SDK directly incorporates the [official A2A Protocol schema](https://github.com/google/A2A/blob/main/samples/js/src/schema.ts) created by Google, ensuring complete compatibility with the specification.

deps/a2a

Submodule a2a added at 00200ad

examples/basic-usage.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Basic usage example for the Artinet SDK
3+
*
4+
* This example demonstrates how to:
5+
* - Create an A2AClient instance
6+
* - Get the agent card
7+
* - Send a simple task
8+
* - Handle the response
9+
*/
10+
11+
import { A2AClient } from "../dist/index.js";
12+
13+
async function main() {
14+
try {
15+
// Create a new client instance
16+
// Replace with your actual A2A server URL
17+
const client = new A2AClient("https://your-a2a-server.com");
18+
console.log("Client initialized");
19+
20+
// You can add authentication if required
21+
client.addHeader("Authorization", "Bearer your-token-here");
22+
23+
// Get the agent card to discover capabilities
24+
try {
25+
const agentCard = await client.agentCard();
26+
console.log(`Connected to agent: ${agentCard.name}`);
27+
console.log(`Agent version: ${agentCard.version}`);
28+
console.log(
29+
`Streaming supported: ${
30+
agentCard.capabilities.streaming ? "Yes" : "No"
31+
}`
32+
);
33+
} catch (error) {
34+
console.log("Could not retrieve agent card, continuing anyway...");
35+
}
36+
37+
// Create a message to send
38+
const message = {
39+
role: "user",
40+
parts: [
41+
{
42+
type: "text",
43+
text: "Hello! Can you help me with a question about climate change?",
44+
},
45+
],
46+
};
47+
48+
// Generate a unique task ID
49+
const taskId = `task-${Date.now()}`;
50+
51+
// Send a task
52+
console.log(`Sending task with ID: ${taskId}...`);
53+
54+
const task = await client.sendTask({
55+
id: taskId,
56+
message,
57+
});
58+
59+
if (task) {
60+
console.log(`Task status: ${task.status.state}`);
61+
62+
if (task.status.message) {
63+
// Extract the text parts from the response
64+
const textParts = task.status.message.parts
65+
.filter((part) => part.type === "text")
66+
.map((part) => part.text);
67+
68+
console.log("Agent response:", textParts.join("\n"));
69+
}
70+
} else {
71+
console.log("No task response received");
72+
}
73+
} catch (error) {
74+
console.error("Error:", error.message);
75+
}
76+
}
77+
78+
// Run the example
79+
main().catch(console.error);

0 commit comments

Comments
 (0)