@artinet/sdk
Version:
A TypeScript SDK for building collaborative AI agents.
32 lines (31 loc) • 1.06 kB
JavaScript
/**
* Copyright 2025 The Artinet Project
* SPDX-License-Identifier: Apache-2.0
*/
import { getLatestHistory } from "../helpers/index.js";
import { INTERNAL_ERROR } from "../../../utils/index.js";
export const sendMessage = async ({ configuration }, context) => {
if (!context) {
throw INTERNAL_ERROR({ error: { message: "Context is required" } });
}
const service = context.service;
let task;
if (configuration?.blocking === false) {
task = await Promise.race([
service.execute({ engine: service.engine, context }).then(async () => {
return await context.getTask();
}),
new Promise((resolve) => {
context.publisher.on("start", (_, task) => {
resolve(task);
});
}),
]);
}
else {
await service.execute({ engine: service.engine, context });
task = await context.getTask();
}
task.history = getLatestHistory(task, configuration?.historyLength);
return task;
};