@delofarag/ai-utils 1.6.0 → 1.7.1
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 +648 -97
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +13 -0
- package/dist/client/index.js.map +1 -0
- package/dist/heart/agent.d.ts +6 -6
- package/dist/heart/agent.d.ts.map +1 -1
- package/dist/heart/agent.js +21 -21
- package/dist/heart/agent.js.map +1 -1
- package/dist/heart/chain.d.ts +4 -8
- package/dist/heart/chain.d.ts.map +1 -1
- package/dist/heart/chain.js +1 -1
- package/dist/heart/chain.js.map +1 -1
- package/dist/heart/deepAgent.d.ts +111 -0
- package/dist/heart/deepAgent.d.ts.map +1 -0
- package/dist/heart/deepAgent.js +305 -0
- package/dist/heart/deepAgent.js.map +1 -0
- package/dist/heart/hermesAgent.d.ts +22 -0
- package/dist/heart/hermesAgent.d.ts.map +1 -0
- package/dist/heart/hermesAgent.js +21 -0
- package/dist/heart/hermesAgent.js.map +1 -0
- package/dist/heart/routine.d.ts +15 -0
- package/dist/heart/routine.d.ts.map +1 -0
- package/dist/heart/routine.js +67 -0
- package/dist/heart/routine.js.map +1 -0
- package/dist/heart/tools/RAGTool.d.ts +3 -7
- package/dist/heart/tools/RAGTool.d.ts.map +1 -1
- package/dist/heart/tools/RAGTool.js +1 -1
- package/dist/heart/tools/RAGTool.js.map +1 -1
- package/dist/heart/tools/Tavily.d.ts +3 -7
- package/dist/heart/tools/Tavily.d.ts.map +1 -1
- package/dist/heart/tools/Tavily.js +1 -1
- package/dist/heart/tools/Tavily.js.map +1 -1
- package/dist/heart/tools/ToolRegistry.d.ts +14 -5
- package/dist/heart/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/heart/tools/ToolRegistry.js +2 -3
- package/dist/heart/tools/ToolRegistry.js.map +1 -1
- package/dist/heart/tools/zodios/CombinedRegistry.js +1 -1
- package/dist/heart/tools/zodios/ZodiosToolRegistry.js +1 -1
- package/dist/helpers/chatbot.d.ts +11 -3
- package/dist/helpers/chatbot.d.ts.map +1 -1
- package/dist/helpers/chatbot.js +44 -5
- package/dist/helpers/chatbot.js.map +1 -1
- package/dist/helpers/deepagent/backend.d.ts +92 -0
- package/dist/helpers/deepagent/backend.d.ts.map +1 -0
- package/dist/helpers/deepagent/backend.js +93 -0
- package/dist/helpers/deepagent/backend.js.map +1 -0
- package/dist/helpers/deepagent/interruptOn.d.ts +93 -0
- package/dist/helpers/deepagent/interruptOn.d.ts.map +1 -0
- package/dist/helpers/deepagent/interruptOn.js +190 -0
- package/dist/helpers/deepagent/interruptOn.js.map +1 -0
- package/dist/helpers/deepagent/interruptTypes.d.ts +65 -0
- package/dist/helpers/deepagent/interruptTypes.d.ts.map +1 -0
- package/dist/helpers/deepagent/interruptTypes.js +2 -0
- package/dist/helpers/deepagent/interruptTypes.js.map +1 -0
- package/dist/helpers/deepagent/permissions.d.ts +58 -0
- package/dist/helpers/deepagent/permissions.d.ts.map +1 -0
- package/dist/helpers/deepagent/permissions.js +72 -0
- package/dist/helpers/deepagent/permissions.js.map +1 -0
- package/dist/helpers/deepagent/sandbox.d.ts +7 -0
- package/dist/helpers/deepagent/sandbox.d.ts.map +1 -0
- package/dist/helpers/deepagent/sandbox.js +8 -0
- package/dist/helpers/deepagent/sandbox.js.map +1 -0
- package/dist/helpers/deepagent/streamEvents.d.ts +10 -0
- package/dist/helpers/deepagent/streamEvents.d.ts.map +1 -0
- package/dist/helpers/deepagent/streamEvents.js +149 -0
- package/dist/helpers/deepagent/streamEvents.js.map +1 -0
- package/dist/helpers/helpers.d.ts +4 -3
- package/dist/helpers/helpers.d.ts.map +1 -1
- package/dist/helpers/helpers.js +25 -0
- package/dist/helpers/helpers.js.map +1 -1
- package/dist/helpers/llms.d.ts +14 -4
- package/dist/helpers/llms.d.ts.map +1 -1
- package/dist/helpers/llms.js +20 -9
- package/dist/helpers/llms.js.map +1 -1
- package/dist/helpers/rag.d.ts +1 -1
- package/dist/imports.d.ts +14 -2
- package/dist/imports.d.ts.map +1 -1
- package/dist/imports.js +15 -2
- package/dist/imports.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/magic-funcs/evaluators/classify.d.ts +3 -11
- package/dist/magic-funcs/evaluators/classify.d.ts.map +1 -1
- package/dist/magic-funcs/evaluators/classify.js +1 -1
- package/dist/magic-funcs/evaluators/decide.d.ts +7 -11
- package/dist/magic-funcs/evaluators/decide.d.ts.map +1 -1
- package/dist/magic-funcs/evaluators/decide.js +1 -1
- package/dist/magic-funcs/parsers/extract.d.ts +2 -2
- package/dist/magic-funcs/parsers/extract.d.ts.map +1 -1
- package/dist/magic-funcs/parsers/extract.js.map +1 -1
- package/dist/magic-funcs/parsers/structure.d.ts +1 -1
- package/dist/magic-funcs/parsers/structure.js.map +1 -1
- package/package.json +33 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
2
|
-
import { z } from "zod/
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
3
|
export class ToolRegistry {
|
|
4
4
|
tools;
|
|
5
5
|
constructor(tools) {
|
|
@@ -14,8 +14,7 @@ export class ToolRegistry {
|
|
|
14
14
|
throw new Error(`Error! mehrere tools wurden unter den gleichen Namen ${name} registriert!`);
|
|
15
15
|
}
|
|
16
16
|
if (tools.length !== 1) {
|
|
17
|
-
|
|
18
|
-
return;
|
|
17
|
+
throw new Error(`unter ${name} wurde kein Tool gefunden`);
|
|
19
18
|
}
|
|
20
19
|
return tools[0];
|
|
21
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolRegistry.js","sourceRoot":"","sources":["../../../src/heart/tools/ToolRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAA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,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA"}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
type SessionStreamable =
|
|
1
|
+
import type { DeepAgentStreamChunkWithTools, DeepAgentUserDecision } from "./deepagent/interruptTypes";
|
|
2
|
+
type SessionStreamable = {
|
|
3
|
+
stream(input: {
|
|
4
|
+
input?: string;
|
|
5
|
+
thread_id: string;
|
|
6
|
+
decision?: DeepAgentUserDecision;
|
|
7
|
+
showToolCalls?: true;
|
|
8
|
+
}): AsyncIterable<DeepAgentStreamChunkWithTools>;
|
|
9
|
+
};
|
|
3
10
|
type SessionProps = {
|
|
4
11
|
streamable: SessionStreamable;
|
|
5
12
|
breakword?: string;
|
|
6
13
|
numberOfMessages?: number;
|
|
7
14
|
id?: string;
|
|
15
|
+
isDeepAgent?: boolean;
|
|
8
16
|
};
|
|
9
17
|
/**
|
|
10
18
|
* die session funktion für ein streamable, wird hauptsächlich für testing eines agenten verwendet
|
|
@@ -14,7 +22,7 @@ type SessionProps = {
|
|
|
14
22
|
* @param id die id der session
|
|
15
23
|
* @returns void
|
|
16
24
|
*/
|
|
17
|
-
export declare function session({ streamable, breakword, numberOfMessages, id }: SessionProps): Promise<void>;
|
|
25
|
+
export declare function session({ streamable, breakword, numberOfMessages, id, isDeepAgent, }: SessionProps): Promise<void>;
|
|
18
26
|
type StreamResponseInit = ResponseInit & {
|
|
19
27
|
encoder?: TextEncoder;
|
|
20
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatbot.d.ts","sourceRoot":"","sources":["../../src/helpers/chatbot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chatbot.d.ts","sourceRoot":"","sources":["../../src/helpers/chatbot.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAEtG,KAAK,iBAAiB,GAAG;IACrB,MAAM,CAAC,KAAK,EAAE;QACV,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,SAAS,EAAE,MAAM,CAAA;QACjB,QAAQ,CAAC,EAAE,qBAAqB,CAAA;QAChC,aAAa,CAAC,EAAE,IAAI,CAAA;KACvB,GAAG,aAAa,CAAC,6BAA6B,CAAC,CAAA;CACnD,CAAA;AAED,KAAK,YAAY,GAAG;IAChB,UAAU,EAAE,iBAAiB,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAuBD;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,EAC1B,UAAU,EACV,SAAkB,EAClB,gBAA2C,EAC3C,EAAoB,EACpB,WAAmB,GACtB,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAqD9B;AAED,KAAK,kBAAkB,GAAG,YAAY,GAAG;IACrC,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB,CAAC;AAEJ;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC5B,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,IAAI,GAAE,kBAAuB,GAC5B,QAAQ,CA4BV"}
|
package/dist/helpers/chatbot.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { input } from "@delofarag/base-utils/server";
|
|
2
2
|
import { logChunk } from "./helpers";
|
|
3
|
+
import { isInterrupt } from "../client/index";
|
|
4
|
+
function parseDeepAgentDecision(message) {
|
|
5
|
+
const normalized = message.trim().toLowerCase();
|
|
6
|
+
if (!normalized)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (normalized.startsWith("reject:")) {
|
|
9
|
+
return { type: "reject", message: message.slice("reject:".length).trim() };
|
|
10
|
+
}
|
|
11
|
+
const approveWords = ["approve", "approved", "aprove", "yes", "y", "ja", "ok", "okay"];
|
|
12
|
+
if (approveWords.includes(normalized) || normalized.includes("darf") || normalized.includes("klar")) {
|
|
13
|
+
return "approve";
|
|
14
|
+
}
|
|
15
|
+
const rejectWords = ["reject", "rejected", "no", "n", "nein"];
|
|
16
|
+
if (rejectWords.includes(normalized)) {
|
|
17
|
+
return "reject";
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
3
21
|
/**
|
|
4
22
|
* die session funktion für ein streamable, wird hauptsächlich für testing eines agenten verwendet
|
|
5
23
|
* @param streamable das streamable welches die session führt
|
|
@@ -8,21 +26,42 @@ import { logChunk } from "./helpers";
|
|
|
8
26
|
* @param id die id der session
|
|
9
27
|
* @returns void
|
|
10
28
|
*/
|
|
11
|
-
export async function session({ streamable, breakword = "exit", numberOfMessages = Number.POSITIVE_INFINITY, id = `${Date.now()}
|
|
29
|
+
export async function session({ streamable, breakword = "exit", numberOfMessages = Number.POSITIVE_INFINITY, id = `${Date.now()}`, isDeepAgent = false, }) {
|
|
12
30
|
let messages = 0;
|
|
31
|
+
let pendingInterrupt = false;
|
|
13
32
|
while (true) {
|
|
14
33
|
try {
|
|
15
34
|
const message = await input("You: ");
|
|
16
35
|
if (message === breakword) {
|
|
17
36
|
break;
|
|
18
37
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
const deepAgentStreamOpts = isDeepAgent ? { showToolCalls: true } : {};
|
|
39
|
+
const decision = pendingInterrupt && isDeepAgent
|
|
40
|
+
? parseDeepAgentDecision(message)
|
|
41
|
+
: undefined;
|
|
42
|
+
if (pendingInterrupt && isDeepAgent && !decision) {
|
|
43
|
+
console.log("Pending interrupt. Bitte antworte mit approve oder reject.");
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const streamInput = decision !== undefined
|
|
47
|
+
? {
|
|
48
|
+
thread_id: id,
|
|
49
|
+
decision,
|
|
50
|
+
...deepAgentStreamOpts,
|
|
51
|
+
}
|
|
52
|
+
: {
|
|
53
|
+
input: message,
|
|
54
|
+
thread_id: id,
|
|
55
|
+
...deepAgentStreamOpts,
|
|
56
|
+
};
|
|
57
|
+
pendingInterrupt = false;
|
|
58
|
+
const response = streamable.stream(streamInput);
|
|
23
59
|
console.log("Assistant: ");
|
|
24
60
|
for await (const chunk of response) {
|
|
25
61
|
logChunk(chunk);
|
|
62
|
+
if (isDeepAgent && isInterrupt(chunk)) {
|
|
63
|
+
pendingInterrupt = true;
|
|
64
|
+
}
|
|
26
65
|
}
|
|
27
66
|
console.log("");
|
|
28
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatbot.js","sourceRoot":"","sources":["../../src/helpers/chatbot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"chatbot.js","sourceRoot":"","sources":["../../src/helpers/chatbot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAoB7C,SAAS,sBAAsB,CAAC,OAAe;IAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC/C,IAAI,CAAC,UAAU;QAAE,OAAO,SAAS,CAAA;IAEjC,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACnC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAA;IAC9E,CAAC;IAED,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAA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,EAAE,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,IAAI,CAAC;IAE7D,MAAM,MAAM,GAAG,IAAI,cAAc,CAAa;QAC5C,KAAK,CAAC,KAAK,CAAC,UAAU;YACpB,IAAI,CAAC;gBACH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;oBACnC,UAAU,CAAC,OAAO,CAChB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAC7C,CAAC;gBACJ,CAAC;gBAED,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;QAC1B,GAAG,YAAY;QACf,OAAO,EAAE;YACP,cAAc,EAAE,sBAAsB;YACtC,GAAG,OAAO;SACX;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { StateBackend, FilesystemBackend, CompositeBackend, type CreateDeepAgentParams, type LocalShellBackendOptions } from "../../imports";
|
|
2
|
+
import type { ExecuteCapableDeepAgentBackend } from "./interruptOn";
|
|
3
|
+
/** Native deepagents-Backend — Instanz oder Factory, kein Promise. */
|
|
4
|
+
export type DeepAgentBackend = NonNullable<CreateDeepAgentParams["backend"]>;
|
|
5
|
+
type Prettify<T> = {
|
|
6
|
+
[K in keyof T]: T[K];
|
|
7
|
+
} & {};
|
|
8
|
+
export type CreateLocalShellBackendOptions = Prettify<Omit<LocalShellBackendOptions, "rootDir"> & {
|
|
9
|
+
route?: string;
|
|
10
|
+
rootDir: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* erstellt einfach den StateBackend von langchain
|
|
14
|
+
* @example
|
|
15
|
+
* export function createStateBackend() {
|
|
16
|
+
return new StateBackend()
|
|
17
|
+
}
|
|
18
|
+
*/
|
|
19
|
+
export declare function createStateBackend(): StateBackend;
|
|
20
|
+
/**
|
|
21
|
+
* erstellt ein reines Filesystembackend, nimm lieber 'createWorkspaceBackend()'
|
|
22
|
+
* @example
|
|
23
|
+
* export function createFilesystemBackend({
|
|
24
|
+
rootDir = process.cwd(),
|
|
25
|
+
virtualMode = true,
|
|
26
|
+
maxFileSizeMb,
|
|
27
|
+
}: {
|
|
28
|
+
rootDir?: string
|
|
29
|
+
virtualMode?: boolean
|
|
30
|
+
maxFileSizeMb?: number
|
|
31
|
+
} = {}): FilesystemBackend {
|
|
32
|
+
return new FilesystemBackend({ rootDir, virtualMode, maxFileSizeMb })
|
|
33
|
+
}
|
|
34
|
+
*/
|
|
35
|
+
export declare function createFilesystemBackend({ rootDir, virtualMode, maxFileSizeMb, }?: {
|
|
36
|
+
rootDir?: string;
|
|
37
|
+
virtualMode?: boolean;
|
|
38
|
+
maxFileSizeMb?: number;
|
|
39
|
+
}): FilesystemBackend;
|
|
40
|
+
/**
|
|
41
|
+
* erstellt ein Filesystembackend mit einem normalem Statebackend damit dein workspace nicht beschmutzt wird
|
|
42
|
+
* @example
|
|
43
|
+
* export function createWorkspaceBackend({
|
|
44
|
+
rootDir = process.cwd(),
|
|
45
|
+
route = "/workspace/",
|
|
46
|
+
virtualMode = true,
|
|
47
|
+
}: {
|
|
48
|
+
rootDir?: string
|
|
49
|
+
route?: string
|
|
50
|
+
virtualMode?: boolean
|
|
51
|
+
} = {}): FilesystemBackend {
|
|
52
|
+
const normalizedRoute = route.endsWith("/") ? route : `${route}/`
|
|
53
|
+
return new CompositeBackend(
|
|
54
|
+
new StateBackend(),
|
|
55
|
+
{
|
|
56
|
+
[normalizedRoute]: new FilesystemBackend({ rootDir, virtualMode }),
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
*/
|
|
61
|
+
export declare function createWorkspaceBackend({ rootDir, virtualMode, route, }: {
|
|
62
|
+
rootDir: string;
|
|
63
|
+
route?: string;
|
|
64
|
+
virtualMode?: boolean;
|
|
65
|
+
}): CompositeBackend;
|
|
66
|
+
/**
|
|
67
|
+
* LocalShell unter route (default /workspace/) + StateBackend für interne Agent-Dateien.
|
|
68
|
+
* execute() läuft weiter auf dem Host — nur für Dev.
|
|
69
|
+
* @example
|
|
70
|
+
* export async function createLocalShellBackend({
|
|
71
|
+
rootDir,
|
|
72
|
+
route = "/workspace/",
|
|
73
|
+
virtualMode = true,
|
|
74
|
+
...options
|
|
75
|
+
}: CreateLocalShellBackendOptions) {
|
|
76
|
+
const normalizedRoute = route.endsWith("/") ? route : `${route}/`
|
|
77
|
+
const shellBackend = await LocalShellBackend.create({
|
|
78
|
+
rootDir,
|
|
79
|
+
virtualMode,
|
|
80
|
+
...options,
|
|
81
|
+
})
|
|
82
|
+
return new CompositeBackend(
|
|
83
|
+
new StateBackend(),
|
|
84
|
+
{
|
|
85
|
+
[normalizedRoute]: shellBackend,
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
*/
|
|
90
|
+
export declare function createLocalShellBackend({ rootDir, route, virtualMode, ...options }: CreateLocalShellBackendOptions): Promise<CompositeBackend & ExecuteCapableDeepAgentBackend>;
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../../src/helpers/deepagent/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,iBAAiB,EAEjB,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAChC,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAA;AAEnE,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAA;AAE5E,KAAK,QAAQ,CAAC,CAAC,IAAI;KACd,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACvB,GAAG,EAAE,CAAA;AAEN,MAAM,MAAM,8BAA8B,GAAG,QAAQ,CACjD,IAAI,CAAC,wBAAwB,EAAE,SAAS,CAAC,GAAG;IACxC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAClB,CACJ,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAEjD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,EACpC,OAAuB,EACvB,WAAkB,EAClB,aAAa,GAChB,GAAE;IACC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,CAAA;CACpB,GAAG,iBAAiB,CAEzB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,EACnC,OAAO,EACP,WAAkB,EAClB,KAAqB,GACxB,EAAE;IACC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,OAAO,CAAA;CACxB,GAAG,gBAAgB,CAQnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,uBAAuB,CAAC,EAC1C,OAAO,EACP,KAAqB,EACrB,WAAkB,EAClB,GAAG,OAAO,EACb,EAAE,8BAA8B,GAAG,OAAO,CAAC,gBAAgB,GAAG,8BAA8B,CAAC,CAc7F"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { StateBackend, FilesystemBackend, LocalShellBackend, CompositeBackend, } from "../../imports";
|
|
2
|
+
/**
|
|
3
|
+
* erstellt einfach den StateBackend von langchain
|
|
4
|
+
* @example
|
|
5
|
+
* export function createStateBackend() {
|
|
6
|
+
return new StateBackend()
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
export function createStateBackend() {
|
|
10
|
+
return new StateBackend();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* erstellt ein reines Filesystembackend, nimm lieber 'createWorkspaceBackend()'
|
|
14
|
+
* @example
|
|
15
|
+
* export function createFilesystemBackend({
|
|
16
|
+
rootDir = process.cwd(),
|
|
17
|
+
virtualMode = true,
|
|
18
|
+
maxFileSizeMb,
|
|
19
|
+
}: {
|
|
20
|
+
rootDir?: string
|
|
21
|
+
virtualMode?: boolean
|
|
22
|
+
maxFileSizeMb?: number
|
|
23
|
+
} = {}): FilesystemBackend {
|
|
24
|
+
return new FilesystemBackend({ rootDir, virtualMode, maxFileSizeMb })
|
|
25
|
+
}
|
|
26
|
+
*/
|
|
27
|
+
export function createFilesystemBackend({ rootDir = process.cwd(), virtualMode = true, maxFileSizeMb, } = {}) {
|
|
28
|
+
return new FilesystemBackend({ rootDir, virtualMode, maxFileSizeMb });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* erstellt ein Filesystembackend mit einem normalem Statebackend damit dein workspace nicht beschmutzt wird
|
|
32
|
+
* @example
|
|
33
|
+
* export function createWorkspaceBackend({
|
|
34
|
+
rootDir = process.cwd(),
|
|
35
|
+
route = "/workspace/",
|
|
36
|
+
virtualMode = true,
|
|
37
|
+
}: {
|
|
38
|
+
rootDir?: string
|
|
39
|
+
route?: string
|
|
40
|
+
virtualMode?: boolean
|
|
41
|
+
} = {}): FilesystemBackend {
|
|
42
|
+
const normalizedRoute = route.endsWith("/") ? route : `${route}/`
|
|
43
|
+
return new CompositeBackend(
|
|
44
|
+
new StateBackend(),
|
|
45
|
+
{
|
|
46
|
+
[normalizedRoute]: new FilesystemBackend({ rootDir, virtualMode }),
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
*/
|
|
51
|
+
export function createWorkspaceBackend({ rootDir, virtualMode = true, route = "/workspace/", }) {
|
|
52
|
+
const normalizedRoute = route.endsWith("/") ? route : `${route}/`;
|
|
53
|
+
return new CompositeBackend(new StateBackend(), {
|
|
54
|
+
[normalizedRoute]: new FilesystemBackend({ rootDir, virtualMode }),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* LocalShell unter route (default /workspace/) + StateBackend für interne Agent-Dateien.
|
|
59
|
+
* execute() läuft weiter auf dem Host — nur für Dev.
|
|
60
|
+
* @example
|
|
61
|
+
* export async function createLocalShellBackend({
|
|
62
|
+
rootDir,
|
|
63
|
+
route = "/workspace/",
|
|
64
|
+
virtualMode = true,
|
|
65
|
+
...options
|
|
66
|
+
}: CreateLocalShellBackendOptions) {
|
|
67
|
+
const normalizedRoute = route.endsWith("/") ? route : `${route}/`
|
|
68
|
+
const shellBackend = await LocalShellBackend.create({
|
|
69
|
+
rootDir,
|
|
70
|
+
virtualMode,
|
|
71
|
+
...options,
|
|
72
|
+
})
|
|
73
|
+
return new CompositeBackend(
|
|
74
|
+
new StateBackend(),
|
|
75
|
+
{
|
|
76
|
+
[normalizedRoute]: shellBackend,
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
*/
|
|
81
|
+
export async function createLocalShellBackend({ rootDir, route = "/workspace/", virtualMode = true, ...options }) {
|
|
82
|
+
const normalizedRoute = route.endsWith("/") ? route : `${route}/`;
|
|
83
|
+
const shellBackend = await LocalShellBackend.create({
|
|
84
|
+
rootDir,
|
|
85
|
+
virtualMode,
|
|
86
|
+
...options,
|
|
87
|
+
});
|
|
88
|
+
const backend = new CompositeBackend(new StateBackend(), {
|
|
89
|
+
[normalizedRoute]: shellBackend,
|
|
90
|
+
});
|
|
91
|
+
return Object.assign(backend, { __deepAgentExecute: true });
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../../../src/helpers/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AM,CAAC;QAChD,OAAO;QACP,WAAW;QACX,GAAG,OAAO;KACb,CAAC,CAAA;IACF,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAChC,IAAI,YAAY,EAAE,EAClB;QACI,CAAC,eAAe,CAAC,EAAE,YAAY;KAClC,CACJ,CAAA;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,kBAAkB,EAAE,IAAa,EAAE,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Command, type HITLRequest, type HITLResponse, type HitlUserDecision } from "../../imports";
|
|
2
|
+
import type { CreateDeepAgentParams, DynamicStructuredTool } from "../../imports";
|
|
3
|
+
import type { LocalShellBackend } from "deepagents";
|
|
4
|
+
import type { DenoSandbox } from "@langchain/deno";
|
|
5
|
+
import type { DaytonaSandbox } from "@langchain/daytona";
|
|
6
|
+
import type { DeepAgentInterrupt, DeepAgentInterruptConfig, DeepAgentUserDecision } from "./interruptTypes";
|
|
7
|
+
export type { DeepAgentAllowedDecision, DeepAgentInterrupt, DeepAgentInterruptSingle, DeepAgentInterruptBatch, DeepAgentStreamChunk, DeepAgentUserDecision, DeepAgentRunInputBase, DeepAgentHitlFields, DeepAgentInterruptConfig, DeepAgentInterruptToolCall, DeepAgentInterruptQuestion, } from "./interruptTypes";
|
|
8
|
+
/** Immer verfügbare Filesystem-Tools von DeepAgents (Middleware). */
|
|
9
|
+
export declare const DEEP_AGENT_FILESYSTEM_TOOLS: readonly ["ls", "read_file", "write_file", "edit_file", "glob", "grep"];
|
|
10
|
+
/** Shell-Tool — nur wenn Backend `execute()` unterstützt (LocalShell, Deno, Daytona). */
|
|
11
|
+
export declare const DEEP_AGENT_EXECUTE_TOOL: "execute";
|
|
12
|
+
export type DeepAgentFilesystemTool = (typeof DEEP_AGENT_FILESYSTEM_TOOLS)[number];
|
|
13
|
+
export type DeepAgentExecuteTool = typeof DEEP_AGENT_EXECUTE_TOOL;
|
|
14
|
+
type ExecuteCapableBackend = LocalShellBackend | DenoSandbox | DaytonaSandbox;
|
|
15
|
+
/** Von `createLocalShellBackend()` etc. — aktiviert `execute` im interruptOn-Autocomplete. */
|
|
16
|
+
export type ExecuteCapableDeepAgentBackend = {
|
|
17
|
+
readonly __deepAgentExecute?: true;
|
|
18
|
+
};
|
|
19
|
+
/** Runtime: `execute` nur bei Shell/Sandbox-Backend — nicht bei `createWorkspaceBackend()` / Composite+StateBackend. */
|
|
20
|
+
export type BackendSupportsExecute<TBackend> = TBackend extends ExecuteCapableBackend | ExecuteCapableDeepAgentBackend ? true : false;
|
|
21
|
+
type LiteralToolName<TName extends string> = string extends TName ? never : TName;
|
|
22
|
+
export type ToolNamesOf<TTools extends readonly {
|
|
23
|
+
name: string;
|
|
24
|
+
}[]> = {
|
|
25
|
+
[K in keyof TTools]: TTools[K] extends {
|
|
26
|
+
name: infer TName extends string;
|
|
27
|
+
} ? LiteralToolName<TName> : never;
|
|
28
|
+
}[number];
|
|
29
|
+
/** Alle Tool-Namen die der Agent haben kann — Keys für `interruptOn`. */
|
|
30
|
+
export type DeepAgentInterruptableToolName<TTools extends readonly {
|
|
31
|
+
name: string;
|
|
32
|
+
}[] = readonly [], TBackend = unknown> = DeepAgentFilesystemTool | ToolNamesOf<TTools> | (BackendSupportsExecute<TBackend> extends true ? DeepAgentExecuteTool : never);
|
|
33
|
+
export type InterruptOnFor<TToolName extends string> = {
|
|
34
|
+
[K in TToolName]?: DeepAgentInterruptConfig;
|
|
35
|
+
};
|
|
36
|
+
/** Untyped fallback — prefer `InterruptOnFor<DeepAgentInterruptableToolName<...>>` via DeepAgent generics. */
|
|
37
|
+
export type InterruptOn = InterruptOnFor<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Human-in-the-Loop (`interruptOn`-Prop) — pausiert den Agent **vor** Tool-Ausführung.
|
|
40
|
+
*
|
|
41
|
+
* Keys = Tool-Namen die der Agent hat (Autocomplete via DeepAgent-Generics):
|
|
42
|
+
* - immer: `ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`
|
|
43
|
+
* - plus deine `tools: []` (`.name`, z.B. aus ToolRegistry)
|
|
44
|
+
* - plus `execute` nur bei Shell/Sandbox-Backend (LocalShell, Deno, Daytona)
|
|
45
|
+
*
|
|
46
|
+
* Tools die **nicht** im Objekt stehen, laufen ohne Pause.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* new DeepAgent({
|
|
50
|
+
* tools: [pingTool] as const,
|
|
51
|
+
* checkpointer: new MemorySaver(),
|
|
52
|
+
* interruptOn: {
|
|
53
|
+
* ping: {
|
|
54
|
+
* decisions: ["approve", "reject"],
|
|
55
|
+
* question: "Ping ausführen?",
|
|
56
|
+
* },
|
|
57
|
+
* write_file: {
|
|
58
|
+
* decisions: ["approve", "edit", "reject"],
|
|
59
|
+
* question: (call) =>
|
|
60
|
+
* `Datei schreiben?\n\nPfad: ${call.args.path ?? "?"}`,
|
|
61
|
+
* },
|
|
62
|
+
* },
|
|
63
|
+
* })
|
|
64
|
+
*
|
|
65
|
+
* `question` als Function: wird von LangGraph **vor** der Pause mit dem
|
|
66
|
+
* geplanten Tool-Call aufgerufen — `call.name` + `call.args`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function mapInterruptOnToNative(interruptOn: InterruptOnFor<string> | undefined): NonNullable<CreateDeepAgentParams["interruptOn"]> | undefined;
|
|
69
|
+
export type InferInterruptOn<TTools extends readonly DynamicStructuredTool[] = readonly DynamicStructuredTool[], TBackend = unknown> = InterruptOnFor<DeepAgentInterruptableToolName<TTools, TBackend>>;
|
|
70
|
+
type InterruptResult = {
|
|
71
|
+
__interrupt__?: Array<{
|
|
72
|
+
value: HITLRequest;
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Prüft ob ein Agent-Result pausiert hat (Human-in-the-Loop).
|
|
77
|
+
*/
|
|
78
|
+
export declare function isInterruptResult(result: unknown): result is InterruptResult & {
|
|
79
|
+
__interrupt__: NonNullable<InterruptResult["__interrupt__"]>;
|
|
80
|
+
};
|
|
81
|
+
export declare function getHitlRequest(result: InterruptResult): HITLRequest | undefined;
|
|
82
|
+
export declare function approveDecision(): HitlUserDecision;
|
|
83
|
+
export declare function rejectDecision(message?: string): HitlUserDecision;
|
|
84
|
+
export declare function editDecision(name: string, args: Record<string, unknown>): HitlUserDecision;
|
|
85
|
+
export declare function approveAll(count: number): HITLResponse;
|
|
86
|
+
export declare function createResumeCommand(decisions: HitlUserDecision[] | HITLResponse): Command;
|
|
87
|
+
export declare function mapHitlToInterrupt(hitl: HITLRequest): DeepAgentInterrupt;
|
|
88
|
+
export declare function mapResultToInterrupt(result: unknown): DeepAgentInterrupt | undefined;
|
|
89
|
+
export declare function userDecisionToHitl(decision: DeepAgentUserDecision, toolName?: string): HitlUserDecision;
|
|
90
|
+
export declare function expandResumeDecisions(decision: DeepAgentUserDecision | undefined, decisions: DeepAgentUserDecision[] | undefined, pendingCount: number, defaultToolName?: string): HitlUserDecision[];
|
|
91
|
+
export declare function getPendingInterruptCount(agent: any, config: Record<string, unknown> | undefined): Promise<number>;
|
|
92
|
+
export declare function extractInterruptFromStreamUpdate(data: unknown): DeepAgentInterrupt | undefined;
|
|
93
|
+
//# sourceMappingURL=interruptOn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interruptOn.d.ts","sourceRoot":"","sources":["../../../src/helpers/deepagent/interruptOn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACnG,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,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
|
+
"ls",
|
|
5
|
+
"read_file",
|
|
6
|
+
"write_file",
|
|
7
|
+
"edit_file",
|
|
8
|
+
"glob",
|
|
9
|
+
"grep",
|
|
10
|
+
];
|
|
11
|
+
/** Shell-Tool — nur wenn Backend `execute()` unterstützt (LocalShell, Deno, Daytona). */
|
|
12
|
+
export const DEEP_AGENT_EXECUTE_TOOL = "execute";
|
|
13
|
+
/**
|
|
14
|
+
* Human-in-the-Loop (`interruptOn`-Prop) — pausiert den Agent **vor** Tool-Ausführung.
|
|
15
|
+
*
|
|
16
|
+
* Keys = Tool-Namen die der Agent hat (Autocomplete via DeepAgent-Generics):
|
|
17
|
+
* - immer: `ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`
|
|
18
|
+
* - plus deine `tools: []` (`.name`, z.B. aus ToolRegistry)
|
|
19
|
+
* - plus `execute` nur bei Shell/Sandbox-Backend (LocalShell, Deno, Daytona)
|
|
20
|
+
*
|
|
21
|
+
* Tools die **nicht** im Objekt stehen, laufen ohne Pause.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* new DeepAgent({
|
|
25
|
+
* tools: [pingTool] as const,
|
|
26
|
+
* checkpointer: new MemorySaver(),
|
|
27
|
+
* interruptOn: {
|
|
28
|
+
* ping: {
|
|
29
|
+
* decisions: ["approve", "reject"],
|
|
30
|
+
* question: "Ping ausführen?",
|
|
31
|
+
* },
|
|
32
|
+
* write_file: {
|
|
33
|
+
* decisions: ["approve", "edit", "reject"],
|
|
34
|
+
* question: (call) =>
|
|
35
|
+
* `Datei schreiben?\n\nPfad: ${call.args.path ?? "?"}`,
|
|
36
|
+
* },
|
|
37
|
+
* },
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* `question` als Function: wird von LangGraph **vor** der Pause mit dem
|
|
41
|
+
* geplanten Tool-Call aufgerufen — `call.name` + `call.args`.
|
|
42
|
+
*/
|
|
43
|
+
export function mapInterruptOnToNative(interruptOn) {
|
|
44
|
+
if (!interruptOn)
|
|
45
|
+
return undefined;
|
|
46
|
+
return Object.fromEntries(Object.entries(interruptOn)
|
|
47
|
+
.filter((entry) => entry[1] !== undefined)
|
|
48
|
+
.map(([tool, config]) => [
|
|
49
|
+
tool,
|
|
50
|
+
{
|
|
51
|
+
allowedDecisions: config.decisions,
|
|
52
|
+
description: config.question,
|
|
53
|
+
},
|
|
54
|
+
]));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Prüft ob ein Agent-Result pausiert hat (Human-in-the-Loop).
|
|
58
|
+
*/
|
|
59
|
+
export function isInterruptResult(result) {
|
|
60
|
+
return (typeof result === "object"
|
|
61
|
+
&& result !== null
|
|
62
|
+
&& "__interrupt__" in result
|
|
63
|
+
&& Array.isArray(result.__interrupt__)
|
|
64
|
+
&& (result.__interrupt__?.length ?? 0) > 0);
|
|
65
|
+
}
|
|
66
|
+
export function getHitlRequest(result) {
|
|
67
|
+
return result.__interrupt__?.[0]?.value;
|
|
68
|
+
}
|
|
69
|
+
export function approveDecision() {
|
|
70
|
+
return { type: "approve" };
|
|
71
|
+
}
|
|
72
|
+
export function rejectDecision(message) {
|
|
73
|
+
return message ? { type: "reject", message } : { type: "reject" };
|
|
74
|
+
}
|
|
75
|
+
export function editDecision(name, args) {
|
|
76
|
+
return { type: "edit", editedAction: { name, args } };
|
|
77
|
+
}
|
|
78
|
+
export function approveAll(count) {
|
|
79
|
+
return {
|
|
80
|
+
decisions: Array.from({ length: count }, () => approveDecision()),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function createResumeCommand(decisions) {
|
|
84
|
+
const resume = Array.isArray(decisions)
|
|
85
|
+
? { decisions }
|
|
86
|
+
: decisions;
|
|
87
|
+
return new Command({ resume });
|
|
88
|
+
}
|
|
89
|
+
export function mapHitlToInterrupt(hitl) {
|
|
90
|
+
const requests = hitl.actionRequests ?? [];
|
|
91
|
+
const reviews = hitl.reviewConfigs ?? [];
|
|
92
|
+
if (requests.length <= 1) {
|
|
93
|
+
const action = requests[0];
|
|
94
|
+
const review = reviews[0];
|
|
95
|
+
return {
|
|
96
|
+
kind: "interrupt",
|
|
97
|
+
question: action?.description ?? `Tool: ${action?.name ?? "unknown"}`,
|
|
98
|
+
decisions: (review?.allowedDecisions ?? ["approve", "reject"]),
|
|
99
|
+
...(action?.name ? { toolName: action.name } : {}),
|
|
100
|
+
...(action?.args ? { args: action.args } : {}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
kind: "interrupt",
|
|
105
|
+
items: requests.map((action, i) => ({
|
|
106
|
+
question: action.description ?? `Tool: ${action.name}`,
|
|
107
|
+
decisions: (reviews[i]?.allowedDecisions ?? ["approve", "reject"]),
|
|
108
|
+
toolName: action.name,
|
|
109
|
+
args: (action.args ?? {}),
|
|
110
|
+
})),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function mapResultToInterrupt(result) {
|
|
114
|
+
if (!isInterruptResult(result))
|
|
115
|
+
return undefined;
|
|
116
|
+
const hitl = getHitlRequest(result);
|
|
117
|
+
if (!hitl)
|
|
118
|
+
return undefined;
|
|
119
|
+
return mapHitlToInterrupt(hitl);
|
|
120
|
+
}
|
|
121
|
+
export function userDecisionToHitl(decision, toolName) {
|
|
122
|
+
if (decision === "approve")
|
|
123
|
+
return approveDecision();
|
|
124
|
+
if (decision === "reject")
|
|
125
|
+
return rejectDecision();
|
|
126
|
+
if (decision.type === "reject")
|
|
127
|
+
return rejectDecision(decision.message);
|
|
128
|
+
if (!toolName) {
|
|
129
|
+
throw new Error("toolName is required for edit decisions");
|
|
130
|
+
}
|
|
131
|
+
return editDecision(toolName, decision.args);
|
|
132
|
+
}
|
|
133
|
+
export function expandResumeDecisions(decision, decisions, pendingCount, defaultToolName) {
|
|
134
|
+
if (decisions) {
|
|
135
|
+
if (decisions.length !== pendingCount) {
|
|
136
|
+
throw new Error(`Expected ${pendingCount} decisions, got ${decisions.length}`);
|
|
137
|
+
}
|
|
138
|
+
return decisions.map((d) => userDecisionToHitl(d, defaultToolName));
|
|
139
|
+
}
|
|
140
|
+
const single = decision ?? "approve";
|
|
141
|
+
return Array.from({ length: pendingCount }, () => userDecisionToHitl(single, defaultToolName));
|
|
142
|
+
}
|
|
143
|
+
export async function getPendingInterruptCount(agent, config) {
|
|
144
|
+
if (!agent?.getState || !config)
|
|
145
|
+
return 1;
|
|
146
|
+
try {
|
|
147
|
+
const state = await agent.getState(config);
|
|
148
|
+
const tasks = state?.tasks ?? [];
|
|
149
|
+
for (const task of tasks) {
|
|
150
|
+
const interrupts = task?.interrupts ?? [];
|
|
151
|
+
if (interrupts.length > 0) {
|
|
152
|
+
const value = interrupts[0]?.value ?? interrupts[0];
|
|
153
|
+
if (value?.actionRequests?.length)
|
|
154
|
+
return value.actionRequests.length;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const values = state?.values;
|
|
158
|
+
if (values?.__interrupt__?.length) {
|
|
159
|
+
const hitl = values.__interrupt__[0]?.value;
|
|
160
|
+
if (hitl?.actionRequests?.length)
|
|
161
|
+
return hitl.actionRequests.length;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
export function extractInterruptFromStreamUpdate(data) {
|
|
170
|
+
if (!data || typeof data !== "object")
|
|
171
|
+
return undefined;
|
|
172
|
+
const record = data;
|
|
173
|
+
if ("__interrupt__" in record && Array.isArray(record.__interrupt__)) {
|
|
174
|
+
const hitl = record.__interrupt__[0]?.value;
|
|
175
|
+
if (hitl)
|
|
176
|
+
return mapHitlToInterrupt(hitl);
|
|
177
|
+
}
|
|
178
|
+
for (const value of Object.values(record)) {
|
|
179
|
+
if (!value || typeof value !== "object")
|
|
180
|
+
continue;
|
|
181
|
+
const nested = value;
|
|
182
|
+
if ("__interrupt__" in nested && Array.isArray(nested.__interrupt__)) {
|
|
183
|
+
const hitl = nested.__interrupt__[0]?.value;
|
|
184
|
+
if (hitl)
|
|
185
|
+
return mapHitlToInterrupt(hitl);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=interruptOn.js.map
|