@kddd/artinet-sdk
Version:
TypeScript SDK for the Agent2Agent (A2A) Protocol
65 lines • 3.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.testDeployment = testDeployment;
const a2a_client_js_1 = require("../../client/a2a-client.js");
const index_js_1 = require("../../transport/index.js");
const index_js_2 = require("../../index.js");
/**
* @fileoverview Provides a utility for testing agent deployments.
* This module allows developers to simulate the deployment of an agent's code
* to a sandboxed environment and then send test tasks to it to verify its behavior.
*/
const testExecuteStreamEvents = index_js_1.executeStreamEvents;
/**
* Tests an agent deployment by sending its code to a test deployment endpoint
* and then issuing a series of test task requests to the deployed agent.
*
* This function first initiates a deployment to `https://agents.artinet.io/test/deploy`,
* streaming deployment status events. Once a successful deployment event with a URL
* is received, it creates an `A2AClient` for that URL and sends each of the provided
* `SendTaskRequest`s to the deployed agent.
*
* It yields all events from the deployment stream and all resulting tasks from the
* test requests.
*
* @param params - The parameters for the server deployment, including the agent's
* name, agent card, and the bundled code.
* @param requests - An array of `SendTaskRequest` objects to be sent to the
* deployed agent for testing.
* @returns An asynchronous iterable that yields `ServerDeploymentResponse` events
* during the deployment phase, and `Task` objects resulting from the
* test requests. Yields `null` for other event types not explicitly handled.
*/
async function* testDeployment(params, requests) {
const generator = await testExecuteStreamEvents(new URL("https://agents.artinet.io/test/deploy"), "/test/deploy", params, {});
const requestExecutor = async (url) => async function* () {
const testClient = new a2a_client_js_1.A2AClient(url);
for (const request of requests) {
const task = await testClient.sendTask({
id: request.params.id,
message: request.params.message,
});
(0, index_js_2.logDebug)("testDeployment", "task: ", task);
yield task;
}
};
for await (const event of generator) {
const deploymentEvent = event;
if (deploymentEvent &&
deploymentEvent.result &&
deploymentEvent.result.deploymentId &&
deploymentEvent.result.url) {
(0, index_js_2.logDebug)("testDeployment", "deployment-event: ", deploymentEvent);
yield event;
const innerGenerator = await requestExecutor(deploymentEvent.result.url);
for await (const task of innerGenerator()) {
yield task;
}
}
else {
yield event;
(0, index_js_2.logDebug)("testDeployment", "event-received: ", event);
}
}
}
//# sourceMappingURL=test-deployment.js.map