@ljoukov/llm 4.0.4 → 4.0.6
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/README.md +1 -1
- package/dist/index.cjs +68 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +68 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -412,6 +412,18 @@ type AgentSubagentToolConfig = {
|
|
|
412
412
|
};
|
|
413
413
|
type AgentSubagentToolSelection = boolean | AgentSubagentToolConfig;
|
|
414
414
|
|
|
415
|
+
type AgentLogLineSink = {
|
|
416
|
+
readonly append: (line: string) => void | Promise<void>;
|
|
417
|
+
readonly flush?: () => void | Promise<void>;
|
|
418
|
+
};
|
|
419
|
+
type AgentLoggingConfig = {
|
|
420
|
+
readonly workspaceDir?: string;
|
|
421
|
+
readonly callLogsDir?: string;
|
|
422
|
+
readonly mirrorToConsole?: boolean;
|
|
423
|
+
readonly sink?: AgentLogLineSink;
|
|
424
|
+
};
|
|
425
|
+
type AgentLoggingSelection = boolean | AgentLoggingConfig;
|
|
426
|
+
|
|
415
427
|
type AgentPathKind = "file" | "directory" | "symlink" | "other";
|
|
416
428
|
type AgentPathInfo = {
|
|
417
429
|
readonly kind: AgentPathKind;
|
|
@@ -576,18 +588,6 @@ declare function createGrepSearchTool(options?: AgentFilesystemToolsOptions): Ll
|
|
|
576
588
|
declare function createRgSearchTool(options?: AgentFilesystemToolsOptions): LlmFunctionTool<typeof geminiRgSearchInputSchema, string>;
|
|
577
589
|
declare function createGlobTool(options?: AgentFilesystemToolsOptions): LlmFunctionTool<typeof geminiGlobInputSchema, string>;
|
|
578
590
|
|
|
579
|
-
type AgentLogLineSink = {
|
|
580
|
-
readonly append: (line: string) => void | Promise<void>;
|
|
581
|
-
readonly flush?: () => void | Promise<void>;
|
|
582
|
-
};
|
|
583
|
-
type AgentLoggingConfig = {
|
|
584
|
-
readonly workspaceDir?: string;
|
|
585
|
-
readonly callLogsDir?: string;
|
|
586
|
-
readonly mirrorToConsole?: boolean;
|
|
587
|
-
readonly sink?: AgentLogLineSink;
|
|
588
|
-
};
|
|
589
|
-
type AgentLoggingSelection = boolean | AgentLoggingConfig;
|
|
590
|
-
|
|
591
591
|
type AgentFilesystemToolConfig = {
|
|
592
592
|
readonly enabled?: boolean;
|
|
593
593
|
readonly profile?: AgentFilesystemToolProfile;
|
package/dist/index.d.ts
CHANGED
|
@@ -412,6 +412,18 @@ type AgentSubagentToolConfig = {
|
|
|
412
412
|
};
|
|
413
413
|
type AgentSubagentToolSelection = boolean | AgentSubagentToolConfig;
|
|
414
414
|
|
|
415
|
+
type AgentLogLineSink = {
|
|
416
|
+
readonly append: (line: string) => void | Promise<void>;
|
|
417
|
+
readonly flush?: () => void | Promise<void>;
|
|
418
|
+
};
|
|
419
|
+
type AgentLoggingConfig = {
|
|
420
|
+
readonly workspaceDir?: string;
|
|
421
|
+
readonly callLogsDir?: string;
|
|
422
|
+
readonly mirrorToConsole?: boolean;
|
|
423
|
+
readonly sink?: AgentLogLineSink;
|
|
424
|
+
};
|
|
425
|
+
type AgentLoggingSelection = boolean | AgentLoggingConfig;
|
|
426
|
+
|
|
415
427
|
type AgentPathKind = "file" | "directory" | "symlink" | "other";
|
|
416
428
|
type AgentPathInfo = {
|
|
417
429
|
readonly kind: AgentPathKind;
|
|
@@ -576,18 +588,6 @@ declare function createGrepSearchTool(options?: AgentFilesystemToolsOptions): Ll
|
|
|
576
588
|
declare function createRgSearchTool(options?: AgentFilesystemToolsOptions): LlmFunctionTool<typeof geminiRgSearchInputSchema, string>;
|
|
577
589
|
declare function createGlobTool(options?: AgentFilesystemToolsOptions): LlmFunctionTool<typeof geminiGlobInputSchema, string>;
|
|
578
590
|
|
|
579
|
-
type AgentLogLineSink = {
|
|
580
|
-
readonly append: (line: string) => void | Promise<void>;
|
|
581
|
-
readonly flush?: () => void | Promise<void>;
|
|
582
|
-
};
|
|
583
|
-
type AgentLoggingConfig = {
|
|
584
|
-
readonly workspaceDir?: string;
|
|
585
|
-
readonly callLogsDir?: string;
|
|
586
|
-
readonly mirrorToConsole?: boolean;
|
|
587
|
-
readonly sink?: AgentLogLineSink;
|
|
588
|
-
};
|
|
589
|
-
type AgentLoggingSelection = boolean | AgentLoggingConfig;
|
|
590
|
-
|
|
591
591
|
type AgentFilesystemToolConfig = {
|
|
592
592
|
readonly enabled?: boolean;
|
|
593
593
|
readonly profile?: AgentFilesystemToolProfile;
|
package/dist/index.js
CHANGED
|
@@ -2682,6 +2682,7 @@ import { AsyncLocalStorage } from "async_hooks";
|
|
|
2682
2682
|
import { Buffer as Buffer3 } from "buffer";
|
|
2683
2683
|
import { appendFile, mkdir, writeFile } from "fs/promises";
|
|
2684
2684
|
import path3 from "path";
|
|
2685
|
+
var DEFAULT_THOUGHT_DELTA_LOG_THROTTLE_MS = 4e3;
|
|
2685
2686
|
function toIsoNow() {
|
|
2686
2687
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
2687
2688
|
}
|
|
@@ -2845,6 +2846,63 @@ function appendAgentStreamEventLog(options) {
|
|
|
2845
2846
|
}
|
|
2846
2847
|
}
|
|
2847
2848
|
}
|
|
2849
|
+
function createAgentStreamEventLogger(options) {
|
|
2850
|
+
const thoughtDeltaThrottleMs = Math.max(
|
|
2851
|
+
0,
|
|
2852
|
+
options.thoughtDeltaThrottleMs ?? DEFAULT_THOUGHT_DELTA_LOG_THROTTLE_MS
|
|
2853
|
+
);
|
|
2854
|
+
let pendingThoughtDelta = "";
|
|
2855
|
+
let thoughtFlushTimer = null;
|
|
2856
|
+
const cancelThoughtFlushTimer = () => {
|
|
2857
|
+
if (thoughtFlushTimer === null) {
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
clearTimeout(thoughtFlushTimer);
|
|
2861
|
+
thoughtFlushTimer = null;
|
|
2862
|
+
};
|
|
2863
|
+
const flushThoughtDelta = () => {
|
|
2864
|
+
cancelThoughtFlushTimer();
|
|
2865
|
+
if (pendingThoughtDelta.length === 0) {
|
|
2866
|
+
return;
|
|
2867
|
+
}
|
|
2868
|
+
options.append(`thought_delta: ${pendingThoughtDelta}`);
|
|
2869
|
+
pendingThoughtDelta = "";
|
|
2870
|
+
};
|
|
2871
|
+
const scheduleThoughtFlush = () => {
|
|
2872
|
+
if (thoughtFlushTimer !== null || thoughtDeltaThrottleMs === 0) {
|
|
2873
|
+
return;
|
|
2874
|
+
}
|
|
2875
|
+
thoughtFlushTimer = setTimeout(() => {
|
|
2876
|
+
thoughtFlushTimer = null;
|
|
2877
|
+
flushThoughtDelta();
|
|
2878
|
+
}, thoughtDeltaThrottleMs);
|
|
2879
|
+
thoughtFlushTimer.unref?.();
|
|
2880
|
+
};
|
|
2881
|
+
return {
|
|
2882
|
+
appendEvent: (event) => {
|
|
2883
|
+
if (event.type === "delta" && event.channel === "thought") {
|
|
2884
|
+
if (event.text.length === 0) {
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2887
|
+
pendingThoughtDelta += event.text;
|
|
2888
|
+
if (thoughtDeltaThrottleMs === 0) {
|
|
2889
|
+
flushThoughtDelta();
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
scheduleThoughtFlush();
|
|
2893
|
+
return;
|
|
2894
|
+
}
|
|
2895
|
+
flushThoughtDelta();
|
|
2896
|
+
appendAgentStreamEventLog({
|
|
2897
|
+
event,
|
|
2898
|
+
append: options.append
|
|
2899
|
+
});
|
|
2900
|
+
},
|
|
2901
|
+
flush: () => {
|
|
2902
|
+
flushThoughtDelta();
|
|
2903
|
+
}
|
|
2904
|
+
};
|
|
2905
|
+
}
|
|
2848
2906
|
var AgentLoggingSessionImpl = class {
|
|
2849
2907
|
workspaceDir;
|
|
2850
2908
|
logsRootDir;
|
|
@@ -9596,7 +9654,7 @@ async function runAccessHook2(runtime, context) {
|
|
|
9596
9654
|
}
|
|
9597
9655
|
function isCodexModel(model) {
|
|
9598
9656
|
const normalized = model.startsWith("chatgpt-") ? model.slice("chatgpt-".length) : model;
|
|
9599
|
-
return normalized.includes("codex");
|
|
9657
|
+
return normalized.includes("codex") || normalized === "gpt-5.4" || normalized === "gpt-5.4-fast";
|
|
9600
9658
|
}
|
|
9601
9659
|
function isGeminiModel(model) {
|
|
9602
9660
|
return model.startsWith("gemini-");
|
|
@@ -10024,19 +10082,17 @@ async function runAgentLoopInternal(request, context) {
|
|
|
10024
10082
|
);
|
|
10025
10083
|
const sourceOnEvent = toolLoopRequestWithSteering.onEvent;
|
|
10026
10084
|
const includeLlmStreamEvents = telemetrySession?.includeLlmStreamEvents === true;
|
|
10085
|
+
const streamEventLogger = loggingSession ? createAgentStreamEventLogger({
|
|
10086
|
+
append: (line) => {
|
|
10087
|
+
loggingSession.logLine(`[agent:${runId}] ${line}`);
|
|
10088
|
+
}
|
|
10089
|
+
}) : void 0;
|
|
10027
10090
|
const wrappedOnEvent = sourceOnEvent || includeLlmStreamEvents ? (event) => {
|
|
10028
10091
|
sourceOnEvent?.(event);
|
|
10029
10092
|
if (includeLlmStreamEvents) {
|
|
10030
10093
|
emitTelemetry({ type: "agent.run.stream", event });
|
|
10031
10094
|
}
|
|
10032
|
-
|
|
10033
|
-
appendAgentStreamEventLog({
|
|
10034
|
-
event,
|
|
10035
|
-
append: (line) => {
|
|
10036
|
-
loggingSession.logLine(`[agent:${runId}] ${line}`);
|
|
10037
|
-
}
|
|
10038
|
-
});
|
|
10039
|
-
}
|
|
10095
|
+
streamEventLogger?.appendEvent(event);
|
|
10040
10096
|
} : void 0;
|
|
10041
10097
|
try {
|
|
10042
10098
|
const result = await runToolLoop({
|
|
@@ -10045,6 +10101,7 @@ async function runAgentLoopInternal(request, context) {
|
|
|
10045
10101
|
...wrappedOnEvent ? { onEvent: wrappedOnEvent } : {},
|
|
10046
10102
|
tools: mergedTools
|
|
10047
10103
|
});
|
|
10104
|
+
streamEventLogger?.flush();
|
|
10048
10105
|
emitTelemetry({
|
|
10049
10106
|
type: "agent.run.completed",
|
|
10050
10107
|
success: true,
|
|
@@ -10077,6 +10134,7 @@ async function runAgentLoopInternal(request, context) {
|
|
|
10077
10134
|
}
|
|
10078
10135
|
return result;
|
|
10079
10136
|
} catch (error) {
|
|
10137
|
+
streamEventLogger?.flush();
|
|
10080
10138
|
emitTelemetry({
|
|
10081
10139
|
type: "agent.run.completed",
|
|
10082
10140
|
success: false,
|
|
@@ -10093,6 +10151,7 @@ async function runAgentLoopInternal(request, context) {
|
|
|
10093
10151
|
);
|
|
10094
10152
|
throw error;
|
|
10095
10153
|
} finally {
|
|
10154
|
+
streamEventLogger?.flush();
|
|
10096
10155
|
await subagentController?.closeAll();
|
|
10097
10156
|
}
|
|
10098
10157
|
}
|