llmist 16.0.1 → 16.0.3
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/index.cjs +102 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -2
- package/dist/index.d.ts +56 -2
- package/dist/index.js +101 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -658,11 +658,11 @@ var init_execution_tree = __esm({
|
|
|
658
658
|
yield this.eventQueue.shift();
|
|
659
659
|
}
|
|
660
660
|
if (this.isCompleted) break;
|
|
661
|
-
const event = await new Promise((
|
|
661
|
+
const event = await new Promise((resolve2) => {
|
|
662
662
|
if (this.eventQueue.length > 0) {
|
|
663
|
-
|
|
663
|
+
resolve2(this.eventQueue.shift());
|
|
664
664
|
} else {
|
|
665
|
-
this.eventWaiters.push(
|
|
665
|
+
this.eventWaiters.push(resolve2);
|
|
666
666
|
}
|
|
667
667
|
});
|
|
668
668
|
yield event;
|
|
@@ -4084,6 +4084,62 @@ var init_registry = __esm({
|
|
|
4084
4084
|
});
|
|
4085
4085
|
|
|
4086
4086
|
// src/agent/file-logging.ts
|
|
4087
|
+
function createFileLoggingState() {
|
|
4088
|
+
return {
|
|
4089
|
+
counters: /* @__PURE__ */ new Map(),
|
|
4090
|
+
subagentDirectories: /* @__PURE__ */ new Map(),
|
|
4091
|
+
activeDirectoryByContext: /* @__PURE__ */ new Map()
|
|
4092
|
+
};
|
|
4093
|
+
}
|
|
4094
|
+
function getDefaultState() {
|
|
4095
|
+
if (!defaultState) {
|
|
4096
|
+
defaultState = createFileLoggingState();
|
|
4097
|
+
}
|
|
4098
|
+
return defaultState;
|
|
4099
|
+
}
|
|
4100
|
+
function getNextCounter(state, directory) {
|
|
4101
|
+
const current = state.counters.get(directory) ?? 0;
|
|
4102
|
+
const next = current + 1;
|
|
4103
|
+
state.counters.set(directory, next);
|
|
4104
|
+
return next;
|
|
4105
|
+
}
|
|
4106
|
+
function getContextKey(subagentContext) {
|
|
4107
|
+
if (!subagentContext) return "root:0";
|
|
4108
|
+
return `${subagentContext.parentGadgetInvocationId}:${subagentContext.depth}`;
|
|
4109
|
+
}
|
|
4110
|
+
function resetFileLoggingState() {
|
|
4111
|
+
defaultState = void 0;
|
|
4112
|
+
}
|
|
4113
|
+
function findParentContextKey(state, currentDepth) {
|
|
4114
|
+
const parentDepth = currentDepth - 1;
|
|
4115
|
+
if (parentDepth === 0) return "root:0";
|
|
4116
|
+
for (const [key, _path] of state.activeDirectoryByContext) {
|
|
4117
|
+
if (key.endsWith(`:${parentDepth}`)) {
|
|
4118
|
+
return key;
|
|
4119
|
+
}
|
|
4120
|
+
}
|
|
4121
|
+
return "root:0";
|
|
4122
|
+
}
|
|
4123
|
+
function resolveLoggingDirectory(state, baseDirectory, counterPadding, subagentContext) {
|
|
4124
|
+
const contextKey = getContextKey(subagentContext);
|
|
4125
|
+
if (!subagentContext) {
|
|
4126
|
+
state.activeDirectoryByContext.set(contextKey, baseDirectory);
|
|
4127
|
+
return baseDirectory;
|
|
4128
|
+
}
|
|
4129
|
+
const { parentGadgetInvocationId, depth } = subagentContext;
|
|
4130
|
+
const parentContextKey = findParentContextKey(state, depth);
|
|
4131
|
+
const parentDir = state.activeDirectoryByContext.get(parentContextKey) ?? baseDirectory;
|
|
4132
|
+
const subagentKey = `${parentDir}:${parentGadgetInvocationId}`;
|
|
4133
|
+
let fullPath = state.subagentDirectories.get(subagentKey);
|
|
4134
|
+
if (!fullPath) {
|
|
4135
|
+
const chronoNumber = getNextCounter(state, parentDir);
|
|
4136
|
+
const subdirName = `${formatCallNumber(chronoNumber, counterPadding)}-${parentGadgetInvocationId}`;
|
|
4137
|
+
fullPath = (0, import_node_path3.join)(parentDir, subdirName);
|
|
4138
|
+
state.subagentDirectories.set(subagentKey, fullPath);
|
|
4139
|
+
}
|
|
4140
|
+
state.activeDirectoryByContext.set(contextKey, fullPath);
|
|
4141
|
+
return fullPath;
|
|
4142
|
+
}
|
|
4087
4143
|
function formatLlmRequest(messages) {
|
|
4088
4144
|
const lines = [];
|
|
4089
4145
|
for (const msg of messages) {
|
|
@@ -4100,16 +4156,20 @@ async function writeLogFile(dir, filename, content) {
|
|
|
4100
4156
|
await (0, import_promises2.mkdir)(dir, { recursive: true });
|
|
4101
4157
|
await (0, import_promises2.writeFile)((0, import_node_path3.join)(dir, filename), content, "utf-8");
|
|
4102
4158
|
}
|
|
4103
|
-
function createFileLoggingHooks(options) {
|
|
4159
|
+
function createFileLoggingHooks(options, state = getDefaultState()) {
|
|
4104
4160
|
const {
|
|
4105
|
-
directory,
|
|
4106
4161
|
startingCounter = 1,
|
|
4107
4162
|
counterPadding = 4,
|
|
4108
4163
|
skipSubagents = true,
|
|
4109
4164
|
formatRequest = formatLlmRequest,
|
|
4110
4165
|
onFileWritten
|
|
4111
4166
|
} = options;
|
|
4112
|
-
|
|
4167
|
+
const baseDirectory = (0, import_node_path3.resolve)(options.directory);
|
|
4168
|
+
if (!state.counters.has(baseDirectory)) {
|
|
4169
|
+
state.counters.set(baseDirectory, startingCounter - 1);
|
|
4170
|
+
}
|
|
4171
|
+
let currentCallNumber = 0;
|
|
4172
|
+
let currentDirectory = baseDirectory;
|
|
4113
4173
|
return {
|
|
4114
4174
|
observers: {
|
|
4115
4175
|
/**
|
|
@@ -4119,17 +4179,25 @@ function createFileLoggingHooks(options) {
|
|
|
4119
4179
|
if (skipSubagents && context.subagentContext) {
|
|
4120
4180
|
return;
|
|
4121
4181
|
}
|
|
4122
|
-
|
|
4123
|
-
|
|
4182
|
+
currentDirectory = resolveLoggingDirectory(
|
|
4183
|
+
state,
|
|
4184
|
+
baseDirectory,
|
|
4185
|
+
counterPadding,
|
|
4186
|
+
context.subagentContext
|
|
4187
|
+
);
|
|
4188
|
+
currentCallNumber = getNextCounter(state, currentDirectory);
|
|
4189
|
+
const filename = `${formatCallNumber(currentCallNumber, counterPadding)}.request`;
|
|
4124
4190
|
const content = formatRequest(context.options.messages);
|
|
4125
4191
|
try {
|
|
4126
|
-
await writeLogFile(
|
|
4192
|
+
await writeLogFile(currentDirectory, filename, content);
|
|
4127
4193
|
if (onFileWritten) {
|
|
4128
4194
|
onFileWritten({
|
|
4129
|
-
filePath: (0, import_node_path3.join)(
|
|
4195
|
+
filePath: (0, import_node_path3.join)(currentDirectory, filename),
|
|
4130
4196
|
type: "request",
|
|
4131
|
-
callNumber:
|
|
4132
|
-
contentLength: content.length
|
|
4197
|
+
callNumber: currentCallNumber,
|
|
4198
|
+
contentLength: content.length,
|
|
4199
|
+
parentGadgetInvocationId: context.subagentContext?.parentGadgetInvocationId,
|
|
4200
|
+
depth: context.subagentContext?.depth
|
|
4133
4201
|
});
|
|
4134
4202
|
}
|
|
4135
4203
|
} catch (error) {
|
|
@@ -4143,16 +4211,22 @@ function createFileLoggingHooks(options) {
|
|
|
4143
4211
|
if (skipSubagents && context.subagentContext) {
|
|
4144
4212
|
return;
|
|
4145
4213
|
}
|
|
4146
|
-
|
|
4214
|
+
if (currentCallNumber === 0) {
|
|
4215
|
+
console.warn("[file-logging] Skipping response write: no matching request recorded");
|
|
4216
|
+
return;
|
|
4217
|
+
}
|
|
4218
|
+
const filename = `${formatCallNumber(currentCallNumber, counterPadding)}.response`;
|
|
4147
4219
|
const content = context.rawResponse;
|
|
4148
4220
|
try {
|
|
4149
|
-
await writeLogFile(
|
|
4221
|
+
await writeLogFile(currentDirectory, filename, content);
|
|
4150
4222
|
if (onFileWritten) {
|
|
4151
4223
|
onFileWritten({
|
|
4152
|
-
filePath: (0, import_node_path3.join)(
|
|
4224
|
+
filePath: (0, import_node_path3.join)(currentDirectory, filename),
|
|
4153
4225
|
type: "response",
|
|
4154
|
-
callNumber:
|
|
4155
|
-
contentLength: content.length
|
|
4226
|
+
callNumber: currentCallNumber,
|
|
4227
|
+
contentLength: content.length,
|
|
4228
|
+
parentGadgetInvocationId: context.subagentContext?.parentGadgetInvocationId,
|
|
4229
|
+
depth: context.subagentContext?.depth
|
|
4156
4230
|
});
|
|
4157
4231
|
}
|
|
4158
4232
|
} catch (error) {
|
|
@@ -4169,7 +4243,7 @@ function getEnvFileLoggingHooks() {
|
|
|
4169
4243
|
}
|
|
4170
4244
|
return createFileLoggingHooks({ directory });
|
|
4171
4245
|
}
|
|
4172
|
-
var import_promises2, import_node_path3, ENV_LOG_RAW_DIRECTORY;
|
|
4246
|
+
var import_promises2, import_node_path3, defaultState, ENV_LOG_RAW_DIRECTORY;
|
|
4173
4247
|
var init_file_logging = __esm({
|
|
4174
4248
|
"src/agent/file-logging.ts"() {
|
|
4175
4249
|
"use strict";
|
|
@@ -14435,7 +14509,7 @@ var init_stream_processor = __esm({
|
|
|
14435
14509
|
const allDone = this.inFlightExecutions.size > 0 ? Promise.all(this.inFlightExecutions.values()).then(() => "done") : Promise.resolve("done");
|
|
14436
14510
|
const result = await Promise.race([
|
|
14437
14511
|
allDone,
|
|
14438
|
-
new Promise((
|
|
14512
|
+
new Promise((resolve2) => setTimeout(() => resolve2("poll"), POLL_INTERVAL_MS))
|
|
14439
14513
|
]);
|
|
14440
14514
|
yield* this.drainCompletedResults();
|
|
14441
14515
|
if (result === "done" && this.getTotalActiveGadgetCount() === 0 && !this.hasQueuedGadgets()) {
|
|
@@ -15577,7 +15651,7 @@ var init_agent = __esm({
|
|
|
15577
15651
|
* Simple sleep utility for rate limit delays.
|
|
15578
15652
|
*/
|
|
15579
15653
|
sleep(ms) {
|
|
15580
|
-
return new Promise((
|
|
15654
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
15581
15655
|
}
|
|
15582
15656
|
/**
|
|
15583
15657
|
* Handle LLM error through controller.
|
|
@@ -16033,6 +16107,7 @@ __export(index_exports, {
|
|
|
16033
16107
|
collectText: () => collectText,
|
|
16034
16108
|
complete: () => complete,
|
|
16035
16109
|
createAnthropicProviderFromEnv: () => createAnthropicProviderFromEnv,
|
|
16110
|
+
createFileLoggingState: () => createFileLoggingState,
|
|
16036
16111
|
createGadget: () => createGadget,
|
|
16037
16112
|
createGadgetOutputViewer: () => createGadgetOutputViewer,
|
|
16038
16113
|
createGeminiProviderFromEnv: () => createGeminiProviderFromEnv,
|
|
@@ -16095,6 +16170,7 @@ __export(index_exports, {
|
|
|
16095
16170
|
parseManifest: () => parseManifest,
|
|
16096
16171
|
parseRetryAfterHeader: () => parseRetryAfterHeader,
|
|
16097
16172
|
randomDelay: () => randomDelay,
|
|
16173
|
+
resetFileLoggingState: () => resetFileLoggingState,
|
|
16098
16174
|
resolveConfig: () => resolveConfig,
|
|
16099
16175
|
resolveHintTemplate: () => resolveHintTemplate,
|
|
16100
16176
|
resolveModel: () => resolveModel,
|
|
@@ -16772,10 +16848,10 @@ function randomDelay(min, max) {
|
|
|
16772
16848
|
}
|
|
16773
16849
|
async function humanDelay(min = 50, max = 150) {
|
|
16774
16850
|
const delay = randomDelay(min, max);
|
|
16775
|
-
return new Promise((
|
|
16851
|
+
return new Promise((resolve2) => setTimeout(resolve2, delay));
|
|
16776
16852
|
}
|
|
16777
16853
|
async function withTimeout(fn, timeoutMs, signal) {
|
|
16778
|
-
return new Promise((
|
|
16854
|
+
return new Promise((resolve2, reject) => {
|
|
16779
16855
|
if (signal?.aborted) {
|
|
16780
16856
|
reject(new Error("Operation aborted"));
|
|
16781
16857
|
return;
|
|
@@ -16801,7 +16877,7 @@ async function withTimeout(fn, timeoutMs, signal) {
|
|
|
16801
16877
|
settled = true;
|
|
16802
16878
|
clearTimeout(timeoutId);
|
|
16803
16879
|
signal?.removeEventListener("abort", abortHandler);
|
|
16804
|
-
|
|
16880
|
+
resolve2(result);
|
|
16805
16881
|
}
|
|
16806
16882
|
}).catch((error) => {
|
|
16807
16883
|
if (!settled) {
|
|
@@ -16834,7 +16910,7 @@ async function withRetry(fn, options = {}) {
|
|
|
16834
16910
|
}
|
|
16835
16911
|
const waitTime = Math.min(currentDelay, maxDelay);
|
|
16836
16912
|
onRetry?.(error, attempt + 1, waitTime);
|
|
16837
|
-
await new Promise((
|
|
16913
|
+
await new Promise((resolve2) => setTimeout(resolve2, waitTime));
|
|
16838
16914
|
if (backoff === "exponential") {
|
|
16839
16915
|
currentDelay *= 2;
|
|
16840
16916
|
} else {
|
|
@@ -16914,6 +16990,7 @@ function getHostExports2(ctx) {
|
|
|
16914
16990
|
collectText,
|
|
16915
16991
|
complete,
|
|
16916
16992
|
createAnthropicProviderFromEnv,
|
|
16993
|
+
createFileLoggingState,
|
|
16917
16994
|
createGadget,
|
|
16918
16995
|
createGadgetOutputViewer,
|
|
16919
16996
|
createGeminiProviderFromEnv,
|
|
@@ -16976,6 +17053,7 @@ function getHostExports2(ctx) {
|
|
|
16976
17053
|
parseManifest,
|
|
16977
17054
|
parseRetryAfterHeader,
|
|
16978
17055
|
randomDelay,
|
|
17056
|
+
resetFileLoggingState,
|
|
16979
17057
|
resolveConfig,
|
|
16980
17058
|
resolveHintTemplate,
|
|
16981
17059
|
resolveModel,
|