@adminforth/agent 1.43.29 → 1.44.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.
@@ -0,0 +1,196 @@
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 { randomUUID } from "crypto";
11
+ function createAgentEventStream(res, options = {}) {
12
+ let isStreamClosed = false;
13
+ let activeBlock = null;
14
+ res.writeHead(200, Object.assign({ "Content-Type": "text/event-stream", "Cache-Control": "no-cache", "Connection": "keep-alive" }, (options.vercelAiUiMessageStream
15
+ ? { "x-vercel-ai-ui-message-stream": "v1" }
16
+ : {})));
17
+ const stream = {
18
+ send(obj) {
19
+ if (isStreamClosed || res.writableEnded || res.destroyed) {
20
+ return;
21
+ }
22
+ res.write(`data: ${JSON.stringify(obj)}\n\n`);
23
+ },
24
+ endActiveBlock() {
25
+ if (!activeBlock) {
26
+ return;
27
+ }
28
+ stream.send({
29
+ type: `${activeBlock.type}-end`,
30
+ id: activeBlock.id,
31
+ });
32
+ activeBlock = null;
33
+ },
34
+ startBlock(type) {
35
+ if ((activeBlock === null || activeBlock === void 0 ? void 0 : activeBlock.type) === type) {
36
+ return activeBlock.id;
37
+ }
38
+ stream.endActiveBlock();
39
+ const id = randomUUID();
40
+ activeBlock = { type, id };
41
+ stream.send({
42
+ type: `${type}-start`,
43
+ id,
44
+ });
45
+ return id;
46
+ },
47
+ start(messageId) {
48
+ stream.send({
49
+ type: "start",
50
+ messageId,
51
+ });
52
+ },
53
+ textDelta(delta) {
54
+ const textId = stream.startBlock("text");
55
+ stream.send({
56
+ type: "text-delta",
57
+ id: textId,
58
+ delta,
59
+ });
60
+ },
61
+ reasoningDelta(delta) {
62
+ const reasoningId = stream.startBlock("reasoning");
63
+ stream.send({
64
+ type: "reasoning-delta",
65
+ id: reasoningId,
66
+ delta,
67
+ });
68
+ },
69
+ toolCall(event) {
70
+ if (options.closeActiveBlockOnToolStart && event.phase === "start") {
71
+ stream.endActiveBlock();
72
+ }
73
+ stream.send({
74
+ type: "data-tool-call",
75
+ data: event,
76
+ });
77
+ },
78
+ transcript(text, language) {
79
+ stream.send({
80
+ type: "transcript",
81
+ data: {
82
+ text,
83
+ language,
84
+ },
85
+ });
86
+ },
87
+ response(text, sessionId, turnId) {
88
+ stream.send({
89
+ type: "response",
90
+ data: {
91
+ text,
92
+ sessionId,
93
+ turnId,
94
+ },
95
+ });
96
+ },
97
+ speechResponse(transcript, response, sessionId, turnId) {
98
+ stream.send({
99
+ type: "speech-response",
100
+ data: {
101
+ transcript,
102
+ response,
103
+ sessionId,
104
+ turnId,
105
+ },
106
+ });
107
+ },
108
+ audioStart(mimeType, format, sampleRate, channelCount, bitsPerSample) {
109
+ stream.send({
110
+ type: "audio-start",
111
+ data: {
112
+ mimeType,
113
+ format,
114
+ sampleRate,
115
+ channelCount,
116
+ bitsPerSample,
117
+ },
118
+ });
119
+ },
120
+ audioDelta(value) {
121
+ stream.send({
122
+ type: "audio-delta",
123
+ data: {
124
+ base64: Buffer.from(value).toString("base64"),
125
+ },
126
+ });
127
+ },
128
+ audioDone() {
129
+ stream.send({
130
+ type: "audio-done",
131
+ });
132
+ },
133
+ error(error) {
134
+ stream.send({
135
+ type: "error",
136
+ error,
137
+ });
138
+ },
139
+ end() {
140
+ if (isStreamClosed || res.writableEnded || res.destroyed) {
141
+ return;
142
+ }
143
+ stream.endActiveBlock();
144
+ stream.send({
145
+ type: "finish",
146
+ });
147
+ res.write("data: [DONE]\n\n");
148
+ isStreamClosed = true;
149
+ res.end();
150
+ },
151
+ };
152
+ return stream;
153
+ }
154
+ export function createSseEventEmitter(res, options = {}) {
155
+ const stream = createAgentEventStream(res, options);
156
+ return (event) => __awaiter(this, void 0, void 0, function* () {
157
+ switch (event.type) {
158
+ case "turn-started":
159
+ stream.start(event.messageId);
160
+ break;
161
+ case "text-delta":
162
+ stream.textDelta(event.delta);
163
+ break;
164
+ case "reasoning-delta":
165
+ stream.reasoningDelta(event.delta);
166
+ break;
167
+ case "tool-call":
168
+ stream.toolCall(event.data);
169
+ break;
170
+ case "transcript":
171
+ stream.transcript(event.text, event.language);
172
+ break;
173
+ case "response":
174
+ stream.response(event.text, event.sessionId, event.turnId);
175
+ break;
176
+ case "speech-response":
177
+ stream.speechResponse(event.transcript, event.response, event.sessionId, event.turnId);
178
+ break;
179
+ case "audio-start":
180
+ stream.audioStart(event.mimeType, event.format, event.sampleRate, event.channelCount, event.bitsPerSample);
181
+ break;
182
+ case "audio-delta":
183
+ stream.audioDelta(event.value);
184
+ break;
185
+ case "audio-done":
186
+ stream.audioDone();
187
+ break;
188
+ case "error":
189
+ stream.error(event.error);
190
+ break;
191
+ case "finish":
192
+ stream.end();
193
+ break;
194
+ }
195
+ });
196
+ }
@@ -0,0 +1,94 @@
1
+ import { type PluginsCommonOptions, type AdminUser, type HttpExtra, type AudioAdapter, type ChatSurfaceAdapter } from "adminforth";
2
+ import type { AgentModeCompletionAdapter } from "./agent/simpleAgent.js";
3
+ interface ISessionResource {
4
+ resourceId: string;
5
+ idField: string;
6
+ titleField: string;
7
+ turnsField: string;
8
+ askerIdField: string;
9
+ createdAtField: string;
10
+ }
11
+ interface ITurnResource {
12
+ resourceId: string;
13
+ idField: string;
14
+ sessionIdField: string;
15
+ createdAtField: string;
16
+ promptField: string;
17
+ responseField: string;
18
+ debugField?: string;
19
+ }
20
+ interface ICheckpointResource {
21
+ resourceId: string;
22
+ idField: string;
23
+ threadIdField: string;
24
+ checkpointNamespaceField: string;
25
+ checkpointIdField: string;
26
+ parentCheckpointIdField: string;
27
+ rowKindField: string;
28
+ taskIdField: string;
29
+ sequenceField: string;
30
+ createdAtField: string;
31
+ checkpointPayloadField: string;
32
+ metadataPayloadField: string;
33
+ writesPayloadField: string;
34
+ schemaVersionField: string;
35
+ }
36
+ export interface PluginOptions extends PluginsCommonOptions {
37
+ /**
38
+ * Optional placeholder examples to preload for the chat textarea.
39
+ * They are resolved once when the chat frontend loads.
40
+ */
41
+ placeholderMessages?: ((input: {
42
+ adminUser: AdminUser;
43
+ headers: HttpExtra["headers"];
44
+ }) => string[] | Promise<string[]>);
45
+ /**
46
+ * Modes for the plugin.
47
+ * Each mode can have its own configuration.
48
+ * Each mode uses its own completion adapter instance.
49
+ */
50
+ modes: {
51
+ name: string;
52
+ completionAdapter: AgentModeCompletionAdapter;
53
+ }[];
54
+ /**
55
+ * Optional audio adapter for speech-to-text and text-to-speech flows.
56
+ */
57
+ audioAdapter?: AudioAdapter;
58
+ /**
59
+ * Optional external chat surfaces, such as Telegram webhooks.
60
+ */
61
+ chatSurfaceAdapters?: ChatSurfaceAdapter[];
62
+ /**
63
+ * Max tokens for the generation.
64
+ * Default is 1000
65
+ */
66
+ maxTokens?: number;
67
+ /**
68
+ * Optional custom system prompt appended to the built-in agent system prompt.
69
+ */
70
+ systemPrompt?: string;
71
+ /**
72
+ * Response generation level.
73
+ * Default is low
74
+ */
75
+ reasoning?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
76
+ /**
77
+ * Resource configuration for sessions.
78
+ */
79
+ sessionResource: ISessionResource;
80
+ /**
81
+ * Resource configuration for turns.
82
+ */
83
+ turnResource: ITurnResource;
84
+ /**
85
+ * Makes chat sticky by default. By default this prop is false
86
+ */
87
+ stickByDefault?: boolean;
88
+ /**
89
+ * Optional resource configuration for a persistent LangGraph checkpointer.
90
+ * Falls back to an in-memory MemorySaver when omitted.
91
+ */
92
+ checkpointResource?: ICheckpointResource;
93
+ }
94
+ export {};