@adminforth/agent 1.9.1 → 1.10.0
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AIMessage } from "@langchain/core/messages";
|
|
2
|
+
import { convertMessagesToResponsesInput } from "@langchain/openai";
|
|
2
3
|
import { createMiddleware } from "langchain";
|
|
3
4
|
import YAML from "yaml";
|
|
4
5
|
import type { ToolCallEvent } from "../toolCallEvents.js";
|
|
@@ -120,44 +121,36 @@ function finalizeSequenceDebug(sequence: PendingSequenceDebug): SequenceDebug {
|
|
|
120
121
|
};
|
|
121
122
|
}
|
|
122
123
|
|
|
124
|
+
type OpenAiResponsesDebugModel = {
|
|
125
|
+
model: string;
|
|
126
|
+
zdrEnabled?: boolean;
|
|
127
|
+
invocationParams: (options?: Record<string, unknown>) => Record<string, unknown>;
|
|
128
|
+
};
|
|
129
|
+
|
|
123
130
|
function stringifyPromptForDebug(params: {
|
|
124
|
-
|
|
125
|
-
|
|
131
|
+
model: OpenAiResponsesDebugModel;
|
|
132
|
+
systemMessage: { text: string };
|
|
133
|
+
messages: unknown[];
|
|
126
134
|
tools: unknown[];
|
|
135
|
+
toolChoice?: unknown;
|
|
127
136
|
modelSettings?: Record<string, unknown>;
|
|
128
137
|
}) {
|
|
129
|
-
const { systemMessage, messages, tools, modelSettings } = params;
|
|
138
|
+
const { model, systemMessage, messages, tools, toolChoice, modelSettings } = params;
|
|
130
139
|
|
|
131
140
|
return YAML.stringify({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
typeof tool === "object" &&
|
|
146
|
-
tool !== null &&
|
|
147
|
-
"schema" in tool &&
|
|
148
|
-
typeof tool.schema === "object" &&
|
|
149
|
-
tool.schema !== null &&
|
|
150
|
-
"name" in tool.schema &&
|
|
151
|
-
typeof tool.schema.name === "string"
|
|
152
|
-
) {
|
|
153
|
-
return tool.schema.name;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return "";
|
|
141
|
+
input: convertMessagesToResponsesInput({
|
|
142
|
+
messages: [
|
|
143
|
+
...(systemMessage.text === "" ? [] : [systemMessage]),
|
|
144
|
+
...messages,
|
|
145
|
+
] as any[],
|
|
146
|
+
zdrEnabled: model.zdrEnabled ?? false,
|
|
147
|
+
model: model.model,
|
|
148
|
+
}),
|
|
149
|
+
...model.invocationParams({
|
|
150
|
+
...(modelSettings ?? {}),
|
|
151
|
+
...(tools.length > 0 ? { tools } : {}),
|
|
152
|
+
...(toolChoice !== undefined ? { tool_choice: toolChoice } : {}),
|
|
157
153
|
}),
|
|
158
|
-
...(modelSettings && Object.keys(modelSettings).length > 0
|
|
159
|
-
? { modelSettings }
|
|
160
|
-
: {}),
|
|
161
154
|
});
|
|
162
155
|
}
|
|
163
156
|
|
|
@@ -356,9 +349,11 @@ export function createSequenceDebugMiddleware(
|
|
|
356
349
|
name: "SequenceDebugMiddleware",
|
|
357
350
|
async wrapModelCall(request, handler) {
|
|
358
351
|
const prompt = stringifyPromptForDebug({
|
|
352
|
+
model: request.model as unknown as OpenAiResponsesDebugModel,
|
|
359
353
|
systemMessage: request.systemMessage,
|
|
360
354
|
messages: request.messages,
|
|
361
355
|
tools: request.tools,
|
|
356
|
+
toolChoice: request.toolChoice,
|
|
362
357
|
modelSettings: request.modelSettings,
|
|
363
358
|
});
|
|
364
359
|
|
|
@@ -18,6 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
+
import { convertMessagesToResponsesInput } from "@langchain/openai";
|
|
21
22
|
import { createMiddleware } from "langchain";
|
|
22
23
|
import YAML from "yaml";
|
|
23
24
|
function createPendingSequenceDebug(sequenceId) {
|
|
@@ -66,27 +67,16 @@ function finalizeSequenceDebug(sequence) {
|
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
69
|
function stringifyPromptForDebug(params) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"schema" in tool &&
|
|
80
|
-
typeof tool.schema === "object" &&
|
|
81
|
-
tool.schema !== null &&
|
|
82
|
-
"name" in tool.schema &&
|
|
83
|
-
typeof tool.schema.name === "string") {
|
|
84
|
-
return tool.schema.name;
|
|
85
|
-
}
|
|
86
|
-
return "";
|
|
87
|
-
}) }, (modelSettings && Object.keys(modelSettings).length > 0
|
|
88
|
-
? { modelSettings }
|
|
89
|
-
: {})));
|
|
70
|
+
var _a;
|
|
71
|
+
const { model, systemMessage, messages, tools, toolChoice, modelSettings } = params;
|
|
72
|
+
return YAML.stringify(Object.assign({ input: convertMessagesToResponsesInput({
|
|
73
|
+
messages: [
|
|
74
|
+
...(systemMessage.text === "" ? [] : [systemMessage]),
|
|
75
|
+
...messages,
|
|
76
|
+
],
|
|
77
|
+
zdrEnabled: (_a = model.zdrEnabled) !== null && _a !== void 0 ? _a : false,
|
|
78
|
+
model: model.model,
|
|
79
|
+
}) }, model.invocationParams(Object.assign(Object.assign(Object.assign({}, (modelSettings !== null && modelSettings !== void 0 ? modelSettings : {})), (tools.length > 0 ? { tools } : {})), (toolChoice !== undefined ? { tool_choice: toolChoice } : {})))));
|
|
90
80
|
}
|
|
91
81
|
function getMessageBlocks(message) {
|
|
92
82
|
if (Array.isArray(message.contentBlocks)) {
|
|
@@ -234,9 +224,11 @@ export function createSequenceDebugMiddleware(sink) {
|
|
|
234
224
|
wrapModelCall(request, handler) {
|
|
235
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
226
|
const prompt = stringifyPromptForDebug({
|
|
227
|
+
model: request.model,
|
|
237
228
|
systemMessage: request.systemMessage,
|
|
238
229
|
messages: request.messages,
|
|
239
230
|
tools: request.tools,
|
|
231
|
+
toolChoice: request.toolChoice,
|
|
240
232
|
modelSettings: request.modelSettings,
|
|
241
233
|
});
|
|
242
234
|
sink.handleModelCallStart(prompt);
|