export async function runAgentScenario(runtime, ciSystem) {
console.log('[Agent] Starting CI build wait scenario');
console.log('[Agent] Creating callback capability for CI build completion');
const callback = await runtime.createCallback({
summary: 'Wait for CI build to complete',
source: 'ci-simulator',
condition: 'build_status != "running"',
delivery_mode: 'enqueue_message',
});
console.log('[Agent] Callback capability created:', {
waiting_intent_id: callback.waiting_intent_id,
callback_url: callback.callback_url,
});
const buildId = ciSystem.startBuild('holon/holon', 'abc123');
ciSystem.registerWebhook({
callbackUrl: callback.callback_url,
buildId,
expectedStatus: 'success',
});
console.log('[Agent] Build started and webhook registered');
console.log('[Agent] Waiting for build to complete...');
return {
waiting_intent_id: callback.waiting_intent_id,
callback_descriptor_id: callback.callback_descriptor_id,
buildId,
callback_url: callback.callback_url,
};
}
export function verifyCallback(message, expectedBuildId) {
console.log('[Agent] Verifying callback message');
if (message.origin?.type !== 'Callback') {
console.error('[Agent] Message origin is not Callback');
return false;
}
const payload = message.body.json;
if (!payload) {
console.error('[Agent] Message body is not JSON');
return false;
}
if (payload.buildId !== expectedBuildId) {
console.error('[Agent] Build ID mismatch:', {
expected: expectedBuildId,
received: payload.buildId,
});
return false;
}
if (payload.status !== 'success') {
console.error('[Agent] Build status is not success:', payload.status);
return false;
}
console.log('[Agent] Callback verified successfully');
return true;
}
export async function cleanupCallback(runtime, waitingIntentId) {
console.log('[Agent] Cancelling waiting intent');
const result = await runtime.cancelWaiting(waitingIntentId);
console.log('[Agent] Waiting intent cancelled:', result);
return result;
}