@adminforth/agent 1.50.1 → 1.51.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/agent/middleware/apiBasedTools.ts +13 -3
- package/agent/models/AgentModeResolver.ts +9 -0
- package/agent/models/AgentModelFactory.ts +28 -0
- package/agent/runtime/AgentContext.ts +30 -0
- package/agent/runtime/AgentRuntime.ts +68 -0
- package/agent/simpleAgent.ts +2 -129
- package/agent/speech/SpeechTurnService.ts +179 -0
- package/agent/tools/AgentToolProvider.ts +28 -0
- package/agent/tools/navigateUser.ts +2 -2
- package/agent/turn/TurnContextBuilder.ts +36 -0
- package/agent/turn/TurnLifecycleService.ts +29 -0
- package/agent/turn/TurnPersistenceService.ts +33 -0
- package/agent/turn/TurnPromptBuilder.ts +51 -0
- package/agent/turn/TurnStreamConsumer.ts +61 -0
- package/agent/turn/VegaLiteStreamBuffer.ts +90 -0
- package/agent/turn/turnTypes.ts +92 -0
- package/agentTurnService.ts +88 -461
- package/build.log +1 -1
- package/dist/agent/middleware/apiBasedTools.js +9 -2
- package/dist/agent/models/AgentModeResolver.d.ts +9 -0
- package/dist/agent/models/AgentModeResolver.js +9 -0
- package/dist/agent/models/AgentModelFactory.d.ts +7 -0
- package/dist/agent/models/AgentModelFactory.js +36 -0
- package/dist/agent/runtime/AgentContext.d.ts +28 -0
- package/dist/agent/runtime/AgentContext.js +17 -0
- package/dist/agent/runtime/AgentRuntime.d.ts +15 -0
- package/dist/agent/runtime/AgentRuntime.js +57 -0
- package/dist/agent/simpleAgent.d.ts +15 -45
- package/dist/agent/simpleAgent.js +1 -67
- package/dist/agent/speech/SpeechTurnService.d.ts +6 -0
- package/dist/agent/speech/SpeechTurnService.js +168 -0
- package/dist/agent/tools/AgentToolProvider.d.ts +9 -0
- package/dist/agent/tools/AgentToolProvider.js +27 -0
- package/dist/agent/tools/navigateUser.js +1 -1
- package/dist/agent/turn/TurnContextBuilder.d.ts +14 -0
- package/dist/agent/turn/TurnContextBuilder.js +31 -0
- package/dist/agent/turn/TurnLifecycleService.d.ts +17 -0
- package/dist/agent/turn/TurnLifecycleService.js +31 -0
- package/dist/agent/turn/TurnPersistenceService.d.ts +13 -0
- package/dist/agent/turn/TurnPersistenceService.js +35 -0
- package/dist/agent/turn/TurnPromptBuilder.d.ts +19 -0
- package/dist/agent/turn/TurnPromptBuilder.js +43 -0
- package/dist/agent/turn/TurnStreamConsumer.d.ts +10 -0
- package/dist/agent/turn/TurnStreamConsumer.js +78 -0
- package/dist/agent/turn/VegaLiteStreamBuffer.d.ts +7 -0
- package/dist/agent/turn/VegaLiteStreamBuffer.js +87 -0
- package/dist/agent/turn/turnTypes.d.ts +81 -0
- package/dist/agent/turn/turnTypes.js +1 -0
- package/dist/agentTurnService.d.ts +20 -69
- package/dist/agentTurnService.js +60 -373
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22 -7
- package/index.ts +35 -7
- package/package.json +6 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AdminUser, IAdminForth } from "adminforth";
|
|
2
|
+
import { HumanMessage, SystemMessage } from "langchain";
|
|
3
|
+
import { type PreviousUserMessage } from "../languageDetect.js";
|
|
4
|
+
import type { AgentModeCompletionAdapter } from "../simpleAgent.js";
|
|
5
|
+
export declare class TurnPromptBuilder {
|
|
6
|
+
private readonly options;
|
|
7
|
+
constructor(options: {
|
|
8
|
+
getAgentSystemPrompt: () => Promise<string>;
|
|
9
|
+
getAdminforth: () => IAdminForth;
|
|
10
|
+
});
|
|
11
|
+
build(input: {
|
|
12
|
+
prompt: string;
|
|
13
|
+
previousUserMessages: PreviousUserMessage[];
|
|
14
|
+
adminUser: AdminUser;
|
|
15
|
+
completionAdapter: AgentModeCompletionAdapter;
|
|
16
|
+
chatSurface?: string;
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
}): Promise<(SystemMessage<import("@langchain/core/messages").MessageStructure<import("@langchain/core/messages").MessageToolSet>> | HumanMessage<import("@langchain/core/messages").MessageStructure<import("@langchain/core/messages").MessageToolSet>>)[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { logger } from "adminforth";
|
|
11
|
+
import { HumanMessage, SystemMessage } from "langchain";
|
|
12
|
+
import { detectUserLanguage } from "../languageDetect.js";
|
|
13
|
+
import { buildAgentTurnSystemPrompt } from "../systemPrompt.js";
|
|
14
|
+
import { getErrorMessage, isAbortError } from "../../errors.js";
|
|
15
|
+
export class TurnPromptBuilder {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
build(input) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const adminforth = this.options.getAdminforth();
|
|
22
|
+
const userLanguage = yield detectUserLanguage(input.completionAdapter, input.prompt, input.previousUserMessages).catch((error) => {
|
|
23
|
+
var _a;
|
|
24
|
+
if (((_a = input.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) || isAbortError(error)) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
logger.warn(`Failed to detect user language: ${getErrorMessage(error)}`);
|
|
28
|
+
return null;
|
|
29
|
+
});
|
|
30
|
+
const systemPrompt = buildAgentTurnSystemPrompt({
|
|
31
|
+
agentSystemPrompt: yield this.options.getAgentSystemPrompt(),
|
|
32
|
+
adminUser: input.adminUser,
|
|
33
|
+
usernameField: adminforth.config.auth.usernameField,
|
|
34
|
+
userLanguage,
|
|
35
|
+
chatSurface: input.chatSurface,
|
|
36
|
+
});
|
|
37
|
+
return [
|
|
38
|
+
new SystemMessage(systemPrompt),
|
|
39
|
+
new HumanMessage(input.prompt),
|
|
40
|
+
];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentEventEmitter } from "../../agentEvents.js";
|
|
2
|
+
export declare class TurnStreamConsumer {
|
|
3
|
+
consume(input: {
|
|
4
|
+
stream: AsyncIterable<[any, any]>;
|
|
5
|
+
abortSignal?: AbortSignal;
|
|
6
|
+
emit?: AgentEventEmitter;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
text: string;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var m = o[Symbol.asyncIterator], i;
|
|
13
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
14
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
15
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
};
|
|
17
|
+
import { VegaLiteStreamBuffer } from "./VegaLiteStreamBuffer.js";
|
|
18
|
+
export class TurnStreamConsumer {
|
|
19
|
+
consume(input) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a, e_1, _b, _c;
|
|
22
|
+
var _d, _e;
|
|
23
|
+
let fullResponse = "";
|
|
24
|
+
const textBuffer = new VegaLiteStreamBuffer();
|
|
25
|
+
try {
|
|
26
|
+
for (var _f = true, _g = __asyncValues(input.stream), _h; _h = yield _g.next(), _a = _h.done, !_a; _f = true) {
|
|
27
|
+
_c = _h.value;
|
|
28
|
+
_f = false;
|
|
29
|
+
const rawChunk = _c;
|
|
30
|
+
if ((_d = input.abortSignal) === null || _d === void 0 ? void 0 : _d.aborted) {
|
|
31
|
+
throw new DOMException("This operation was aborted", "AbortError");
|
|
32
|
+
}
|
|
33
|
+
const [token, metadata] = rawChunk;
|
|
34
|
+
const nodeName = typeof (metadata === null || metadata === void 0 ? void 0 : metadata.langgraph_node) === "string"
|
|
35
|
+
? metadata.langgraph_node
|
|
36
|
+
: "";
|
|
37
|
+
if (nodeName && !["model", "model_request"].includes(nodeName)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const blocks = Array.isArray(token === null || token === void 0 ? void 0 : token.contentBlocks)
|
|
41
|
+
? token.contentBlocks
|
|
42
|
+
: Array.isArray(token === null || token === void 0 ? void 0 : token.content)
|
|
43
|
+
? token.content
|
|
44
|
+
: [];
|
|
45
|
+
const reasoningDelta = blocks
|
|
46
|
+
.filter((block) => (block === null || block === void 0 ? void 0 : block.type) === "reasoning")
|
|
47
|
+
.map((block) => { var _a; return String((_a = block.reasoning) !== null && _a !== void 0 ? _a : ""); })
|
|
48
|
+
.join("");
|
|
49
|
+
const textDelta = blocks
|
|
50
|
+
.filter((block) => (block === null || block === void 0 ? void 0 : block.type) === "text")
|
|
51
|
+
.map((block) => { var _a; return String((_a = block.text) !== null && _a !== void 0 ? _a : ""); })
|
|
52
|
+
.join("");
|
|
53
|
+
if (reasoningDelta) {
|
|
54
|
+
yield ((_e = input.emit) === null || _e === void 0 ? void 0 : _e.call(input, {
|
|
55
|
+
type: "reasoning-delta",
|
|
56
|
+
delta: reasoningDelta,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
if (textDelta) {
|
|
60
|
+
fullResponse += textDelta;
|
|
61
|
+
yield textBuffer.push(textDelta, input.emit);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
66
|
+
finally {
|
|
67
|
+
try {
|
|
68
|
+
if (!_f && !_a && (_b = _g.return)) yield _b.call(_g);
|
|
69
|
+
}
|
|
70
|
+
finally { if (e_1) throw e_1.error; }
|
|
71
|
+
}
|
|
72
|
+
yield textBuffer.flush(input.emit);
|
|
73
|
+
return {
|
|
74
|
+
text: fullResponse,
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentEventEmitter } from "../../agentEvents.js";
|
|
2
|
+
export declare class VegaLiteStreamBuffer {
|
|
3
|
+
private bufferedTextDelta;
|
|
4
|
+
private isRenderingVegaLite;
|
|
5
|
+
push(textDelta: string, emit?: AgentEventEmitter): Promise<void>;
|
|
6
|
+
flush(emit?: AgentEventEmitter): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const VEGA_LITE_FENCE_START = "```vega-lite";
|
|
11
|
+
const FENCE_END = "```";
|
|
12
|
+
export class VegaLiteStreamBuffer {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.bufferedTextDelta = "";
|
|
15
|
+
this.isRenderingVegaLite = false;
|
|
16
|
+
}
|
|
17
|
+
push(textDelta, emit) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
this.bufferedTextDelta += textDelta;
|
|
20
|
+
if (hasUnclosedLatestVegaLiteBlock(this.bufferedTextDelta)) {
|
|
21
|
+
if (!this.isRenderingVegaLite) {
|
|
22
|
+
this.isRenderingVegaLite = true;
|
|
23
|
+
yield (emit === null || emit === void 0 ? void 0 : emit({
|
|
24
|
+
type: "rendering",
|
|
25
|
+
phase: "start",
|
|
26
|
+
label: "Rendering...",
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (this.isRenderingVegaLite) {
|
|
32
|
+
this.isRenderingVegaLite = false;
|
|
33
|
+
yield (emit === null || emit === void 0 ? void 0 : emit({
|
|
34
|
+
type: "rendering",
|
|
35
|
+
phase: "end",
|
|
36
|
+
label: "Rendering...",
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
const streamableLength = this.bufferedTextDelta.includes(VEGA_LITE_FENCE_START)
|
|
40
|
+
? this.bufferedTextDelta.length
|
|
41
|
+
: this.bufferedTextDelta.length - getPartialVegaLiteFenceStartLength(this.bufferedTextDelta);
|
|
42
|
+
if (!streamableLength) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
yield (emit === null || emit === void 0 ? void 0 : emit({
|
|
46
|
+
type: "text-delta",
|
|
47
|
+
delta: this.bufferedTextDelta.slice(0, streamableLength),
|
|
48
|
+
}));
|
|
49
|
+
this.bufferedTextDelta = this.bufferedTextDelta.slice(streamableLength);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
flush(emit) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (this.isRenderingVegaLite) {
|
|
55
|
+
yield (emit === null || emit === void 0 ? void 0 : emit({
|
|
56
|
+
type: "rendering",
|
|
57
|
+
phase: "end",
|
|
58
|
+
label: "Rendering...",
|
|
59
|
+
}));
|
|
60
|
+
this.isRenderingVegaLite = false;
|
|
61
|
+
}
|
|
62
|
+
if (this.bufferedTextDelta) {
|
|
63
|
+
yield (emit === null || emit === void 0 ? void 0 : emit({
|
|
64
|
+
type: "text-delta",
|
|
65
|
+
delta: this.bufferedTextDelta,
|
|
66
|
+
}));
|
|
67
|
+
this.bufferedTextDelta = "";
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function hasUnclosedLatestVegaLiteBlock(text) {
|
|
73
|
+
const latestBlockStart = text.lastIndexOf(VEGA_LITE_FENCE_START);
|
|
74
|
+
if (latestBlockStart === -1) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const blockContentStart = latestBlockStart + VEGA_LITE_FENCE_START.length;
|
|
78
|
+
return text.indexOf(FENCE_END, blockContentStart) === -1;
|
|
79
|
+
}
|
|
80
|
+
function getPartialVegaLiteFenceStartLength(text) {
|
|
81
|
+
for (let length = Math.min(text.length, VEGA_LITE_FENCE_START.length - 1); length > 0; length -= 1) {
|
|
82
|
+
if (VEGA_LITE_FENCE_START.startsWith(text.slice(-length))) {
|
|
83
|
+
return length;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { AdminUser, AudioAdapter } from "adminforth";
|
|
2
|
+
import type { Messages } from "@langchain/langgraph";
|
|
3
|
+
import type { AgentChatModel, AgentMiddleware } from "../simpleAgent.js";
|
|
4
|
+
import type { SequenceDebugCollector } from "../middleware/sequenceDebug.js";
|
|
5
|
+
import type { PreviousUserMessage } from "../languageDetect.js";
|
|
6
|
+
import type { CurrentPageContext } from "../tools/getUserLocation.js";
|
|
7
|
+
import type { AgentEventEmitter } from "../../agentEvents.js";
|
|
8
|
+
export type BaseAgentTurnInput = {
|
|
9
|
+
prompt: string;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
modeName?: string | null;
|
|
12
|
+
userTimeZone?: string;
|
|
13
|
+
currentPage?: CurrentPageContext;
|
|
14
|
+
chatSurface?: string;
|
|
15
|
+
adminPublicOrigin?: string;
|
|
16
|
+
abortSignal?: AbortSignal;
|
|
17
|
+
adminUser: AdminUser;
|
|
18
|
+
};
|
|
19
|
+
export type TextAgentTurnInput = BaseAgentTurnInput & {
|
|
20
|
+
emit: AgentEventEmitter;
|
|
21
|
+
failureLogMessage?: string;
|
|
22
|
+
abortLogMessage?: string;
|
|
23
|
+
};
|
|
24
|
+
export type SpeechAgentTurnInput = Omit<BaseAgentTurnInput, "prompt"> & {
|
|
25
|
+
emit: AgentEventEmitter;
|
|
26
|
+
audioAdapter: AudioAdapter;
|
|
27
|
+
audio: {
|
|
28
|
+
buffer: Buffer;
|
|
29
|
+
filename: string;
|
|
30
|
+
mimeType: string;
|
|
31
|
+
};
|
|
32
|
+
failureLogMessage?: string;
|
|
33
|
+
abortLogMessage?: string;
|
|
34
|
+
};
|
|
35
|
+
export type AgentTurnContext = {
|
|
36
|
+
adminUser: AdminUser;
|
|
37
|
+
userTimeZone: string;
|
|
38
|
+
sessionId: string;
|
|
39
|
+
turnId: string;
|
|
40
|
+
abortSignal?: AbortSignal;
|
|
41
|
+
currentPage?: CurrentPageContext;
|
|
42
|
+
chatSurface?: string;
|
|
43
|
+
adminPublicOrigin?: string;
|
|
44
|
+
};
|
|
45
|
+
export type AgentTurnObservability = {
|
|
46
|
+
emit?: AgentEventEmitter;
|
|
47
|
+
sequenceDebugSink: SequenceDebugCollector;
|
|
48
|
+
};
|
|
49
|
+
export type PreparedAgentTurn = {
|
|
50
|
+
prompt: string;
|
|
51
|
+
sessionId: string;
|
|
52
|
+
turnId: string;
|
|
53
|
+
previousUserMessages: PreviousUserMessage[];
|
|
54
|
+
modeName?: string | null;
|
|
55
|
+
context: AgentTurnContext;
|
|
56
|
+
observability: AgentTurnObservability;
|
|
57
|
+
};
|
|
58
|
+
export type AgentTurnModels = {
|
|
59
|
+
model: AgentChatModel;
|
|
60
|
+
summaryModel: AgentChatModel;
|
|
61
|
+
modelMiddleware?: AgentMiddleware[];
|
|
62
|
+
};
|
|
63
|
+
export type AgentRuntimeRunInput = {
|
|
64
|
+
models: AgentTurnModels;
|
|
65
|
+
messages: Messages;
|
|
66
|
+
context: AgentTurnContext;
|
|
67
|
+
observability: AgentTurnObservability;
|
|
68
|
+
};
|
|
69
|
+
export type RunAndPersistAgentResponseInput = BaseAgentTurnInput & {
|
|
70
|
+
emit?: AgentEventEmitter;
|
|
71
|
+
failureLogMessage: string;
|
|
72
|
+
abortLogMessage: string;
|
|
73
|
+
};
|
|
74
|
+
export type RunAndPersistAgentResponseResult = {
|
|
75
|
+
text: string;
|
|
76
|
+
turnId: string;
|
|
77
|
+
aborted: boolean;
|
|
78
|
+
failed: boolean;
|
|
79
|
+
};
|
|
80
|
+
export type HandleTurnInput = TextAgentTurnInput;
|
|
81
|
+
export type HandleSpeechTurnInput = SpeechAgentTurnInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,72 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
modeName?: string | null;
|
|
11
|
-
userTimeZone: string;
|
|
12
|
-
currentPage?: CurrentPageContext;
|
|
13
|
-
chatSurface?: string;
|
|
14
|
-
adminPublicOrigin?: string;
|
|
15
|
-
abortSignal?: AbortSignal;
|
|
16
|
-
adminUser: AdminUser;
|
|
17
|
-
emit?: AgentEventEmitter;
|
|
18
|
-
failureLogMessage: string;
|
|
19
|
-
abortLogMessage: string;
|
|
20
|
-
};
|
|
21
|
-
export type RunAndPersistAgentResponseResult = {
|
|
22
|
-
text: string;
|
|
23
|
-
turnId: string;
|
|
24
|
-
aborted: boolean;
|
|
25
|
-
failed: boolean;
|
|
26
|
-
};
|
|
27
|
-
export type HandleTurnInput = Omit<RunAndPersistAgentResponseInput, "failureLogMessage" | "abortLogMessage"> & {
|
|
28
|
-
emit: AgentEventEmitter;
|
|
29
|
-
failureLogMessage?: string;
|
|
30
|
-
abortLogMessage?: string;
|
|
31
|
-
};
|
|
32
|
-
export type HandleSpeechTurnInput = Omit<HandleTurnInput, "prompt"> & {
|
|
33
|
-
audioAdapter: AudioAdapter;
|
|
34
|
-
audio: {
|
|
35
|
-
buffer: Buffer;
|
|
36
|
-
filename: string;
|
|
37
|
-
mimeType: string;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
type AgentTurnServiceOptions = {
|
|
41
|
-
getAdminforth: () => IAdminForth;
|
|
42
|
-
getPluginInstanceId: () => string;
|
|
43
|
-
options: PluginOptions;
|
|
44
|
-
sessionStore: AgentSessionStore;
|
|
45
|
-
getCheckpointer: () => BaseCheckpointSaver;
|
|
46
|
-
getInternalAgentResourceIds: () => string[];
|
|
47
|
-
getAgentSystemPrompt: () => Promise<string>;
|
|
48
|
-
};
|
|
1
|
+
import { AgentModelFactory } from "./agent/models/AgentModelFactory.js";
|
|
2
|
+
import { AgentModeResolver } from "./agent/models/AgentModeResolver.js";
|
|
3
|
+
import { AgentRuntime } from "./agent/runtime/AgentRuntime.js";
|
|
4
|
+
import { TurnContextBuilder } from "./agent/turn/TurnContextBuilder.js";
|
|
5
|
+
import { TurnLifecycleService } from "./agent/turn/TurnLifecycleService.js";
|
|
6
|
+
import { TurnPromptBuilder } from "./agent/turn/TurnPromptBuilder.js";
|
|
7
|
+
import { TurnStreamConsumer } from "./agent/turn/TurnStreamConsumer.js";
|
|
8
|
+
import type { HandleTurnInput, RunAndPersistAgentResponseInput, RunAndPersistAgentResponseResult } from "./agent/turn/turnTypes.js";
|
|
9
|
+
export type { BaseAgentTurnInput, HandleSpeechTurnInput, HandleTurnInput, RunAndPersistAgentResponseInput, RunAndPersistAgentResponseResult, } from "./agent/turn/turnTypes.js";
|
|
49
10
|
export declare class AgentTurnService {
|
|
50
|
-
private
|
|
51
|
-
|
|
11
|
+
private readonly lifecycle;
|
|
12
|
+
private readonly contextBuilder;
|
|
13
|
+
private readonly modeResolver;
|
|
14
|
+
private readonly modelFactory;
|
|
15
|
+
private readonly promptBuilder;
|
|
16
|
+
private readonly runtime;
|
|
17
|
+
private readonly streamConsumer;
|
|
18
|
+
constructor(lifecycle: TurnLifecycleService, contextBuilder: TurnContextBuilder, modeResolver: AgentModeResolver, modelFactory: AgentModelFactory, promptBuilder: TurnPromptBuilder, runtime: AgentRuntime, streamConsumer: TurnStreamConsumer);
|
|
19
|
+
private prepareTurn;
|
|
52
20
|
private runAgentTurn;
|
|
53
|
-
runAndPersistAgentResponse(input: RunAndPersistAgentResponseInput): Promise<
|
|
54
|
-
|
|
55
|
-
turnId: any;
|
|
56
|
-
aborted: boolean;
|
|
57
|
-
failed: boolean;
|
|
58
|
-
}>;
|
|
59
|
-
handleTurn(input: HandleTurnInput): Promise<{
|
|
60
|
-
text: string;
|
|
61
|
-
turnId: any;
|
|
62
|
-
aborted: boolean;
|
|
63
|
-
failed: boolean;
|
|
64
|
-
}>;
|
|
65
|
-
handleSpeechTurn(input: HandleSpeechTurnInput): Promise<{
|
|
66
|
-
text: string;
|
|
67
|
-
turnId: any;
|
|
68
|
-
aborted: boolean;
|
|
69
|
-
failed: boolean;
|
|
70
|
-
} | null>;
|
|
21
|
+
runAndPersistAgentResponse(input: RunAndPersistAgentResponseInput): Promise<RunAndPersistAgentResponseResult>;
|
|
22
|
+
handleTurn(input: HandleTurnInput): Promise<RunAndPersistAgentResponseResult>;
|
|
71
23
|
}
|
|
72
|
-
export {};
|