@adminforth/agent 1.43.29 → 1.44.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/agentEvents.ts +66 -0
- package/agentResponseEvents.ts +1 -206
- package/build.log +2 -2
- package/custom/conversation_area/ProcessingTimeline.vue +23 -2
- package/custom/incremark_code_renderers/IncremarkShikiCodeBlock.vue +2 -2
- package/custom/types.ts +5 -4
- package/dist/agent/checkpointer.d.ts +29 -0
- package/dist/agent/languageDetect.d.ts +10 -0
- package/dist/agent/middleware/apiBasedTools.d.ts +3 -0
- package/dist/agent/middleware/openAiResponsesContinuation.d.ts +1 -0
- package/dist/agent/middleware/sequenceDebug.d.ts +46 -0
- package/dist/agent/simpleAgent.d.ts +61 -0
- package/dist/agent/skills/registry.d.ts +13 -0
- package/dist/agent/systemPrompt.d.ts +11 -0
- package/dist/agent/toolCallEvents.d.ts +27 -0
- package/dist/agent/tools/apiTool.d.ts +6 -0
- package/dist/agent/tools/fetchSkill.d.ts +8 -0
- package/dist/agent/tools/fetchToolSchema.d.ts +9 -0
- package/dist/agent/tools/getUserLocation.d.ts +8 -0
- package/dist/agent/tools/index.d.ts +4 -0
- package/dist/agentEvents.d.ts +56 -0
- package/dist/agentEvents.js +1 -0
- package/dist/agentResponseEvents.d.ts +1 -0
- package/dist/agentResponseEvents.js +1 -144
- package/dist/apiBasedTools.d.ts +29 -0
- package/dist/custom/conversation_area/ProcessingTimeline.vue +23 -2
- package/dist/custom/incremark_code_renderers/IncremarkShikiCodeBlock.vue +2 -2
- package/dist/custom/types.ts +5 -4
- package/dist/index.d.ts +58 -0
- package/dist/index.js +280 -48
- package/dist/sanitizeSpeechText.d.ts +1 -0
- package/dist/surfaces/web-sse/createSseEventEmitter.d.ts +14 -0
- package/dist/surfaces/web-sse/createSseEventEmitter.js +211 -0
- package/dist/types.d.ts +94 -0
- package/index.ts +315 -46
- package/package.json +2 -2
- package/surfaces/web-sse/createSseEventEmitter.ts +278 -0
- package/tsconfig.json +1 -0
- package/types.ts +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createSseEventEmitter } from "./surfaces/web-sse/createSseEventEmitter.js";
|
|
@@ -1,144 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export function createAgentEventStream(res, options = {}) {
|
|
3
|
-
let isStreamClosed = false;
|
|
4
|
-
let activeBlock = null;
|
|
5
|
-
res.writeHead(200, Object.assign({ "Content-Type": "text/event-stream", "Cache-Control": "no-cache", "Connection": "keep-alive" }, (options.vercelAiUiMessageStream
|
|
6
|
-
? { "x-vercel-ai-ui-message-stream": "v1" }
|
|
7
|
-
: {})));
|
|
8
|
-
const stream = {
|
|
9
|
-
send(obj) {
|
|
10
|
-
if (isStreamClosed || res.writableEnded || res.destroyed) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
res.write(`data: ${JSON.stringify(obj)}\n\n`);
|
|
14
|
-
},
|
|
15
|
-
endActiveBlock() {
|
|
16
|
-
if (!activeBlock) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
stream.send({
|
|
20
|
-
type: `${activeBlock.type}-end`,
|
|
21
|
-
id: activeBlock.id,
|
|
22
|
-
});
|
|
23
|
-
activeBlock = null;
|
|
24
|
-
},
|
|
25
|
-
startBlock(type) {
|
|
26
|
-
if ((activeBlock === null || activeBlock === void 0 ? void 0 : activeBlock.type) === type) {
|
|
27
|
-
return activeBlock.id;
|
|
28
|
-
}
|
|
29
|
-
stream.endActiveBlock();
|
|
30
|
-
const id = randomUUID();
|
|
31
|
-
activeBlock = { type, id };
|
|
32
|
-
stream.send({
|
|
33
|
-
type: `${type}-start`,
|
|
34
|
-
id,
|
|
35
|
-
});
|
|
36
|
-
return id;
|
|
37
|
-
},
|
|
38
|
-
start(messageId) {
|
|
39
|
-
stream.send({
|
|
40
|
-
type: "start",
|
|
41
|
-
messageId,
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
textDelta(delta) {
|
|
45
|
-
const textId = stream.startBlock("text");
|
|
46
|
-
stream.send({
|
|
47
|
-
type: "text-delta",
|
|
48
|
-
id: textId,
|
|
49
|
-
delta,
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
reasoningDelta(delta) {
|
|
53
|
-
const reasoningId = stream.startBlock("reasoning");
|
|
54
|
-
stream.send({
|
|
55
|
-
type: "reasoning-delta",
|
|
56
|
-
id: reasoningId,
|
|
57
|
-
delta,
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
toolCall(event) {
|
|
61
|
-
if (options.closeActiveBlockOnToolStart && event.phase === "start") {
|
|
62
|
-
stream.endActiveBlock();
|
|
63
|
-
}
|
|
64
|
-
stream.send({
|
|
65
|
-
type: "data-tool-call",
|
|
66
|
-
data: event,
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
transcript(text, language) {
|
|
70
|
-
stream.send({
|
|
71
|
-
type: "transcript",
|
|
72
|
-
data: {
|
|
73
|
-
text,
|
|
74
|
-
language,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
response(text, sessionId, turnId) {
|
|
79
|
-
stream.send({
|
|
80
|
-
type: "response",
|
|
81
|
-
data: {
|
|
82
|
-
text,
|
|
83
|
-
sessionId,
|
|
84
|
-
turnId,
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
speechResponse(transcript, response, sessionId, turnId) {
|
|
89
|
-
stream.send({
|
|
90
|
-
type: "speech-response",
|
|
91
|
-
data: {
|
|
92
|
-
transcript,
|
|
93
|
-
response,
|
|
94
|
-
sessionId,
|
|
95
|
-
turnId,
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
audioStart(mimeType, format, sampleRate, channelCount, bitsPerSample) {
|
|
100
|
-
stream.send({
|
|
101
|
-
type: "audio-start",
|
|
102
|
-
data: {
|
|
103
|
-
mimeType,
|
|
104
|
-
format,
|
|
105
|
-
sampleRate,
|
|
106
|
-
channelCount,
|
|
107
|
-
bitsPerSample,
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
},
|
|
111
|
-
audioDelta(value) {
|
|
112
|
-
stream.send({
|
|
113
|
-
type: "audio-delta",
|
|
114
|
-
data: {
|
|
115
|
-
base64: Buffer.from(value).toString("base64"),
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
audioDone() {
|
|
120
|
-
stream.send({
|
|
121
|
-
type: "audio-done",
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
error(error) {
|
|
125
|
-
stream.send({
|
|
126
|
-
type: "error",
|
|
127
|
-
error,
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
end() {
|
|
131
|
-
if (isStreamClosed || res.writableEnded || res.destroyed) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
stream.endActiveBlock();
|
|
135
|
-
stream.send({
|
|
136
|
-
type: "finish",
|
|
137
|
-
});
|
|
138
|
-
res.write("data: [DONE]\n\n");
|
|
139
|
-
isStreamClosed = true;
|
|
140
|
-
res.end();
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
return stream;
|
|
144
|
-
}
|
|
1
|
+
export { createSseEventEmitter } from "./surfaces/web-sse/createSseEventEmitter.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type AdminUser, type IAdminForth } from 'adminforth';
|
|
2
|
+
export type ApiBasedToolCallParams = {
|
|
3
|
+
adminUser?: AdminUser;
|
|
4
|
+
adminuser?: AdminUser;
|
|
5
|
+
abortSignal?: AbortSignal;
|
|
6
|
+
inputs?: Record<string, unknown>;
|
|
7
|
+
userTimeZone?: string;
|
|
8
|
+
acceptLanguage?: string;
|
|
9
|
+
};
|
|
10
|
+
export type ApiBasedTool = {
|
|
11
|
+
description?: string;
|
|
12
|
+
input_schema?: unknown;
|
|
13
|
+
output_schema?: unknown;
|
|
14
|
+
call: (params?: ApiBasedToolCallParams) => Promise<string>;
|
|
15
|
+
};
|
|
16
|
+
export declare function formatApiBasedToolCall(params: {
|
|
17
|
+
adminforth: IAdminForth;
|
|
18
|
+
adminUser?: AdminUser;
|
|
19
|
+
inputs?: Record<string, unknown>;
|
|
20
|
+
toolName: string;
|
|
21
|
+
userTimeZone?: string;
|
|
22
|
+
}): Promise<string | undefined>;
|
|
23
|
+
export declare function prepareApiBasedTools(adminforth: IAdminForth, hiddenResourceIds?: Iterable<string>): Record<string, ApiBasedTool>;
|
|
24
|
+
export declare function serializeApiBasedTool(tool: ApiBasedTool | undefined): {
|
|
25
|
+
description: string | undefined;
|
|
26
|
+
input_schema: unknown;
|
|
27
|
+
output_schema: unknown;
|
|
28
|
+
call: string;
|
|
29
|
+
} | null;
|
|
@@ -39,6 +39,15 @@
|
|
|
39
39
|
<template v-for="(part, index) in ToolOrReasoningParts" :key="index">
|
|
40
40
|
<ReasoningRenderer v-if="part.type === 'reasoning'" :state="part.state" :text="part.text" />
|
|
41
41
|
<ToolsGroup v-else-if="part.type==='data-tool-call'" :toolGroup="groupToolCallParts(message, part)" />
|
|
42
|
+
<li v-else-if="part.type === 'data-rendering'" class="mb-6 mx-2 mt-2 px-2 z-50 overflow-hidden">
|
|
43
|
+
<span class="bg-lightNavbar dark:bg-darkNavbar absolute flex items-center text-listTableHeadingText dark:text-darkListTableHeadingText justify-center w-5 h-5 rounded-full -start-[0.68rem] ring-4 ring-lightNavbar dark:ring-darkNavbar">
|
|
44
|
+
<div class="w-2 h-2 rounded-full bg-current animate-pulse"></div>
|
|
45
|
+
</span>
|
|
46
|
+
<h3 class="flex items-center mb-1 text-sm ml-3 gap-1 text-listTableHeadingText dark:text-darkListTableHeadingText">
|
|
47
|
+
<span class="font-semibold">{{ part.data?.label ?? 'Rendering...' }}</span>
|
|
48
|
+
<ThreeDotsAnimation />
|
|
49
|
+
</h3>
|
|
50
|
+
</li>
|
|
42
51
|
</template>
|
|
43
52
|
</ol>
|
|
44
53
|
</CustomAutoScrollContainer>
|
|
@@ -73,7 +82,11 @@
|
|
|
73
82
|
const isExpanded = ref(true);
|
|
74
83
|
let isUserScrolled = false;
|
|
75
84
|
const ToolOrReasoningParts = computed(() => {
|
|
76
|
-
return props.message.parts.filter((part: IPart) =>
|
|
85
|
+
return props.message.parts.filter((part: IPart) => {
|
|
86
|
+
return part.type === 'data-tool-call'
|
|
87
|
+
|| part.type === 'reasoning'
|
|
88
|
+
|| isActiveRenderingPart(part);
|
|
89
|
+
});
|
|
77
90
|
});
|
|
78
91
|
const isResponseInProgress = computed(() =>{
|
|
79
92
|
return props.isLastMessageInChat && agentStore.isResponseInProgress;
|
|
@@ -157,6 +170,14 @@
|
|
|
157
170
|
});
|
|
158
171
|
};
|
|
159
172
|
|
|
173
|
+
function isActiveRenderingPart(part: IPart) {
|
|
174
|
+
return part.type === 'data-rendering'
|
|
175
|
+
&& part.data?.phase === 'start'
|
|
176
|
+
&& !props.message.parts.some((candidate: IPart) => {
|
|
177
|
+
return candidate.type === 'data-rendering' && candidate.data?.phase === 'end';
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
160
181
|
const groupToolCallParts = (message: IMessage, currentPart: IPart): IToolGroup[] => {
|
|
161
182
|
if (currentPart.type !== 'data-tool-call') {
|
|
162
183
|
return [];
|
|
@@ -259,4 +280,4 @@
|
|
|
259
280
|
}
|
|
260
281
|
}
|
|
261
282
|
|
|
262
|
-
</style>
|
|
283
|
+
</style>
|
|
@@ -72,7 +72,7 @@ let highlightModulePromise: Promise<typeof import('./incremarkCodeHighlight')> |
|
|
|
72
72
|
const sourceCode = computed(() => props.node.value ?? '');
|
|
73
73
|
const language = computed(() => props.node.lang?.trim().toLowerCase() || 'text');
|
|
74
74
|
const languageLabel = computed(() => language.value === 'vega-lite' ? '' : props.node.lang?.trim() || 'text');
|
|
75
|
-
const shouldRenderVega = computed(() => language.value === 'vega-lite'
|
|
75
|
+
const shouldRenderVega = computed(() => language.value === 'vega-lite');
|
|
76
76
|
const codeTheme = computed<IncremarkCodeTheme>(() => {
|
|
77
77
|
const requestedTheme = props.theme ?? (prefersDarkMode.value ? props.darkTheme : props.lightTheme);
|
|
78
78
|
|
|
@@ -390,4 +390,4 @@ function clearVega() {
|
|
|
390
390
|
:deep(.incremark-vega){
|
|
391
391
|
padding: 0;
|
|
392
392
|
}
|
|
393
|
-
</style>
|
|
393
|
+
</style>
|
package/dist/custom/types.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export interface IPartData {
|
|
2
|
-
toolCallId
|
|
3
|
-
toolName
|
|
4
|
-
phase
|
|
2
|
+
toolCallId?: string;
|
|
3
|
+
toolName?: string;
|
|
4
|
+
phase?: 'start' | 'end';
|
|
5
|
+
label?: string;
|
|
5
6
|
input?: any;
|
|
6
7
|
output?: any;
|
|
7
8
|
durationMs?: number;
|
|
8
9
|
toolInfo?: string;
|
|
9
10
|
}
|
|
10
11
|
export interface IPart {
|
|
11
|
-
type: 'reasoning' | 'data-tool-call' | 'text';
|
|
12
|
+
type: 'reasoning' | 'data-tool-call' | 'data-rendering' | 'text';
|
|
12
13
|
text?: string;
|
|
13
14
|
state?: 'started' | 'thinking' | 'processing' | 'streaming' | 'done';
|
|
14
15
|
data?: IPartData;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { AdminUser, AdminForthResource, IAdminForth, IHttpServer } from "adminforth";
|
|
2
|
+
import { AdminForthPlugin } from "adminforth";
|
|
3
|
+
import type { PluginOptions } from './types.js';
|
|
4
|
+
import { createSequenceDebugCollector } from "./agent/middleware/sequenceDebug.js";
|
|
5
|
+
import { type PreviousUserMessage } from "./agent/languageDetect.js";
|
|
6
|
+
import type { AgentEventEmitter } from "./agentEvents.js";
|
|
7
|
+
import type { CurrentPageContext } from "./agent/tools/getUserLocation.js";
|
|
8
|
+
export type { AgentEvent, AgentEventEmitter } from "./agentEvents.js";
|
|
9
|
+
type AgentTurnRunInput = {
|
|
10
|
+
prompt: string;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
turnId: string;
|
|
13
|
+
previousUserMessages: PreviousUserMessage[];
|
|
14
|
+
modeName?: string | null;
|
|
15
|
+
userTimeZone: string;
|
|
16
|
+
currentPage?: CurrentPageContext;
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
adminUser: AdminUser;
|
|
19
|
+
sequenceDebugCollector: ReturnType<typeof createSequenceDebugCollector>;
|
|
20
|
+
emit?: AgentEventEmitter;
|
|
21
|
+
};
|
|
22
|
+
type RunAndPersistAgentResponseInput = Omit<AgentTurnRunInput, "turnId" | "sequenceDebugCollector" | "previousUserMessages"> & {
|
|
23
|
+
failureLogMessage: string;
|
|
24
|
+
abortLogMessage: string;
|
|
25
|
+
};
|
|
26
|
+
type HandleTurnInput = Omit<RunAndPersistAgentResponseInput, "failureLogMessage" | "abortLogMessage"> & {
|
|
27
|
+
emit: AgentEventEmitter;
|
|
28
|
+
failureLogMessage?: string;
|
|
29
|
+
abortLogMessage?: string;
|
|
30
|
+
};
|
|
31
|
+
export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
32
|
+
options: PluginOptions;
|
|
33
|
+
agentSystemPromptPromise: Promise<string>;
|
|
34
|
+
private checkpointer;
|
|
35
|
+
private parseBody;
|
|
36
|
+
private createNewTurn;
|
|
37
|
+
private getSessionTurns;
|
|
38
|
+
private getPreviousUserMessages;
|
|
39
|
+
private getChatSurfaceSessionId;
|
|
40
|
+
private getOrCreateChatSurfaceSession;
|
|
41
|
+
private getCheckpointer;
|
|
42
|
+
private getInternalAgentResourceIds;
|
|
43
|
+
constructor(options: PluginOptions);
|
|
44
|
+
modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource): Promise<void>;
|
|
45
|
+
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
|
|
46
|
+
instanceUniqueRepresentation(pluginOptions: any): string;
|
|
47
|
+
private runAgentTurn;
|
|
48
|
+
private runAndPersistAgentResponse;
|
|
49
|
+
handleTurn(input: HandleTurnInput): Promise<{
|
|
50
|
+
text: string;
|
|
51
|
+
turnId: any;
|
|
52
|
+
aborted: boolean;
|
|
53
|
+
failed: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
private createChatSurfaceEventEmitter;
|
|
56
|
+
private handleChatSurfaceMessage;
|
|
57
|
+
setupEndpoints(server: IHttpServer): void;
|
|
58
|
+
}
|