agent-contracts-runtime
Version:
Runtime bridge for executing agent-contracts workflows on Agent SDKs
41 lines • 1.21 kB
JavaScript
// src/adapters/mock.ts
var MockAdapter = class {
responses;
defaultLatencyMs;
lastMemoryRef = null;
constructor(options) {
this.responses = options?.responses ?? {};
this.defaultLatencyMs = options?.defaultLatencyMs ?? 0;
}
async send(prompt, _options) {
const match = prompt.match(/## Task: (\S+)/);
const taskId = match?.[1] ?? "unknown";
const reqMatch = prompt.match(/## User Request\n\n([\s\S]*?)(?:\n\n---|$)/);
const userRequest = reqMatch?.[1]?.trim() ?? "";
if (this.defaultLatencyMs > 0) {
await new Promise((r) => setTimeout(r, this.defaultLatencyMs));
}
const responseFn = this.responses[taskId];
if (!responseFn) {
return `Task "${taskId}" completed but no structured output available.`;
}
const result = responseFn(userRequest);
this.lastMemoryRef = {
id: `mock-ref-${Date.now()}`,
provider: "mock",
compat: "mock@1",
created_at: (/* @__PURE__ */ new Date()).toISOString()
};
return result;
}
getLastMemoryRef() {
return this.lastMemoryRef;
}
isCompatible(compat) {
return compat.startsWith("mock@");
}
};
export {
MockAdapter
};
//# sourceMappingURL=mock.js.map