@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.
package/agentEvents.ts ADDED
@@ -0,0 +1,61 @@
1
+ import type { ToolCallEvent } from "./agent/toolCallEvents.js";
2
+
3
+ export type AgentEvent =
4
+ | {
5
+ type: "turn-started";
6
+ messageId: string;
7
+ }
8
+ | {
9
+ type: "text-delta";
10
+ delta: string;
11
+ }
12
+ | {
13
+ type: "reasoning-delta";
14
+ delta: string;
15
+ }
16
+ | {
17
+ type: "tool-call";
18
+ data: ToolCallEvent;
19
+ }
20
+ | {
21
+ type: "transcript";
22
+ text: string;
23
+ language?: string;
24
+ }
25
+ | {
26
+ type: "response";
27
+ text: string;
28
+ sessionId: string;
29
+ turnId: string;
30
+ }
31
+ | {
32
+ type: "speech-response";
33
+ transcript: { text: string; language?: string };
34
+ response: { text: string };
35
+ sessionId: string;
36
+ turnId: string;
37
+ }
38
+ | {
39
+ type: "audio-start";
40
+ mimeType: string;
41
+ format: string;
42
+ sampleRate: number;
43
+ channelCount: number;
44
+ bitsPerSample: number;
45
+ }
46
+ | {
47
+ type: "audio-delta";
48
+ value: Uint8Array;
49
+ }
50
+ | {
51
+ type: "audio-done";
52
+ }
53
+ | {
54
+ type: "error";
55
+ error: string;
56
+ }
57
+ | {
58
+ type: "finish";
59
+ };
60
+
61
+ export type AgentEventEmitter = (event: AgentEvent) => void | Promise<void>;
@@ -1,206 +1 @@
1
- import { randomUUID } from "crypto";
2
-
3
- import type { ToolCallEvent } from "./agent/toolCallEvents.js";
4
-
5
- type AgentEventStreamResponse = {
6
- writeHead: (statusCode: number, headers: Record<string, string>) => void;
7
- write: (chunk: string) => unknown;
8
- end: () => unknown;
9
- writableEnded: boolean;
10
- destroyed: boolean;
11
- };
12
-
13
- type AgentEventStreamOptions = {
14
- vercelAiUiMessageStream?: boolean;
15
- closeActiveBlockOnToolStart?: boolean;
16
- };
17
-
18
- export function createAgentEventStream(
19
- res: AgentEventStreamResponse,
20
- options: AgentEventStreamOptions = {},
21
- ) {
22
- let isStreamClosed = false;
23
- let activeBlock: { type: "text" | "reasoning"; id: string } | null = null;
24
-
25
- res.writeHead(200, {
26
- "Content-Type": "text/event-stream",
27
- "Cache-Control": "no-cache",
28
- "Connection": "keep-alive",
29
- ...(options.vercelAiUiMessageStream
30
- ? { "x-vercel-ai-ui-message-stream": "v1" }
31
- : {}),
32
- });
33
-
34
- const stream = {
35
- send(obj: unknown) {
36
- if (isStreamClosed || res.writableEnded || res.destroyed) {
37
- return;
38
- }
39
-
40
- res.write(`data: ${JSON.stringify(obj)}\n\n`);
41
- },
42
-
43
- endActiveBlock() {
44
- if (!activeBlock) {
45
- return;
46
- }
47
-
48
- stream.send({
49
- type: `${activeBlock.type}-end`,
50
- id: activeBlock.id,
51
- });
52
-
53
- activeBlock = null;
54
- },
55
-
56
- startBlock(type: "text" | "reasoning") {
57
- if (activeBlock?.type === type) {
58
- return activeBlock.id;
59
- }
60
-
61
- stream.endActiveBlock();
62
-
63
- const id = randomUUID();
64
- activeBlock = { type, id };
65
-
66
- stream.send({
67
- type: `${type}-start`,
68
- id,
69
- });
70
-
71
- return id;
72
- },
73
-
74
- start(messageId: string) {
75
- stream.send({
76
- type: "start",
77
- messageId,
78
- });
79
- },
80
-
81
- textDelta(delta: string) {
82
- const textId = stream.startBlock("text");
83
- stream.send({
84
- type: "text-delta",
85
- id: textId,
86
- delta,
87
- });
88
- },
89
-
90
- reasoningDelta(delta: string) {
91
- const reasoningId = stream.startBlock("reasoning");
92
- stream.send({
93
- type: "reasoning-delta",
94
- id: reasoningId,
95
- delta,
96
- });
97
- },
98
-
99
- toolCall(event: ToolCallEvent) {
100
- if (options.closeActiveBlockOnToolStart && event.phase === "start") {
101
- stream.endActiveBlock();
102
- }
103
-
104
- stream.send({
105
- type: "data-tool-call",
106
- data: event,
107
- });
108
- },
109
-
110
- transcript(text: string, language?: string) {
111
- stream.send({
112
- type: "transcript",
113
- data: {
114
- text,
115
- language,
116
- },
117
- });
118
- },
119
-
120
- response(text: string, sessionId: string, turnId: string) {
121
- stream.send({
122
- type: "response",
123
- data: {
124
- text,
125
- sessionId,
126
- turnId,
127
- },
128
- });
129
- },
130
-
131
- speechResponse(
132
- transcript: { text: string; language?: string },
133
- response: { text: string },
134
- sessionId: string,
135
- turnId: string,
136
- ) {
137
- stream.send({
138
- type: "speech-response",
139
- data: {
140
- transcript,
141
- response,
142
- sessionId,
143
- turnId,
144
- },
145
- });
146
- },
147
-
148
- audioStart(
149
- mimeType: string,
150
- format: string,
151
- sampleRate: number,
152
- channelCount: number,
153
- bitsPerSample: number,
154
- ) {
155
- stream.send({
156
- type: "audio-start",
157
- data: {
158
- mimeType,
159
- format,
160
- sampleRate,
161
- channelCount,
162
- bitsPerSample,
163
- },
164
- });
165
- },
166
-
167
- audioDelta(value: Uint8Array) {
168
- stream.send({
169
- type: "audio-delta",
170
- data: {
171
- base64: Buffer.from(value).toString("base64"),
172
- },
173
- });
174
- },
175
-
176
- audioDone() {
177
- stream.send({
178
- type: "audio-done",
179
- });
180
- },
181
-
182
- error(error: string) {
183
- stream.send({
184
- type: "error",
185
- error,
186
- });
187
- },
188
-
189
- end() {
190
- if (isStreamClosed || res.writableEnded || res.destroyed) {
191
- return;
192
- }
193
-
194
- stream.endActiveBlock();
195
- stream.send({
196
- type: "finish",
197
- });
198
-
199
- res.write("data: [DONE]\n\n");
200
- isStreamClosed = true;
201
- res.end();
202
- },
203
- };
204
-
205
- return stream;
206
- }
1
+ export { createSseEventEmitter } from "./surfaces/web-sse/createSseEventEmitter.js";
package/build.log CHANGED
@@ -62,5 +62,5 @@ custom/speech_recognition_frontend/voiceActivityDetection.ts
62
62
  custom/speech_recognition_frontend/types/
