@bluecopa/harness 2.0.1-snapshot.2 → 2.0.1-snapshot.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/arc/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { tool, generateText, stepCountIs, streamText } from 'ai';
|
|
2
2
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import {
|
|
4
|
+
import { randomUUID, createHash } from 'crypto';
|
|
5
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
5
6
|
import * as fs from 'fs/promises';
|
|
6
7
|
import * as path from 'path';
|
|
7
8
|
|
|
@@ -2140,6 +2141,73 @@ var MemorySessionStore = class {
|
|
|
2140
2141
|
return [...this.metas.values()].sort((a, b) => b.lastActiveAt - a.lastActiveAt);
|
|
2141
2142
|
}
|
|
2142
2143
|
};
|
|
2144
|
+
var InMemoryEpisodeStore = class {
|
|
2145
|
+
episodes = /* @__PURE__ */ new Map();
|
|
2146
|
+
traces = /* @__PURE__ */ new Map();
|
|
2147
|
+
async addEpisode(episode) {
|
|
2148
|
+
this.episodes.set(episode.id, episode);
|
|
2149
|
+
}
|
|
2150
|
+
async addTrace(trace) {
|
|
2151
|
+
this.traces.set(trace.episodeId, trace);
|
|
2152
|
+
}
|
|
2153
|
+
async getEpisode(id) {
|
|
2154
|
+
return this.episodes.get(id) ?? null;
|
|
2155
|
+
}
|
|
2156
|
+
async getTrace(episodeId) {
|
|
2157
|
+
return this.traces.get(episodeId) ?? null;
|
|
2158
|
+
}
|
|
2159
|
+
async getEpisodesByTask(taskId) {
|
|
2160
|
+
return [...this.episodes.values()].filter((e) => e.taskId === taskId);
|
|
2161
|
+
}
|
|
2162
|
+
async getEpisodesBySession(sessionId) {
|
|
2163
|
+
return [...this.episodes.values()].filter((e) => e.sessionId === sessionId);
|
|
2164
|
+
}
|
|
2165
|
+
async getRecentEpisodes(limit) {
|
|
2166
|
+
return [...this.episodes.values()].sort((a, b) => b.createdAt - a.createdAt).slice(0, limit);
|
|
2167
|
+
}
|
|
2168
|
+
async evictTraces(_olderThan) {
|
|
2169
|
+
return 0;
|
|
2170
|
+
}
|
|
2171
|
+
};
|
|
2172
|
+
var InMemorySessionMemoStore = class {
|
|
2173
|
+
memos = /* @__PURE__ */ new Map();
|
|
2174
|
+
async addMemo(memo) {
|
|
2175
|
+
this.memos.set(memo.id, memo);
|
|
2176
|
+
}
|
|
2177
|
+
async getMemo(id) {
|
|
2178
|
+
return this.memos.get(id) ?? null;
|
|
2179
|
+
}
|
|
2180
|
+
async getMemosBySession(sessionId) {
|
|
2181
|
+
return [...this.memos.values()].filter((m) => m.sessionId === sessionId);
|
|
2182
|
+
}
|
|
2183
|
+
async getRecentMemos(limit) {
|
|
2184
|
+
return [...this.memos.values()].sort((a, b) => b.createdAt - a.createdAt).slice(0, limit);
|
|
2185
|
+
}
|
|
2186
|
+
};
|
|
2187
|
+
var InMemoryLongTermStore = class {
|
|
2188
|
+
memories = /* @__PURE__ */ new Map();
|
|
2189
|
+
async addMemory(memory) {
|
|
2190
|
+
this.memories.set(memory.id, memory);
|
|
2191
|
+
}
|
|
2192
|
+
async getMemory(id) {
|
|
2193
|
+
return this.memories.get(id) ?? null;
|
|
2194
|
+
}
|
|
2195
|
+
async getAllMemories() {
|
|
2196
|
+
return [...this.memories.values()];
|
|
2197
|
+
}
|
|
2198
|
+
async getMemoriesByCategory(category) {
|
|
2199
|
+
return [...this.memories.values()].filter((m) => m.category === category);
|
|
2200
|
+
}
|
|
2201
|
+
async updateMemory(id, updates) {
|
|
2202
|
+
const existing = this.memories.get(id);
|
|
2203
|
+
if (existing) {
|
|
2204
|
+
this.memories.set(id, { ...existing, ...updates });
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
async deleteMemory(id) {
|
|
2208
|
+
this.memories.delete(id);
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2143
2211
|
|
|
2144
2212
|
// src/arc/jobs/memory-job-registry.js
|
|
2145
2213
|
var MemoryJobRegistry = class {
|
|
@@ -4896,6 +4964,91 @@ function extractReasoningText(result) {
|
|
|
4896
4964
|
}
|
|
4897
4965
|
return "";
|
|
4898
4966
|
}
|
|
4967
|
+
|
|
4968
|
+
// src/hooks/hook-runner.ts
|
|
4969
|
+
var HookRunner = class {
|
|
4970
|
+
hooks = /* @__PURE__ */ new Map();
|
|
4971
|
+
register(event, callback) {
|
|
4972
|
+
const list = this.hooks.get(event) ?? [];
|
|
4973
|
+
list.push(callback);
|
|
4974
|
+
this.hooks.set(event, list);
|
|
4975
|
+
}
|
|
4976
|
+
async run(context) {
|
|
4977
|
+
const list = this.hooks.get(context.event) ?? [];
|
|
4978
|
+
for (const hook of list) {
|
|
4979
|
+
const result = await hook(context);
|
|
4980
|
+
if (result && result.allow === false) {
|
|
4981
|
+
return result;
|
|
4982
|
+
}
|
|
4983
|
+
}
|
|
4984
|
+
return { allow: true };
|
|
4985
|
+
}
|
|
4986
|
+
};
|
|
4987
|
+
var HarnessTelemetry = class {
|
|
4988
|
+
constructor(enabled = true) {
|
|
4989
|
+
this.enabled = enabled;
|
|
4990
|
+
}
|
|
4991
|
+
context = new AsyncLocalStorage();
|
|
4992
|
+
spans = [];
|
|
4993
|
+
metrics = [];
|
|
4994
|
+
isEnabled() {
|
|
4995
|
+
return this.enabled;
|
|
4996
|
+
}
|
|
4997
|
+
startSpan(name, attributes = {}) {
|
|
4998
|
+
const now = Date.now();
|
|
4999
|
+
const parent = this.context.getStore();
|
|
5000
|
+
const traceId = parent?.traceId ?? randomUUID().replace(/-/g, "");
|
|
5001
|
+
const spanId = randomUUID().replace(/-/g, "").slice(0, 16);
|
|
5002
|
+
const record = {
|
|
5003
|
+
traceId,
|
|
5004
|
+
spanId,
|
|
5005
|
+
parentSpanId: parent?.spanId,
|
|
5006
|
+
name,
|
|
5007
|
+
attributes: { ...attributes },
|
|
5008
|
+
startTime: now,
|
|
5009
|
+
endTime: now
|
|
5010
|
+
};
|
|
5011
|
+
this.spans.push(record);
|
|
5012
|
+
return {
|
|
5013
|
+
traceId,
|
|
5014
|
+
spanId,
|
|
5015
|
+
end: (extra = {}) => {
|
|
5016
|
+
record.endTime = Date.now();
|
|
5017
|
+
record.attributes = { ...record.attributes, ...extra };
|
|
5018
|
+
}
|
|
5019
|
+
};
|
|
5020
|
+
}
|
|
5021
|
+
async withSpan(name, attributes, fn) {
|
|
5022
|
+
if (!this.enabled) {
|
|
5023
|
+
return fn();
|
|
5024
|
+
}
|
|
5025
|
+
const span = this.startSpan(name, attributes);
|
|
5026
|
+
return this.context.run({ traceId: span.traceId, spanId: span.spanId }, async () => {
|
|
5027
|
+
try {
|
|
5028
|
+
const result = await fn();
|
|
5029
|
+
span.end({ success: true });
|
|
5030
|
+
return result;
|
|
5031
|
+
} catch (error) {
|
|
5032
|
+
span.end({ success: false, error: error instanceof Error ? error.message : "unknown" });
|
|
5033
|
+
throw error;
|
|
5034
|
+
}
|
|
5035
|
+
});
|
|
5036
|
+
}
|
|
5037
|
+
counter(name, value = 1, attributes = {}) {
|
|
5038
|
+
if (!this.enabled) return;
|
|
5039
|
+
this.metrics.push({ name, value, type: "counter", attributes });
|
|
5040
|
+
}
|
|
5041
|
+
histogram(name, value, attributes = {}) {
|
|
5042
|
+
if (!this.enabled) return;
|
|
5043
|
+
this.metrics.push({ name, value, type: "histogram", attributes });
|
|
5044
|
+
}
|
|
5045
|
+
getSpans() {
|
|
5046
|
+
return [...this.spans];
|
|
5047
|
+
}
|
|
5048
|
+
getMetrics() {
|
|
5049
|
+
return [...this.metrics];
|
|
5050
|
+
}
|
|
5051
|
+
};
|
|
4899
5052
|
var FsTranscriptStore = class {
|
|
4900
5053
|
dir;
|
|
4901
5054
|
indexPath;
|
|
@@ -4981,6 +5134,259 @@ var FsArtifactStore = class {
|
|
|
4981
5134
|
}
|
|
4982
5135
|
};
|
|
4983
5136
|
|
|
4984
|
-
|
|
5137
|
+
// src/arc/composite-tool-provider.ts
|
|
5138
|
+
var CompositeToolProvider = class {
|
|
5139
|
+
providers;
|
|
5140
|
+
constructor(providers) {
|
|
5141
|
+
this.providers = providers;
|
|
5142
|
+
}
|
|
5143
|
+
capabilities() {
|
|
5144
|
+
return this.providers.reduce(
|
|
5145
|
+
(acc, p) => {
|
|
5146
|
+
const c = p.capabilities();
|
|
5147
|
+
return {
|
|
5148
|
+
bash: acc.bash || c.bash,
|
|
5149
|
+
fileSystem: acc.fileSystem || c.fileSystem,
|
|
5150
|
+
webFetch: acc.webFetch || c.webFetch,
|
|
5151
|
+
webSearch: acc.webSearch || c.webSearch,
|
|
5152
|
+
codeExecution: acc.codeExecution || c.codeExecution,
|
|
5153
|
+
sandboxed: acc.sandboxed || c.sandboxed
|
|
5154
|
+
};
|
|
5155
|
+
},
|
|
5156
|
+
{
|
|
5157
|
+
bash: false,
|
|
5158
|
+
fileSystem: false,
|
|
5159
|
+
webFetch: false,
|
|
5160
|
+
webSearch: false,
|
|
5161
|
+
codeExecution: false,
|
|
5162
|
+
sandboxed: false
|
|
5163
|
+
}
|
|
5164
|
+
);
|
|
5165
|
+
}
|
|
5166
|
+
/** Pick the first provider that supports the requested capability. */
|
|
5167
|
+
pick(capability) {
|
|
5168
|
+
const provider = this.providers.find((p) => p.capabilities()[capability]);
|
|
5169
|
+
if (!provider) {
|
|
5170
|
+
throw new Error(`No provider supports capability: ${capability}`);
|
|
5171
|
+
}
|
|
5172
|
+
return provider;
|
|
5173
|
+
}
|
|
5174
|
+
async bash(command, options) {
|
|
5175
|
+
return this.pick("bash").bash(command, options);
|
|
5176
|
+
}
|
|
5177
|
+
async readFile(path2, options) {
|
|
5178
|
+
return this.pick("fileSystem").readFile(path2, options);
|
|
5179
|
+
}
|
|
5180
|
+
async writeFile(path2, content) {
|
|
5181
|
+
return this.pick("fileSystem").writeFile(path2, content);
|
|
5182
|
+
}
|
|
5183
|
+
async editFile(path2, oldText, newText) {
|
|
5184
|
+
return this.pick("fileSystem").editFile(path2, oldText, newText);
|
|
5185
|
+
}
|
|
5186
|
+
async glob(pattern, options) {
|
|
5187
|
+
return this.pick("fileSystem").glob(pattern, options);
|
|
5188
|
+
}
|
|
5189
|
+
async grep(pattern, path2, options) {
|
|
5190
|
+
return this.pick("fileSystem").grep(pattern, path2, options);
|
|
5191
|
+
}
|
|
5192
|
+
};
|
|
5193
|
+
|
|
5194
|
+
// src/arc/e2b-tool-provider.ts
|
|
5195
|
+
var E2BToolProvider = class {
|
|
5196
|
+
constructor(executor) {
|
|
5197
|
+
this.executor = executor;
|
|
5198
|
+
}
|
|
5199
|
+
capabilities() {
|
|
5200
|
+
return {
|
|
5201
|
+
bash: true,
|
|
5202
|
+
fileSystem: true,
|
|
5203
|
+
webFetch: false,
|
|
5204
|
+
webSearch: false,
|
|
5205
|
+
codeExecution: true,
|
|
5206
|
+
sandboxed: true
|
|
5207
|
+
};
|
|
5208
|
+
}
|
|
5209
|
+
async bash(command, options) {
|
|
5210
|
+
return this.executor.bash(command, options);
|
|
5211
|
+
}
|
|
5212
|
+
async readFile(path2, options) {
|
|
5213
|
+
return this.executor.readFile(path2, options);
|
|
5214
|
+
}
|
|
5215
|
+
async writeFile(path2, content) {
|
|
5216
|
+
return this.executor.writeFile(path2, content);
|
|
5217
|
+
}
|
|
5218
|
+
async editFile(path2, oldText, newText) {
|
|
5219
|
+
return this.executor.editFile(path2, oldText, newText);
|
|
5220
|
+
}
|
|
5221
|
+
async glob(pattern, options) {
|
|
5222
|
+
return this.executor.glob(pattern, options);
|
|
5223
|
+
}
|
|
5224
|
+
async grep(pattern, path2, options) {
|
|
5225
|
+
return this.executor.grep(pattern, path2, options);
|
|
5226
|
+
}
|
|
5227
|
+
};
|
|
5228
|
+
|
|
5229
|
+
// src/arc/control-plane-e2b-executor.ts
|
|
5230
|
+
var ControlPlaneE2BExecutor = class {
|
|
5231
|
+
baseUrl;
|
|
5232
|
+
apiKey;
|
|
5233
|
+
templateId;
|
|
5234
|
+
constructor(options) {
|
|
5235
|
+
this.baseUrl = options.baseUrl;
|
|
5236
|
+
this.apiKey = options.apiKey;
|
|
5237
|
+
this.templateId = options.templateId ?? "polyglot-v1";
|
|
5238
|
+
}
|
|
5239
|
+
async bash(_command, _options) {
|
|
5240
|
+
throw new Error(
|
|
5241
|
+
"ControlPlaneE2BExecutor.bash() not implemented \u2014 use a concrete subclass"
|
|
5242
|
+
);
|
|
5243
|
+
}
|
|
5244
|
+
async readFile(_path, _options) {
|
|
5245
|
+
throw new Error("ControlPlaneE2BExecutor.readFile() not implemented");
|
|
5246
|
+
}
|
|
5247
|
+
async writeFile(_path, _content) {
|
|
5248
|
+
throw new Error("ControlPlaneE2BExecutor.writeFile() not implemented");
|
|
5249
|
+
}
|
|
5250
|
+
async editFile(_path, _oldText, _newText) {
|
|
5251
|
+
throw new Error("ControlPlaneE2BExecutor.editFile() not implemented");
|
|
5252
|
+
}
|
|
5253
|
+
async glob(_pattern, _options) {
|
|
5254
|
+
throw new Error("ControlPlaneE2BExecutor.glob() not implemented");
|
|
5255
|
+
}
|
|
5256
|
+
async grep(_pattern, _path, _options) {
|
|
5257
|
+
throw new Error("ControlPlaneE2BExecutor.grep() not implemented");
|
|
5258
|
+
}
|
|
5259
|
+
async writeFileBytes(_path, _data) {
|
|
5260
|
+
throw new Error("ControlPlaneE2BExecutor.writeFileBytes() not implemented");
|
|
5261
|
+
}
|
|
5262
|
+
async readFileBytes(_path) {
|
|
5263
|
+
throw new Error("ControlPlaneE2BExecutor.readFileBytes() not implemented");
|
|
5264
|
+
}
|
|
5265
|
+
get activeSandboxId() {
|
|
5266
|
+
return void 0;
|
|
5267
|
+
}
|
|
5268
|
+
async destroy() {
|
|
5269
|
+
}
|
|
5270
|
+
};
|
|
5271
|
+
|
|
5272
|
+
// src/arc/permission-manager.ts
|
|
5273
|
+
var PermissionManager = class {
|
|
5274
|
+
mode;
|
|
5275
|
+
resolver;
|
|
5276
|
+
constructor(mode, resolver) {
|
|
5277
|
+
this.mode = mode;
|
|
5278
|
+
this.resolver = resolver;
|
|
5279
|
+
}
|
|
5280
|
+
/** Check whether a tool call is permitted. */
|
|
5281
|
+
async canExecute(request) {
|
|
5282
|
+
switch (this.mode) {
|
|
5283
|
+
case "deny_all":
|
|
5284
|
+
return false;
|
|
5285
|
+
case "allow_all":
|
|
5286
|
+
return true;
|
|
5287
|
+
case "ask":
|
|
5288
|
+
if (this.resolver) {
|
|
5289
|
+
return this.resolver(request);
|
|
5290
|
+
}
|
|
5291
|
+
return false;
|
|
5292
|
+
default:
|
|
5293
|
+
return false;
|
|
5294
|
+
}
|
|
5295
|
+
}
|
|
5296
|
+
};
|
|
5297
|
+
|
|
5298
|
+
// src/arc/resilience.ts
|
|
5299
|
+
var ResiliencePipeline = class {
|
|
5300
|
+
options;
|
|
5301
|
+
constructor(options = {}) {
|
|
5302
|
+
this.options = options;
|
|
5303
|
+
}
|
|
5304
|
+
/** Set a timeout in milliseconds for execution. */
|
|
5305
|
+
timeout(ms) {
|
|
5306
|
+
this.options.timeout = ms;
|
|
5307
|
+
return this;
|
|
5308
|
+
}
|
|
5309
|
+
/** Set retry count. */
|
|
5310
|
+
retries(count) {
|
|
5311
|
+
this.options.retryCount = count;
|
|
5312
|
+
return this;
|
|
5313
|
+
}
|
|
5314
|
+
/** Build the executable pipeline. */
|
|
5315
|
+
build() {
|
|
5316
|
+
const { timeout: timeoutMs, retryCount = 0 } = this.options;
|
|
5317
|
+
return {
|
|
5318
|
+
execute: async (fn, ctx) => {
|
|
5319
|
+
let lastError;
|
|
5320
|
+
for (let attempt = 0; attempt <= retryCount; attempt++) {
|
|
5321
|
+
if (ctx.signal.aborted) {
|
|
5322
|
+
throw ctx.signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
5323
|
+
}
|
|
5324
|
+
try {
|
|
5325
|
+
if (timeoutMs) {
|
|
5326
|
+
const result = await raceWithTimeout(
|
|
5327
|
+
fn(),
|
|
5328
|
+
timeoutMs,
|
|
5329
|
+
ctx.signal
|
|
5330
|
+
);
|
|
5331
|
+
return result;
|
|
5332
|
+
}
|
|
5333
|
+
return await fn();
|
|
5334
|
+
} catch (err2) {
|
|
5335
|
+
lastError = err2 instanceof Error ? err2 : new Error(String(err2));
|
|
5336
|
+
if (attempt === retryCount) {
|
|
5337
|
+
throw lastError;
|
|
5338
|
+
}
|
|
5339
|
+
const delay = Math.min(4e3, 500 * Math.pow(2, attempt));
|
|
5340
|
+
await sleep2(delay, ctx.signal);
|
|
5341
|
+
}
|
|
5342
|
+
}
|
|
5343
|
+
throw lastError ?? new Error("Pipeline failed");
|
|
5344
|
+
}
|
|
5345
|
+
};
|
|
5346
|
+
}
|
|
5347
|
+
};
|
|
5348
|
+
function resilience() {
|
|
5349
|
+
return new ResiliencePipeline();
|
|
5350
|
+
}
|
|
5351
|
+
async function raceWithTimeout(promise, timeoutMs, signal) {
|
|
5352
|
+
return Promise.race([
|
|
5353
|
+
promise,
|
|
5354
|
+
new Promise((_, reject) => {
|
|
5355
|
+
const timer = setTimeout(() => {
|
|
5356
|
+
reject(new Error(`Timeout after ${timeoutMs}ms`));
|
|
5357
|
+
}, timeoutMs);
|
|
5358
|
+
const onAbort = () => {
|
|
5359
|
+
clearTimeout(timer);
|
|
5360
|
+
reject(
|
|
5361
|
+
signal.reason ?? new DOMException("Aborted", "AbortError")
|
|
5362
|
+
);
|
|
5363
|
+
};
|
|
5364
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
5365
|
+
})
|
|
5366
|
+
]);
|
|
5367
|
+
}
|
|
5368
|
+
function sleep2(ms, signal) {
|
|
5369
|
+
return new Promise((resolve, reject) => {
|
|
5370
|
+
if (signal.aborted) {
|
|
5371
|
+
reject(
|
|
5372
|
+
signal.reason ?? new DOMException("Aborted", "AbortError")
|
|
5373
|
+
);
|
|
5374
|
+
return;
|
|
5375
|
+
}
|
|
5376
|
+
const timer = setTimeout(() => {
|
|
5377
|
+
signal.removeEventListener("abort", onAbort);
|
|
5378
|
+
resolve();
|
|
5379
|
+
}, ms);
|
|
5380
|
+
function onAbort() {
|
|
5381
|
+
clearTimeout(timer);
|
|
5382
|
+
reject(
|
|
5383
|
+
signal.reason ?? new DOMException("Aborted", "AbortError")
|
|
5384
|
+
);
|
|
5385
|
+
}
|
|
5386
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
5387
|
+
});
|
|
5388
|
+
}
|
|
5389
|
+
|
|
5390
|
+
export { ABSOLUTE_MAX_WORKER_STEPS, ArcLoop, CompositeToolProvider, ControlPlaneE2BExecutor, DEFAULT_MAX_STEPS_PER_WORKER, DEFAULT_WORKER_STEP_BUDGETS, E2BToolProvider, FsArtifactStore, FsTranscriptStore, HarnessTelemetry, HookRunner, InMemoryEpisodeStore, InMemoryLongTermStore, InMemorySessionMemoStore, MemoryArtifactStore, MemoryJobRegistry, MemoryMessageStore, MemoryScratchPad, MemorySessionStore, MemorySummaryDAG, MemoryTranscriptStore, MemoryVectorIndex, PermissionManager, REQUEST_MORE_STEPS_INCREMENT, cloneForTrace, formatDispatchForPrompt, resilience };
|
|
4985
5391
|
//# sourceMappingURL=index.js.map
|
|
4986
5392
|
//# sourceMappingURL=index.js.map
|