@adminforth/agent 2.0.10 → 2.1.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.
Files changed (187) hide show
  1. package/README.md +333 -10
  2. package/dist/application/ports.d.ts +66 -0
  3. package/dist/application/runTurnUseCase.d.ts +68 -0
  4. package/dist/application/runTurnUseCase.js +358 -0
  5. package/dist/{agentEvents.d.ts → domain/agentEvents.d.ts} +1 -1
  6. package/dist/{agent → domain}/systemPrompt.js +1 -1
  7. package/dist/{agent/turn → domain}/turnTypes.d.ts +41 -37
  8. package/dist/{agent/turn/VegaLiteStreamBuffer.d.ts → domain/vegaLiteStreamBuffer.d.ts} +1 -1
  9. package/dist/index.d.ts +3 -2
  10. package/dist/index.js +40 -35
  11. package/dist/{agent/runtime/AgentContext.d.ts → llm/agentContext.d.ts} +3 -3
  12. package/dist/{agent/simpleAgent.d.ts → llm/agentModels.d.ts} +18 -16
  13. package/dist/llm/agentModels.js +65 -0
  14. package/dist/{agent/runtime/AgentRuntime.d.ts → llm/agentRuntime.d.ts} +11 -2
  15. package/dist/{agent/runtime/AgentRuntime.js → llm/agentRuntime.js} +38 -6
  16. package/dist/llm/langGraphLlm.d.ts +25 -0
  17. package/dist/llm/langGraphLlm.js +54 -0
  18. package/dist/{agent/middleware/apiBasedTools.d.ts → llm/middleware/apiToolsMiddleware.d.ts} +1 -1
  19. package/dist/{agent/middleware/apiBasedTools.js → llm/middleware/apiToolsMiddleware.js} +8 -14
  20. package/dist/{agent → llm}/middleware/sequenceDebug.d.ts +1 -1
  21. package/dist/{agent/models/AgentModelFactory.d.ts → llm/modelFactory.d.ts} +1 -1
  22. package/dist/{agent/models/AgentModelFactory.js → llm/modelFactory.js} +1 -1
  23. package/dist/llm/streamAdapter.d.ts +18 -0
  24. package/dist/llm/streamAdapter.js +117 -0
  25. package/dist/{sessionStore.d.ts → persistence/sessionStore.d.ts} +12 -2
  26. package/dist/{sessionStore.js → persistence/sessionStore.js} +33 -0
  27. package/dist/{agent/tools/AgentToolProvider.d.ts → tools/agentToolProvider.d.ts} +1 -1
  28. package/dist/{agent/tools/AgentToolProvider.js → tools/agentToolProvider.js} +1 -1
  29. package/dist/{apiBasedTools.js → tools/apiBasedTools.js} +0 -3
  30. package/dist/{agent/tools → tools}/apiTool.d.ts +1 -1
  31. package/dist/{agent/tools → tools}/fetchSkill.js +1 -1
  32. package/dist/{agent/tools → tools}/fetchToolSchema.d.ts +1 -1
  33. package/dist/{agent/tools → tools}/index.d.ts +1 -1
  34. package/dist/{agent/tools → tools}/navigateUser.d.ts +3 -3
  35. package/dist/{endpoints → transport/http}/context.d.ts +2 -2
  36. package/dist/transport/http/context.js +1 -0
  37. package/dist/{endpoints/core.js → transport/http/coreEndpoints.js} +3 -3
  38. package/dist/{endpoints/sessions.js → transport/http/sessionEndpoints.js} +7 -1
  39. package/dist/transport/sse/sseWriter.d.ts +29 -0
  40. package/dist/{surfaces/web-sse/createSseEventEmitter.js → transport/sse/sseWriter.js} +15 -0
  41. package/dist/{chatSurfaceService.d.ts → transport/surfaces/chatSurfaceService.d.ts} +3 -3
  42. package/dist/{chatSurfaceService.js → transport/surfaces/chatSurfaceService.js} +7 -5
  43. package/dist/{agent/speech/SpeechTurnService.d.ts → transport/surfaces/speechTurnService.d.ts} +1 -1
  44. package/dist/{agent/speech/SpeechTurnService.js → transport/surfaces/speechTurnService.js} +2 -2
  45. package/dist/types.d.ts +10 -4
  46. package/package.json +11 -2
  47. package/.woodpecker/buildRelease.sh +0 -13
  48. package/.woodpecker/buildSlackNotify.sh +0 -46
  49. package/.woodpecker/release.yml +0 -57
  50. package/agent/checkpointer.ts +0 -329
  51. package/agent/languageDetect.ts +0 -92
  52. package/agent/middleware/apiBasedTools.ts +0 -174
  53. package/agent/middleware/openAiResponsesContinuation.ts +0 -92
  54. package/agent/middleware/sequenceDebug.ts +0 -429
  55. package/agent/models/AgentModeResolver.ts +0 -9
  56. package/agent/models/AgentModelFactory.ts +0 -28
  57. package/agent/runtime/AgentContext.ts +0 -30
  58. package/agent/runtime/AgentRuntime.ts +0 -89
  59. package/agent/simpleAgent.ts +0 -199
  60. package/agent/skills/registry.ts +0 -162
  61. package/agent/speech/SpeechTurnService.ts +0 -179
  62. package/agent/systemPrompt.ts +0 -133
  63. package/agent/toolCallEvents.ts +0 -135
  64. package/agent/tools/AgentToolProvider.ts +0 -28
  65. package/agent/tools/apiTool.ts +0 -66
  66. package/agent/tools/fetchSkill.ts +0 -68
  67. package/agent/tools/fetchToolSchema.ts +0 -47
  68. package/agent/tools/getUserLocation.ts +0 -45
  69. package/agent/tools/index.ts +0 -31
  70. package/agent/tools/navigateUser.ts +0 -210
  71. package/agent/turn/TurnContextBuilder.ts +0 -36
  72. package/agent/turn/TurnLifecycleService.ts +0 -47
  73. package/agent/turn/TurnPersistenceService.ts +0 -33
  74. package/agent/turn/TurnPromptBuilder.ts +0 -51
  75. package/agent/turn/TurnStreamConsumer.ts +0 -69
  76. package/agent/turn/VegaLiteStreamBuffer.ts +0 -90
  77. package/agent/turn/turnTypes.ts +0 -100
  78. package/agentEvents.ts +0 -75
  79. package/agentTurnService.ts +0 -314
  80. package/apiBasedTools.ts +0 -712
  81. package/build.log +0 -67
  82. package/chatSurfaceService.ts +0 -319
  83. package/custom/ChatFooter.vue +0 -173
  84. package/custom/ChatHeader.vue +0 -78
  85. package/custom/ChatSurface.vue +0 -160
  86. package/custom/CustomAutoScrollContainer.vue +0 -164
  87. package/custom/SessionsHistory.vue +0 -88
  88. package/custom/chat.ts +0 -82
  89. package/custom/composables/agentAudio/utils.ts +0 -220
  90. package/custom/composables/agentStore/constants.ts +0 -19
  91. package/custom/composables/agentStore/pageContext.ts +0 -8
  92. package/custom/composables/agentStore/useAgentChat.ts +0 -241
  93. package/custom/composables/agentStore/useAgentPlaceholder.ts +0 -142
  94. package/custom/composables/agentStore/useAgentSessions.ts +0 -350
  95. package/custom/composables/useAgentAudio.ts +0 -272
  96. package/custom/composables/useAgentStore.ts +0 -510
  97. package/custom/composables/useAgentTransitions.ts +0 -58
  98. package/custom/conversation_area/ConversationArea.vue +0 -301
  99. package/custom/conversation_area/MessageRenderer.vue +0 -49
  100. package/custom/conversation_area/ProcessingTimeline.vue +0 -286
  101. package/custom/conversation_area/ReasoningRenderer.vue +0 -79
  102. package/custom/conversation_area/SystemMessageRenderer.vue +0 -28
  103. package/custom/conversation_area/TextRenderer.vue +0 -182
  104. package/custom/conversation_area/ThreeDotsAnimation.vue +0 -35
  105. package/custom/conversation_area/ToolApprovalRenderer.vue +0 -98
  106. package/custom/conversation_area/ToolRenderer.vue +0 -178
  107. package/custom/conversation_area/ToolsGroup.vue +0 -59
  108. package/custom/env.d.ts +0 -7
  109. package/custom/incremark_code_renderers/IncremarkShikiCodeBlock.vue +0 -393
  110. package/custom/incremark_code_renderers/incremarkCodeHighlight.ts +0 -285
  111. package/custom/incremark_code_renderers/incremarkRenderer.ts +0 -653
  112. package/custom/incremark_code_renderers/renderIncremarkMarkdown.ts +0 -118
  113. package/custom/package.json +0 -30
  114. package/custom/pnpm-lock.yaml +0 -2394
  115. package/custom/public/agentAudio/agent-processing.mp3 +0 -0
  116. package/custom/skills/analyze_data/SKILL.md +0 -25
  117. package/custom/skills/charts/SKILL.md +0 -193
  118. package/custom/skills/fetch_data/SKILL.md +0 -31
  119. package/custom/skills/mutate_data/SKILL.md +0 -121
  120. package/custom/speech_recognition_frontend/AudioLines.vue +0 -43
  121. package/custom/speech_recognition_frontend/MicrophoneButon.vue +0 -185
  122. package/custom/speech_recognition_frontend/types/voice-activity-detection.d.ts +0 -22
  123. package/custom/speech_recognition_frontend/voiceActivityDetection.ts +0 -62
  124. package/custom/tsconfig.json +0 -15
  125. package/custom/types.ts +0 -108
  126. package/custom/utils.ts +0 -38
  127. package/dist/agent/middleware/openAiResponsesContinuation.d.ts +0 -1
  128. package/dist/agent/middleware/openAiResponsesContinuation.js +0 -66
  129. package/dist/agent/models/AgentModeResolver.d.ts +0 -9
  130. package/dist/agent/models/AgentModeResolver.js +0 -9
  131. package/dist/agent/simpleAgent.js +0 -118
  132. package/dist/agent/turn/TurnContextBuilder.d.ts +0 -14
  133. package/dist/agent/turn/TurnContextBuilder.js +0 -31
  134. package/dist/agent/turn/TurnLifecycleService.d.ts +0 -24
  135. package/dist/agent/turn/TurnLifecycleService.js +0 -47
  136. package/dist/agent/turn/TurnPersistenceService.d.ts +0 -13
  137. package/dist/agent/turn/TurnPersistenceService.js +0 -35
  138. package/dist/agent/turn/TurnPromptBuilder.d.ts +0 -19
  139. package/dist/agent/turn/TurnPromptBuilder.js +0 -43
  140. package/dist/agent/turn/TurnStreamConsumer.d.ts +0 -11
  141. package/dist/agent/turn/TurnStreamConsumer.js +0 -84
  142. package/dist/agentTurnService.d.ts +0 -24
  143. package/dist/agentTurnService.js +0 -269
  144. package/dist/surfaces/web-sse/createSseEventEmitter.d.ts +0 -14
  145. package/endpoints/chatSurfaces.ts +0 -66
  146. package/endpoints/context.ts +0 -52
  147. package/endpoints/core.ts +0 -181
  148. package/endpoints/sessions.ts +0 -183
  149. package/errors.ts +0 -10
  150. package/index.ts +0 -192
  151. package/pnpm-workspace.yaml +0 -4
  152. package/sanitizeSpeechText.ts +0 -32
  153. package/sessionStore.ts +0 -105
  154. package/surfaces/web-sse/createSseEventEmitter.ts +0 -311
  155. package/tsconfig.json +0 -14
  156. package/types.ts +0 -127
  157. /package/dist/{agent/turn/turnTypes.js → application/ports.js} +0 -0
  158. /package/dist/{agentEvents.js → domain/agentEvents.js} +0 -0
  159. /package/dist/{agent → domain}/languageDetect.d.ts +0 -0
  160. /package/dist/{agent → domain}/languageDetect.js +0 -0
  161. /package/dist/{agent → domain}/systemPrompt.d.ts +0 -0
  162. /package/dist/{agent → domain}/toolCallEvents.d.ts +0 -0
  163. /package/dist/{agent → domain}/toolCallEvents.js +0 -0
  164. /package/dist/{endpoints/context.js → domain/turnTypes.js} +0 -0
  165. /package/dist/{agent/turn/VegaLiteStreamBuffer.js → domain/vegaLiteStreamBuffer.js} +0 -0
  166. /package/dist/{agent/runtime/AgentContext.js → llm/agentContext.js} +0 -0
  167. /package/dist/{agent → llm}/middleware/sequenceDebug.js +0 -0
  168. /package/dist/{agent/checkpointer.d.ts → persistence/checkpointStore.d.ts} +0 -0
  169. /package/dist/{agent/checkpointer.js → persistence/checkpointStore.js} +0 -0
  170. /package/dist/{errors.d.ts → shared/errors.d.ts} +0 -0
  171. /package/dist/{errors.js → shared/errors.js} +0 -0
  172. /package/dist/{sanitizeSpeechText.d.ts → shared/sanitizeSpeechText.d.ts} +0 -0
  173. /package/dist/{sanitizeSpeechText.js → shared/sanitizeSpeechText.js} +0 -0
  174. /package/dist/{apiBasedTools.d.ts → tools/apiBasedTools.d.ts} +0 -0
  175. /package/dist/{agent/tools → tools}/apiTool.js +0 -0
  176. /package/dist/{agent/tools → tools}/fetchSkill.d.ts +0 -0
  177. /package/dist/{agent/tools → tools}/fetchToolSchema.js +0 -0
  178. /package/dist/{agent/tools → tools}/getUserLocation.d.ts +0 -0
  179. /package/dist/{agent/tools → tools}/getUserLocation.js +0 -0
  180. /package/dist/{agent/tools → tools}/index.js +0 -0
  181. /package/dist/{agent/tools → tools}/navigateUser.js +0 -0
  182. /package/dist/{agent → tools}/skills/registry.d.ts +0 -0
  183. /package/dist/{agent → tools}/skills/registry.js +0 -0
  184. /package/dist/{endpoints/chatSurfaces.d.ts → transport/http/chatSurfaceEndpoints.d.ts} +0 -0
  185. /package/dist/{endpoints/chatSurfaces.js → transport/http/chatSurfaceEndpoints.js} +0 -0
  186. /package/dist/{endpoints/core.d.ts → transport/http/coreEndpoints.d.ts} +0 -0
  187. /package/dist/{endpoints/sessions.d.ts → transport/http/sessionEndpoints.d.ts} +0 -0