63
63
  custom/speech_recognition_frontend/types/voice-activity-detection.d.ts
64
64
 
65
- sent 1,666,103 bytes received 921 bytes 3,334,048.00 bytes/sec
65
+ sent 1,666,161 bytes received 921 bytes 3,334,164.00 bytes/sec
66
66
  total size is 1,662,008 speedup is 1.00
@@ -0,0 +1,29 @@
1
+ import type { RunnableConfig } from "@langchain/core/runnables";
2
+ import { BaseCheckpointSaver, type Checkpoint, type CheckpointMetadata, type CheckpointTuple, type PendingWrite } from "@langchain/langgraph-checkpoint";
3
+ import type { PluginOptions } from "../types.js";
4
+ export declare class AdminForthCheckpointSaver extends BaseCheckpointSaver {
5
+ private readonly adminforth;
6
+ private readonly pluginOptions;
7
+ constructor(adminforth: any, pluginOptions: PluginOptions);
8
+ private get resourceConfig();
9
+ private resource;
10
+ private serialize;
11
+ private deserialize;
12
+ private now;
13
+ private encodeCheckpointNamespace;
14
+ private decodeCheckpointNamespace;
15
+ private getConfigValues;
16
+ private buildConfig;
17
+ private buildCheckpointRowId;
18
+ private buildWritesRowId;
19
+ private getWriteIndex;
20
+ private isDuplicateCheckpointWriteError;
21
+ put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata, _newVersions: Record<string, unknown>): Promise<RunnableConfig>;
22
+ putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
23
+ getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
24
+ list(config: RunnableConfig, options?: {
25
+ before?: RunnableConfig;
26
+ limit?: number;
27
+ }): AsyncGenerator<CheckpointTuple>;
28
+ deleteThread(threadId: string, checkpointNs?: string): Promise<void>;
29
+ }
@@ -0,0 +1,10 @@
1
+ import type { PluginOptions } from "../types.js";
2
+ export type DetectedLanguage = {
3
+ language: string;
4
+ code: string;
5
+ ambiguous: boolean;
6
+ };
7
+ export type PreviousUserMessage = {
8
+ text: string;
9
+ };
10
+ export declare function detectUserLanguage(completionAdapter: PluginOptions["modes"][number]["completionAdapter"], prompt: string, previousUserMessages?: PreviousUserMessage[]): Promise<DetectedLanguage | null>;
@@ -0,0 +1,3 @@
1
+ import { type IAdminForth } from "adminforth";
2
+ import { type ApiBasedTool } from "../../apiBasedTools.js";
3
+ export declare function createApiBasedToolsMiddleware(apiBasedTools: Record<string, ApiBasedTool>, adminforth: IAdminForth): import("langchain").AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ClientTool | import("@langchain/core/tools").ServerTool)[]>;
@@ -0,0 +1 @@
1
+ export declare function createOpenAiResponsesContinuationMiddleware(): import("langchain").AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ClientTool | import("@langchain/core/tools").ServerTool)[]>;
@@ -0,0 +1,46 @@
1
+ import type { ToolCallEvent } from "../toolCallEvents.js";
2
+ export type SequenceDebugResultType = "tool_calls" | "final_text";
3
+ type SequenceDebugToolCall = {
4
+ toolCallId: string;
5
+ toolName: string;
6
+ input: string;
7
+ output: string | null;
8
+ error: string | null;
9
+ };
10
+ export type SequenceDebug = {
11
+ sequenceId: number;
12
+ startedAt: string;
13
+ prompt: string;
14
+ promptTokens: number;
15
+ reasoning: string;
16
+ reasoningTokens: number;
17
+ text: string;
18
+ textTokens: number;
19
+ cachedTokens: number;
20
+ responseId: string | null;
21
+ toolCalls: SequenceDebugToolCall[];
22
+ endedAt: string;
23
+ resultType: SequenceDebugResultType;
24
+ };
25
+ type SequenceDebugModelCall = {
26
+ promptTokens: number;
27
+ reasoning: string;
28
+ reasoningTokens: number;
29
+ text: string;
30
+ textTokens: number;
31
+ cachedTokens: number;
32
+ responseId: string | null;
33
+ resultType: SequenceDebugResultType;
34
+ };
35
+ export type SequenceDebugModelCallSink = {
36
+ handleModelCallStart: (prompt: string) => void;
37
+ handleModelCallComplete: (params: SequenceDebugModelCall) => void;
38
+ };
39
+ export type SequenceDebugCollector = SequenceDebugModelCallSink & {
40
+ handleToolCallEvent: (event: ToolCallEvent) => void;
41
+ flush: () => void;
42
+ getHistory: () => SequenceDebug[];
43
+ };
44
+ export declare function createSequenceDebugCollector(): SequenceDebugCollector;
45
+ export declare function createSequenceDebugMiddleware(sink: SequenceDebugModelCallSink): import("langchain").AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ClientTool | import("@langchain/core/tools").ServerTool)[]>;
46
+ export {};
@@ -0,0 +1,61 @@
1
+ import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
2
+ import { type AdminUser, type CompletionAdapter, type IAdminForth } from "adminforth";
3
+ import { type BaseCheckpointSaver, type Messages } from "@langchain/langgraph";
4
+ import { z } from "zod";
5
+ import { createSequenceDebugMiddleware, type SequenceDebugModelCallSink } from "./middleware/sequenceDebug.js";
6
+ import type { ApiBasedTool } from "../apiBasedTools.js";
7
+ import type { ToolCallEventSink } from "./toolCallEvents.js";
8
+ import type { CurrentPageContext } from "./tools/getUserLocation.js";
9
+ export declare const contextSchema: z.ZodObject<{
10
+ adminUser: z.ZodCustom<AdminUser, AdminUser>;
11
+ userTimeZone: z.ZodString;
12
+ sessionId: z.ZodString;
13
+ turnId: z.ZodString;
14
+ abortSignal: z.ZodOptional<z.ZodCustom<AbortSignal, AbortSignal>>;
15
+ currentPage: z.ZodOptional<z.ZodCustom<CurrentPageContext, CurrentPageContext>>;
16
+ emitToolCallEvent: z.ZodCustom<ToolCallEventSink, ToolCallEventSink>;
17
+ }, z.core.$strip>;
18
+ export type AgentChatModel = BaseChatModel<any, any>;
19
+ export type AgentModelPurpose = "primary" | "summary";
20
+ export type AgentModeCompletionAdapter = CompletionAdapter & {
21
+ getLangChainAgentSpec(params: {
22
+ maxTokens: number;
23
+ purpose: AgentModelPurpose;
24
+ }): Promise<{
25
+ model: unknown;
26
+ middleware?: unknown[];
27
+ }> | {
28
+ model: unknown;
29
+ middleware?: unknown[];
30
+ };
31
+ };
32
+ type AgentMiddleware = ReturnType<typeof createSequenceDebugMiddleware>;
33
+ type AgentChatModelSpec = {
34
+ model: AgentChatModel;
35
+ middleware: AgentMiddleware[];
36
+ };
37
+ export declare function createAgentChatModel(params: {
38
+ adapter: CompletionAdapter;
39
+ maxTokens: number;
40
+ purpose: AgentModelPurpose;
41
+ }): Promise<AgentChatModelSpec>;
42
+ export declare function callAgent(params: {
43
+ name: string;
44
+ model: AgentChatModel;
45
+ summaryModel: AgentChatModel;
46
+ modelMiddleware?: AgentMiddleware[];
47
+ checkpointer?: BaseCheckpointSaver;
48
+ messages: Messages;
49
+ adminUser: AdminUser;
50
+ adminforth: IAdminForth;
51
+ apiBasedTools: Record<string, ApiBasedTool>;
52
+ customComponentsDir: string;
53
+ sessionId: string;
54
+ turnId: string;
55
+ currentPage?: CurrentPageContext;
56
+ userTimeZone: string;
57
+ abortSignal?: AbortSignal;
58
+ emitToolCallEvent: ToolCallEventSink;
59
+ sequenceDebugSink: SequenceDebugModelCallSink;
60
+ }): Promise<import("@langchain/core/utils/stream").IterableReadableStream<[import("langchain").BaseMessage<import("@langchain/core/messages").MessageStructure<import("@langchain/core/messages").MessageToolSet>, import("@langchain/core/messages").MessageType>, Record<string, any>]>>;
61
+ export {};
@@ -0,0 +1,13 @@
1
+ export interface AgentSkillManifest {
2
+ directoryName: string;
3
+ name: string;
4
+ description: string;
5
+ instructions: string;
6
+ }
7
+ export declare function getProjectSkillsDirectoryPath(customComponentsDir: string): string;
8
+ export declare function getProjectPluginSkillsDirectoryPath(customComponentsDir: string): string;
9
+ export declare function listBundledSkillManifests(): Promise<AgentSkillManifest[]>;
10
+ export declare function listProjectSkillManifests(customComponentsDir: string): Promise<AgentSkillManifest[]>;
11
+ export declare function listSkillManifests(customComponentsDir: string): Promise<AgentSkillManifest[]>;
12
+ export declare function loadSkillManifest(skillName: string, customComponentsDir: string): Promise<AgentSkillManifest | null>;
13
+ export declare function loadSkillMarkdown(skillName: string, customComponentsDir: string): Promise<string | null>;
@@ -0,0 +1,11 @@
1
+ import type { AdminUser, IAdminForth } from "adminforth";
2
+ import type { DetectedLanguage } from "./languageDetect.js";
3
+ export declare const DEFAULT_AGENT_SYSTEM_PROMPT: string;
4
+ export declare function appendCustomSystemPrompt(systemPrompt: string, customSystemPrompt?: string): string;
5
+ export declare function buildAgentTurnSystemPrompt(input: {
6
+ agentSystemPrompt: string;
7
+ adminUser: AdminUser;
8
+ usernameField: string;
9
+ userLanguage: DetectedLanguage | null;
10
+ }): string;
11
+ export declare function buildAgentSystemPrompt(adminforth: IAdminForth, hiddenResourceIds?: Iterable<string>): Promise<string>;
@@ -0,0 +1,27 @@
1
+ export type ToolCallEvent = {
2
+ toolCallId: string;
3
+ toolName: string;
4
+ toolInfo?: string;
5
+ phase: "start";
6
+ input: string;
7
+ } | {
8
+ toolCallId: string;
9
+ toolName: string;
10
+ phase: "end";
11
+ durationMs: number;
12
+ output: string | null;
13
+ error: string | null;
14
+ };
15
+ export type ToolCallEventSink = (event: ToolCallEvent) => void;
16
+ export declare function createToolCallTracker(params: {
17
+ emit: ToolCallEventSink;
18
+ toolCallId?: string;
19
+ toolName: string;
20
+ toolInfo?: string;
21
+ input?: Record<string, unknown>;
22
+ startedAt?: number;
23
+ }): {
24
+ start(): void;
25
+ finishSuccess(output: unknown): void;
26
+ finishError(error: unknown): void;
27
+ };
@@ -0,0 +1,6 @@
1
+ import type { ApiBasedTool } from "../../apiBasedTools.js";
2
+ export declare function createApiTool(toolName: string, apiBasedTool: ApiBasedTool): import("langchain").DynamicStructuredTool<Record<string, unknown> | {
3
+ readonly type: "object";
4
+ readonly properties: {};
5
+ readonly additionalProperties: true;
6
+ }, unknown, unknown, string, unknown, string>;
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ export declare function createFetchSkillTool(customComponentsDir: string): Promise<import("langchain").DynamicStructuredTool<z.ZodObject<{
3
+ skillName: z.ZodString;
4
+ }, z.core.$strip>, {
5
+ skillName: string;
6
+ }, {
7
+ skillName: string;
8
+ }, string, unknown, "fetch_skill">>;
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ import { type ApiBasedTool } from "../../apiBasedTools.js";
3
+ export declare function createFetchToolSchemaTool(apiBasedTools: Record<string, ApiBasedTool>): Promise<import("langchain").DynamicStructuredTool<z.ZodObject<{
4
+ toolName: z.ZodString;
5
+ }, z.core.$strip>, {
6
+ toolName: string;
7
+ }, {
8
+ toolName: string;
9
+ }, string, unknown, "fetch_tool_schema">>;
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ export type CurrentPageContext = {
3
+ path: string;
4
+ fullPath: string;
5
+ title: string;
6
+ url: string;
7
+ };
8
+ export declare function createGetUserLocationTool(): import("langchain").DynamicStructuredTool<z.ZodObject<{}, z.core.$strip>, Record<string, never>, Record<string, never>, string, unknown, "get_user_location">;
@@ -0,0 +1,4 @@
1
+ import type { ClientTool } from "@langchain/core/tools";
2
+ import type { ApiBasedTool } from "../../apiBasedTools.js";
3
+ export declare const ALWAYS_AVAILABLE_API_TOOL_NAMES: readonly ["get_resource"];
4
+ export declare function createAgentTools(customComponentsDir: string, apiBasedTools: Record<string, ApiBasedTool>): Promise<ClientTool[]>;
@@ -0,0 +1,52 @@
1
+ import type { ToolCallEvent } from "./agent/toolCallEvents.js";
2
+ export type AgentEvent = {
3
+ type: "turn-started";
4
+ messageId: string;
5
+ } | {
6
+ type: "text-delta";
7
+ delta: string;
8
+ } | {
9
+ type: "reasoning-delta";
10
+ delta: string;
11
+ } | {
12
+ type: "tool-call";
13
+ data: ToolCallEvent;
14
+ } | {
15
+ type: "transcript";
16
+ text: string;
17
+ language?: string;
18
+ } | {
19
+ type: "response";
20
+ text: string;
21
+ sessionId: string;
22
+ turnId: string;
23
+ } | {
24
+ type: "speech-response";
25
+ transcript: {
26
+ text: string;
27
+ language?: string;
28
+ };
29
+ response: {
30
+ text: string;
31
+ };
32
+ sessionId: string;
33
+ turnId: string;
34
+ } | {
35
+ type: "audio-start";
36
+ mimeType: string;
37
+ format: string;
38
+ sampleRate: number;
39
+ channelCount: number;
40
+ bitsPerSample: number;
41
+ } | {
42
+ type: "audio-delta";
43
+ value: Uint8Array;
44
+ } | {
45
+ type: "audio-done";
46
+ } | {
47
+ type: "error";
48
+ error: string;
49
+ } | {
50
+ type: "finish";
51
+ };
52
+ export type AgentEventEmitter = (event: AgentEvent) => void | Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { createSseEventEmitter } from "./surfaces/web-sse/createSseEventEmitter.js";