package/sessionStore.ts DELETED
@@ -1,105 +0,0 @@
1
- import type { AdminUser, IAdminForth } from "adminforth";
2
- import { Filters, Sorts } from "adminforth";
3
- import { randomUUID } from "crypto";
4
- import type { ChatSurfaceIncomingMessage } from "adminforth";
5
- import type { PreviousUserMessage } from "./agent/languageDetect.js";
6
- import type { PluginOptions } from "./types.js";
7
-
8
- export const AGENT_SYSTEM_TURN_PROMPT = "__adminforth_system_message__";
9
-
10
- export class AgentSessionStore {
11
- constructor(
12
- private getAdminforth: () => IAdminForth,
13
- private options: PluginOptions,
14
- ) {}
15
-
16
- async createNewTurn(sessionId: string, prompt: string, response?: string) {
17
- const turnId = randomUUID();
18
- const turnRecord = {
19
- [this.options.turnResource.idField]: turnId,
20
- [this.options.turnResource.sessionIdField]: sessionId,
21
- [this.options.turnResource.promptField]: prompt,
22
- [this.options.turnResource.responseField]: response ?? "not_finished",
23
- };
24
- const newTurn = await this.getAdminforth().resource(this.options.turnResource.resourceId).create(turnRecord);
25
- return newTurn.createdRecord[this.options.turnResource.idField];
26
- }
27
-
28
- async createSystemTurn(sessionId: string, systemMessage: string) {
29
- const turnId = randomUUID();
30
- const turnRecord = {
31
- [this.options.turnResource.idField]: turnId,
32
- [this.options.turnResource.sessionIdField]: sessionId,
33
- [this.options.turnResource.promptField]: AGENT_SYSTEM_TURN_PROMPT,
34
- [this.options.turnResource.responseField]: systemMessage,
35
- };
36
- const newTurn = await this.getAdminforth().resource(this.options.turnResource.resourceId).create(turnRecord);
37
- return newTurn.createdRecord[this.options.turnResource.idField];
38
- }
39
-
40
- async getSessionTurns(sessionId: string) {
41
- const turns = await this.getAdminforth().resource(this.options.turnResource.resourceId).list(
42
- [Filters.EQ(this.options.turnResource.sessionIdField, sessionId)],
43
- undefined,
44
- undefined,
45
- [Sorts.ASC(this.options.turnResource.createdAtField)]
46
- );
47
- return turns.map(turn => ({
48
- prompt: turn[this.options.turnResource.promptField],
49
- response: turn[this.options.turnResource.responseField],
50
- }));
51
- }
52
-
53
- async getPreviousUserMessages(sessionId: string) {
54
- const turns = await this.getAdminforth().resource(this.options.turnResource.resourceId).list(
55
- [Filters.EQ(this.options.turnResource.sessionIdField, sessionId)],
56
- 2,
57
- undefined,
58
- [Sorts.DESC(this.options.turnResource.createdAtField)]
59
- );
60
- return turns
61
- .reverse()
62
- .filter((turn) => turn[this.options.turnResource.promptField] !== AGENT_SYSTEM_TURN_PROMPT)
63
- .map((turn): PreviousUserMessage => ({
64
- text: turn[this.options.turnResource.promptField],
65
- }));
66
- }
67
-
68
- async getLatestTurn(sessionId: string) {
69
- const turns = await this.getAdminforth().resource(this.options.turnResource.resourceId).list(
70
- [Filters.EQ(this.options.turnResource.sessionIdField, sessionId)],
71
- 1,
72
- undefined,
73
- [Sorts.DESC(this.options.turnResource.createdAtField)]
74
- );
75
-
76
- return turns[0];
77
- }
78
-
79
- getChatSurfaceSessionId(incoming: ChatSurfaceIncomingMessage) {
80
- return `${incoming.surface}:${incoming.externalConversationId}`;
81
- }
82
-
83
- async getOrCreateChatSurfaceSession(
84
- incoming: ChatSurfaceIncomingMessage,
85
- adminUser: AdminUser,
86
- ) {
87
- const sessionId = this.getChatSurfaceSessionId(incoming);
88
- const sessionResource = this.getAdminforth().resource(this.options.sessionResource.resourceId);
89
- const session = await sessionResource.get(
90
- [Filters.EQ(this.options.sessionResource.idField, sessionId)]
91
- );
92
-
93
- if (session) {
94
- return sessionId;
95
- }
96
-
97
- await sessionResource.create({
98
- [this.options.sessionResource.idField]: sessionId,
99
- [this.options.sessionResource.titleField]: incoming.prompt.slice(0, 40) || "New Session",
100
- [this.options.sessionResource.askerIdField]: adminUser.pk,
101
- });
102
-
103
- return sessionId;
104
- }
105
- }
@@ -1,311 +0,0 @@
1
- import { randomUUID } from "crypto";
2
-
3
- import type { AgentEvent, AgentEventEmitter } from "../../agentEvents.js";
4
- import type { ToolCallEvent } from "../../agent/toolCallEvents.js";
5
-
6
- type AgentEventStreamResponse = {
7
- writeHead: (statusCode: number, headers: Record<string, string>) => void;
8
- write: (chunk: string) => unknown;
9
- end: () => unknown;
10
- writableEnded: boolean;
11
- destroyed: boolean;
12
- };
13
-
14
- type AgentEventStreamOptions = {
15
- vercelAiUiMessageStream?: boolean;
16
- closeActiveBlockOnToolStart?: boolean;
17
- };
18
-
19
- function createAgentEventStream(
20
- res: AgentEventStreamResponse,
21
- options: AgentEventStreamOptions = {},
22
- ) {
23
- let isStreamClosed = false;
24
- let activeBlock: { type: "text" | "reasoning"; id: string } | null = null;
25
- const isAiUiMessageStream = options.vercelAiUiMessageStream === true;
26
-
27
- res.writeHead(200, {
28
- "Content-Type": "text/event-stream",
29
- "Cache-Control": "no-cache",
30
- "Connection": "keep-alive",
31
- ...(options.vercelAiUiMessageStream
32
- ? { "x-vercel-ai-ui-message-stream": "v1" }
33
- : {}),
34
- });
35
-
36
- const stream = {
37
- send(obj: unknown) {
38
- if (isStreamClosed || res.writableEnded || res.destroyed) {
39
- return;
40
- }
41
-
42
- res.write(`data: ${JSON.stringify(obj)}\n\n`);
43
- },
44
-
45
- endActiveBlock() {
46
- if (!activeBlock) {
47
- return;
48
- }
49
-
50
- stream.send({
51
- type: `${activeBlock.type}-end`,
52
- id: activeBlock.id,
53
- });
54
-
55
- activeBlock = null;
56
- },
57
-
58
- startBlock(type: "text" | "reasoning") {
59
- if (activeBlock?.type === type) {
60
- return activeBlock.id;
61
- }
62
-
63
- stream.endActiveBlock();
64
-
65
- const id = randomUUID();
66
- activeBlock = { type, id };
67
-
68
- stream.send({
69
- type: `${type}-start`,
70
- id,
71
- });
72
-
73
- return id;
74
- },
75
-
76
- start(messageId: string) {
77
- stream.send({
78
- type: "start",
79
- messageId,
80
- });
81
- },
82
-
83
- textDelta(delta: string) {
84
- const textId = stream.startBlock("text");
85
- stream.send({
86
- type: "text-delta",
87
- id: textId,
88
- delta,
89
- });
90
- },
91
-
92
- reasoningDelta(delta: string) {
93
- const reasoningId = stream.startBlock("reasoning");
94
- stream.send({
95
- type: "reasoning-delta",
96
- id: reasoningId,
97
- delta,
98
- });
99
- },
100
-
101
- toolCall(event: ToolCallEvent) {
102
- if (options.closeActiveBlockOnToolStart && event.phase === "start") {
103
- stream.endActiveBlock();
104
- }
105
-
106
- stream.send({
107
- type: "data-tool-call",
108
- data: event,
109
- });
110
- },
111
-
112
- rendering(phase: "start" | "end", label: string) {
113
- if (phase === "start") {
114
- stream.endActiveBlock();
115
- }
116
-
117
- stream.send({
118
- type: "data-rendering",
119
- data: {
120
- phase,
121
- label,
122
- },
123
- });
124
- },
125
-
126
- interrupt(sessionId: string, interrupt: unknown) {
127
- stream.endActiveBlock();
128
- stream.send({
129
- type: isAiUiMessageStream ? "data-interrupt" : "interrupt",
130
- data: {
131
- sessionId,
132
- interrupt,
133
- },
134
- });
135
- },
136
-
137
- openPage(targetPath: string) {
138
- stream.send({
139
- type: isAiUiMessageStream ? "data-open-page" : "open-page",
140
- data: {
141
- targetPath,
142
- },
143
- });
144
- },
145
-
146
- transcript(text: string, language?: string) {
147
- stream.send({
148
- type: isAiUiMessageStream ? "data-transcript" : "transcript",
149
- data: {
150
- text,
151
- language,
152
- },
153
- });
154
- },
155
-
156
- response(text: string, sessionId: string, turnId: string) {
157
- stream.send({
158
- type: isAiUiMessageStream ? "data-response" : "response",
159
- data: {
160
- text,
161
- sessionId,
162
- turnId,
163
- },
164
- });
165
- },
166
-
167
- speechResponse(
168
- transcript: { text: string; language?: string },
169
- response: { text: string },
170
- sessionId: string,
171
- turnId: string,
172
- ) {
173
- stream.send({
174
- type: isAiUiMessageStream ? "data-speech-response" : "speech-response",
175
- data: {
176
- transcript,
177
- response,
178
- sessionId,
179
- turnId,
180
- },
181
- });
182
- },
183
-
184
- audioStart(
185
- mimeType: string,
186
- format: string,
187
- sampleRate: number,
188
- channelCount: number,
189
- bitsPerSample: number,
190
- ) {
191
- stream.send({
192
- type: isAiUiMessageStream ? "data-audio-start" : "audio-start",
193
- data: {
194
- mimeType,
195
- format,
196
- sampleRate,
197
- channelCount,
198
- bitsPerSample,
199
- },
200
- });
201
- },
202
-
203
- audioDelta(value: Uint8Array) {
204
- stream.send({
205
- type: isAiUiMessageStream ? "data-audio-delta" : "audio-delta",
206
- data: {
207
- base64: Buffer.from(value).toString("base64"),
208
- },
209
- });
210
- },
211
-
212
- audioDone() {
213
- stream.send({
214
- type: isAiUiMessageStream ? "data-audio-done" : "audio-done",
215
- ...(isAiUiMessageStream ? { data: {} } : {}),
216
- });
217
- },
218
-
219
- error(error: string) {
220
- stream.send(isAiUiMessageStream
221
- ? {
222
- type: "error",
223
- errorText: error,
224
- }
225
- : {
226
- type: "error",
227
- error,
228
- });
229
- },
230
-
231
- end() {
232
- if (isStreamClosed || res.writableEnded || res.destroyed) {
233
- return;
234
- }
235
-
236
- stream.endActiveBlock();
237
- stream.send({
238
- type: "finish",
239
- });
240
-
241
- res.write("data: [DONE]\n\n");
242
- isStreamClosed = true;
243
- res.end();
244
- },
245
- };
246
-
247
- return stream;
248
- }
249
-
250
- export function createSseEventEmitter(
251
- res: AgentEventStreamResponse,
252
- options: AgentEventStreamOptions = {},
253
- ): AgentEventEmitter {
254
- const stream = createAgentEventStream(res, options);
255
-
256
- return async (event: AgentEvent) => {
257
- switch (event.type) {
258
- case "turn-started":
259
- stream.start(event.messageId);
260
- break;
261
- case "text-delta":
262
- stream.textDelta(event.delta);
263
- break;
264
- case "reasoning-delta":
265
- stream.reasoningDelta(event.delta);
266
- break;
267
- case "tool-call":
268
- stream.toolCall(event.data);
269
- break;
270
- case "rendering":
271
- stream.rendering(event.phase, event.label);
272
- break;
273
- case "interrupt":
274
- stream.interrupt(event.sessionId, event.interrupt);
275
- break;
276
- case "open-page":
277
- stream.openPage(event.targetPath);
278
- break;
279
- case "transcript":
280
- stream.transcript(event.text, event.language);
281
- break;
282
- case "response":
283
- stream.response(event.text, event.sessionId, event.turnId);
284
- break;
285
- case "speech-response":
286
- stream.speechResponse(event.transcript, event.response, event.sessionId, event.turnId);
287
- break;
288
- case "audio-start":
289
- stream.audioStart(
290
- event.mimeType,
291
- event.format,
292
- event.sampleRate,
293
- event.channelCount,
294
- event.bitsPerSample,
295
- );
296
- break;
297
- case "audio-delta":
298
- stream.audioDelta(event.value);
299
- break;
300
- case "audio-done":
301
- stream.audioDone();
302
- break;
303
- case "error":
304
- stream.error(event.error);
305
- break;
306
- case "finish":
307
- stream.end();
308
- break;
309
- }
310
- };
311
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include*/
4
- "module": "node16", /* Specify what module code is generated. */
5
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
6
- "declaration": true,
7
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. */
8
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
9
- "strict": true, /* Enable all strict type-checking options. */
10
- "skipLibCheck": true, /* Skip type checking all .d.ts files. */
11
- },
12
- "exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
13
- }
14
-
package/types.ts DELETED
@@ -1,127 +0,0 @@
1
- import {
2
- type PluginsCommonOptions,
3
- type AdminUser,
4
- type HttpExtra,
5
- type AudioAdapter,
6
- type ChatSurfaceAdapter,
7
- } from "adminforth";
8
- import type { AgentModeCompletionAdapter } from "./agent/simpleAgent.js";
9
-
10
- interface ISessionResource {
11
- resourceId: string;
12
- idField: string;
13
- titleField: string;
14
- turnsField: string;
15
- askerIdField: string;
16
- createdAtField: string;
17
- }
18
-
19
- interface ITurnResource {
20
- resourceId: string;
21
- idField: string;
22
- sessionIdField: string;
23
- createdAtField: string;
24
- promptField: string;
25
- responseField: string;
26
- debugField?: string;
27
- }
28
-
29
- interface ICheckpointResource {
30
- resourceId: string;
31
- idField: string;
32
- threadIdField: string;
33
- checkpointNamespaceField: string;
34
- checkpointIdField: string;
35
- parentCheckpointIdField: string;
36
- rowKindField: string;
37
- taskIdField: string;
38
- sequenceField: string;
39
- createdAtField: string;
40
- checkpointPayloadField: string;
41
- metadataPayloadField: string;
42
- writesPayloadField: string;
43
- schemaVersionField: string;
44
- }
45
-
46
- export interface PluginOptions extends PluginsCommonOptions {
47
- /**
48
- * Optional placeholder examples to preload for the chat textarea.
49
- * They are resolved once when the chat frontend loads.
50
- */
51
- placeholderMessages?: ((input: {
52
- adminUser: AdminUser;
53
- headers: HttpExtra["headers"];
54
- }) => string[] | Promise<string[]>);
55
-
56
- /**
57
- * Modes for the plugin.
58
- * Each mode can have its own configuration.
59
- * Each mode uses its own completion adapter instance.
60
- */
61
- modes: {
62
- name: string;
63
- completionAdapter: AgentModeCompletionAdapter;
64
- }[];
65
-
66
- /**
67
- * Optional audio adapter for speech-to-text and text-to-speech flows.
68
- */
69
- audioAdapter?: AudioAdapter;
70
-
71
- /**
72
- * Optional external chat surfaces, such as Telegram webhooks.
73
- */
74
- chatSurfaceAdapters?: ChatSurfaceAdapter[];
75
-
76
- /**
77
- * Max tokens for the generation.
78
- * Default is 1000
79
- */
80
- maxTokens?: number;
81
-
82
- /**
83
- * Optional custom system prompt appended to the built-in agent system prompt.
84
- */
85
- systemPrompt?: string;
86
-
87
- /**
88
- * Response generation level.
89
- * Default is low
90
- */
91
- reasoning?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
92
-
93
- /**
94
- * Resource configuration for sessions.
95
- */
96
- sessionResource: ISessionResource;
97
-
98
- /**
99
- * Resource configuration for turns.
100
- */
101
- turnResource: ITurnResource;
102
-
103
- /**
104
- * Makes chat sticky by default. By default this prop is false
105
- */
106
- stickByDefault?: boolean;
107
-
108
- /**
109
- * Optional resource configuration for a persistent LangGraph checkpointer.
110
- * Falls back to an in-memory MemorySaver when omitted.
111
- */
112
- checkpointResource?: ICheckpointResource;
113
-
114
- /**
115
- * Optional resource configuration for resolving chat users through OAuth external identities.
116
- */
117
- chatExternalIdentityResource?: {
118
- resourceId: string;
119
- adminUserIdField?: string;
120
- providerField?: string;
121
- subjectField?: string;
122
- externalUserIdField?: string;
123
- surfaces: Record<string, {
124
- provider: string;
125
- }>;
126
- };
127
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes