veryfront 0.1.144 → 0.1.145

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 (71) hide show
  1. package/esm/deno.js +1 -1
  2. package/esm/src/agent/ag-ui-handler.d.ts +77 -0
  3. package/esm/src/agent/ag-ui-handler.d.ts.map +1 -0
  4. package/esm/src/agent/ag-ui-handler.js +331 -0
  5. package/esm/src/agent/index.d.ts +2 -1
  6. package/esm/src/agent/index.d.ts.map +1 -1
  7. package/esm/src/agent/index.js +2 -1
  8. package/esm/src/agent/runtime/index.d.ts +2 -0
  9. package/esm/src/agent/runtime/index.d.ts.map +1 -1
  10. package/esm/src/agent/runtime/index.js +15 -7
  11. package/esm/src/agent/runtime/resume-session.d.ts +61 -0
  12. package/esm/src/agent/runtime/resume-session.d.ts.map +1 -0
  13. package/esm/src/agent/runtime/resume-session.js +232 -0
  14. package/esm/src/agent/runtime/tool-helpers.d.ts +4 -2
  15. package/esm/src/agent/runtime/tool-helpers.d.ts.map +1 -1
  16. package/esm/src/agent/runtime/tool-helpers.js +57 -4
  17. package/esm/src/agent/types.d.ts +2 -1
  18. package/esm/src/agent/types.d.ts.map +1 -1
  19. package/esm/src/internal-agents/session-manager.d.ts +8 -24
  20. package/esm/src/internal-agents/session-manager.d.ts.map +1 -1
  21. package/esm/src/internal-agents/session-manager.js +55 -178
  22. package/esm/src/mcp/index.d.ts +2 -0
  23. package/esm/src/mcp/index.d.ts.map +1 -1
  24. package/esm/src/mcp/index.js +2 -0
  25. package/esm/src/mcp/server.d.ts +1 -0
  26. package/esm/src/mcp/server.d.ts.map +1 -1
  27. package/esm/src/mcp/server.js +47 -8
  28. package/esm/src/mcp/session.d.ts +9 -0
  29. package/esm/src/mcp/session.d.ts.map +1 -0
  30. package/esm/src/mcp/session.js +25 -0
  31. package/esm/src/mcp/sse.d.ts +8 -0
  32. package/esm/src/mcp/sse.d.ts.map +1 -0
  33. package/esm/src/mcp/sse.js +17 -0
  34. package/esm/src/platform/cloud/resolver.d.ts.map +1 -1
  35. package/esm/src/platform/cloud/resolver.js +13 -3
  36. package/esm/src/provider/index.d.ts +2 -0
  37. package/esm/src/provider/index.d.ts.map +1 -1
  38. package/esm/src/provider/index.js +1 -0
  39. package/esm/src/provider/veryfront-cloud/context.d.ts +10 -0
  40. package/esm/src/provider/veryfront-cloud/context.d.ts.map +1 -0
  41. package/esm/src/provider/veryfront-cloud/context.js +11 -0
  42. package/esm/src/tool/index.d.ts +3 -1
  43. package/esm/src/tool/index.d.ts.map +1 -1
  44. package/esm/src/tool/index.js +1 -0
  45. package/esm/src/tool/remote-mcp.d.ts +14 -0
  46. package/esm/src/tool/remote-mcp.d.ts.map +1 -0
  47. package/esm/src/tool/remote-mcp.js +176 -0
  48. package/esm/src/tool/types.d.ts +12 -0
  49. package/esm/src/tool/types.d.ts.map +1 -1
  50. package/esm/src/utils/version-constant.d.ts +1 -1
  51. package/esm/src/utils/version-constant.js +1 -1
  52. package/package.json +1 -1
  53. package/src/deno.js +1 -1
  54. package/src/src/agent/ag-ui-handler.ts +451 -0
  55. package/src/src/agent/index.ts +21 -1
  56. package/src/src/agent/runtime/index.ts +28 -3
  57. package/src/src/agent/runtime/resume-session.ts +319 -0
  58. package/src/src/agent/runtime/tool-helpers.ts +89 -6
  59. package/src/src/agent/types.ts +2 -1
  60. package/src/src/internal-agents/session-manager.ts +69 -243
  61. package/src/src/mcp/index.ts +3 -0
  62. package/src/src/mcp/server.ts +54 -9
  63. package/src/src/mcp/session.ts +31 -0
  64. package/src/src/mcp/sse.ts +19 -0
  65. package/src/src/platform/cloud/resolver.ts +15 -3
  66. package/src/src/provider/index.ts +5 -0
  67. package/src/src/provider/veryfront-cloud/context.ts +28 -0
  68. package/src/src/tool/index.ts +9 -1
  69. package/src/src/tool/remote-mcp.ts +261 -0
  70. package/src/src/tool/types.ts +17 -0
  71. package/src/src/utils/version-constant.ts +1 -1
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.144",
3
+ "version": "0.1.145",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "exclude": [
@@ -0,0 +1,77 @@
1
+ import * as dntShim from "../../_dnt.shims.js";
2
+ import { z } from "zod";
3
+ import type { Agent } from "./types.js";
4
+ declare const AgUiInjectedToolSchema: z.ZodObject<{
5
+ name: z.ZodString;
6
+ description: z.ZodOptional<z.ZodString>;
7
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
8
+ }, z.core.$strip>;
9
+ declare const AgUiContextItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
+ type: z.ZodLiteral<"text">;
11
+ title: z.ZodOptional<z.ZodString>;
12
+ text: z.ZodString;
13
+ }, z.core.$strip>, z.ZodObject<{
14
+ type: z.ZodLiteral<"json">;
15
+ title: z.ZodOptional<z.ZodString>;
16
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
17
+ }, z.core.$strip>, z.ZodObject<{
18
+ type: z.ZodLiteral<"resource">;
19
+ title: z.ZodOptional<z.ZodString>;
20
+ uri: z.ZodString;
21
+ mimeType: z.ZodOptional<z.ZodString>;
22
+ text: z.ZodOptional<z.ZodString>;
23
+ }, z.core.$strip>], "type">;
24
+ export declare const AgUiRequestSchema: z.ZodObject<{
25
+ threadId: z.ZodOptional<z.ZodString>;
26
+ runId: z.ZodOptional<z.ZodString>;
27
+ messages: z.ZodArray<z.ZodObject<{
28
+ id: z.ZodString;
29
+ role: z.ZodEnum<{
30
+ tool: "tool";
31
+ user: "user";
32
+ assistant: "assistant";
33
+ system: "system";
34
+ }>;
35
+ parts: z.ZodDefault<z.ZodArray<z.ZodObject<{
36
+ type: z.ZodString;
37
+ }, z.core.$loose>>>;
38
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
39
+ createdAt: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strip>>;
41
+ tools: z.ZodDefault<z.ZodArray<z.ZodObject<{
42
+ name: z.ZodString;
43
+ description: z.ZodOptional<z.ZodString>;
44
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
45
+ }, z.core.$strip>>>;
46
+ context: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
47
+ type: z.ZodLiteral<"text">;
48
+ title: z.ZodOptional<z.ZodString>;
49
+ text: z.ZodString;
50
+ }, z.core.$strip>, z.ZodObject<{
51
+ type: z.ZodLiteral<"json">;
52
+ title: z.ZodOptional<z.ZodString>;
53
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
54
+ }, z.core.$strip>, z.ZodObject<{
55
+ type: z.ZodLiteral<"resource">;
56
+ title: z.ZodOptional<z.ZodString>;
57
+ uri: z.ZodString;
58
+ mimeType: z.ZodOptional<z.ZodString>;
59
+ text: z.ZodOptional<z.ZodString>;
60
+ }, z.core.$strip>], "type">>>;
61
+ forwardedProps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
62
+ model: z.ZodOptional<z.ZodString>;
63
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
64
+ }, z.core.$strip>;
65
+ export type AgUiInjectedTool = z.infer<typeof AgUiInjectedToolSchema>;
66
+ export type AgUiContextItem = z.infer<typeof AgUiContextItemSchema>;
67
+ export type AgUiRequest = z.infer<typeof AgUiRequestSchema>;
68
+ export interface AgUiHandlerOptions {
69
+ context?: Record<string, unknown> | ((request: dntShim.Request) => Record<string, unknown> | Promise<Record<string, unknown>>);
70
+ }
71
+ export interface AgUiHandlerConfigWithAgent extends AgUiHandlerOptions {
72
+ agent: Agent;
73
+ }
74
+ export declare function createAgUiHandler(agentId: string, options?: AgUiHandlerOptions): (requestOrCtx: unknown) => Promise<dntShim.Response>;
75
+ export declare function createAgUiHandler(config: AgUiHandlerConfigWithAgent, options?: AgUiHandlerOptions): (requestOrCtx: unknown) => Promise<dntShim.Response>;
76
+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D,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,0BAA0B,EAClC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,331 @@
1
+ import * as dntShim from "../../_dnt.shims.js";
2
+ import { z } from "zod";
3
+ import { getAgent } from "./composition/index.js";
4
+ import { INVALID_ARGUMENT } from "../errors/index.js";
5
+ import { createStreamTransformState, finalizeRunEvents, formatAgUiEvent, mapRuntimeEventToAgUi, parseSseJsonEvents, } from "../internal-agents/ag-ui-sse.js";
6
+ const AGENT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
7
+ const MAX_TOOL_PARAMETERS_BYTES = 16_384;
8
+ const MAX_CONTEXT_ITEM_BYTES = 16_384;
9
+ const MAX_CONTEXT_TOTAL_BYTES = 65_536;
10
+ const MAX_FORWARDED_PROPS_BYTES = 65_536;
11
+ const MAX_TEXT_PART_LENGTH = 10_000;
12
+ const MAX_MESSAGES_PER_REQUEST = 100;
13
+ const encoder = new TextEncoder();
14
+ const AG_UI_HEADERS = {
15
+ "Content-Type": "text/event-stream",
16
+ "Cache-Control": "no-cache",
17
+ Connection: "keep-alive",
18
+ };
19
+ function isWithinJsonSizeLimit(value, maxBytes) {
20
+ try {
21
+ return encoder.encode(JSON.stringify(value)).byteLength <= maxBytes;
22
+ }
23
+ catch {
24
+ return false;
25
+ }
26
+ }
27
+ const AgUiRunIdSchema = z.string().min(1).max(128).regex(AGENT_ID_PATTERN);
28
+ const AgUiInjectedToolSchema = z.object({
29
+ name: z.string().min(1).max(128),
30
+ description: z.string().max(1024).optional(),
31
+ parameters: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_TOOL_PARAMETERS_BYTES), { message: "Tool parameters must be less than 16 KB" }),
32
+ });
33
+ const AgUiContextItemSchema = z.discriminatedUnion("type", [
34
+ z.object({
35
+ type: z.literal("text"),
36
+ title: z.string().max(256).optional(),
37
+ text: z.string().max(MAX_CONTEXT_ITEM_BYTES),
38
+ }),
39
+ z.object({
40
+ type: z.literal("json"),
41
+ title: z.string().max(256).optional(),
42
+ data: z.record(z.string(), z.unknown()).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_ITEM_BYTES), { message: "JSON context item must be less than 16 KB" }),
43
+ }),
44
+ z.object({
45
+ type: z.literal("resource"),
46
+ title: z.string().max(256).optional(),
47
+ uri: z.string().max(2048),
48
+ mimeType: z.string().max(256).optional(),
49
+ text: z.string().max(MAX_CONTEXT_ITEM_BYTES).optional(),
50
+ }),
51
+ ]);
52
+ const AgUiMessagePartSchema = z.object({ type: z.string().min(1) }).passthrough();
53
+ const AgUiMessageSchema = z.object({
54
+ id: z.string().min(1),
55
+ role: z.enum(["user", "assistant", "system", "tool"]),
56
+ parts: z.array(AgUiMessagePartSchema).default([]),
57
+ metadata: z.record(z.string(), z.unknown()).optional(),
58
+ createdAt: z.string().optional(),
59
+ });
60
+ export const AgUiRequestSchema = z.object({
61
+ threadId: z.string().uuid().optional(),
62
+ runId: AgUiRunIdSchema.optional(),
63
+ messages: z.array(AgUiMessageSchema).min(1).max(MAX_MESSAGES_PER_REQUEST),
64
+ tools: z.array(AgUiInjectedToolSchema).max(50).default([]),
65
+ context: z.array(AgUiContextItemSchema).max(10).default([]).refine((value) => isWithinJsonSizeLimit(value, MAX_CONTEXT_TOTAL_BYTES), { message: "context must be less than 64 KB total" }),
66
+ forwardedProps: z.record(z.string(), z.unknown()).optional().refine((value) => value === undefined || isWithinJsonSizeLimit(value, MAX_FORWARDED_PROPS_BYTES), { message: "forwardedProps must be less than 64 KB" }),
67
+ model: z.string().optional(),
68
+ maxOutputTokens: z.number().int().positive().optional(),
69
+ });
70
+ function isRecord(value) {
71
+ return typeof value === "object" && value !== null && !Array.isArray(value);
72
+ }
73
+ function normalizeToolArgs(part) {
74
+ if (isRecord(part.args))
75
+ return part.args;
76
+ if (isRecord(part.input))
77
+ return part.input;
78
+ return {};
79
+ }
80
+ function normalizeMessagePart(part) {
81
+ if (part.type === "text" && typeof part.text === "string" &&
82
+ part.text.length <= MAX_TEXT_PART_LENGTH) {
83
+ return { type: "text", text: part.text };
84
+ }
85
+ if (part.type === "tool_call" && typeof part.id === "string" && typeof part.name === "string") {
86
+ return {
87
+ type: "tool-call",
88
+ toolCallId: part.id,
89
+ toolName: part.name,
90
+ args: normalizeToolArgs(part),
91
+ };
92
+ }
93
+ if (part.type === "tool-call" &&
94
+ typeof part.toolCallId === "string" &&
95
+ typeof part.toolName === "string") {
96
+ return {
97
+ type: "tool-call",
98
+ toolCallId: part.toolCallId,
99
+ toolName: part.toolName,
100
+ args: normalizeToolArgs(part),
101
+ };
102
+ }
103
+ if (typeof part.type === "string" &&
104
+ part.type.startsWith("tool-") &&
105
+ part.type !== "tool-result" &&
106
+ typeof part.toolCallId === "string" &&
107
+ typeof part.toolName === "string") {
108
+ return {
109
+ type: part.type,
110
+ toolCallId: part.toolCallId,
111
+ toolName: part.toolName,
112
+ args: normalizeToolArgs(part),
113
+ };
114
+ }
115
+ if (part.type === "tool_result" && typeof part.tool_call_id === "string") {
116
+ return {
117
+ type: "tool-result",
118
+ toolCallId: part.tool_call_id,
119
+ toolName: typeof part.tool_name === "string" ? part.tool_name : "unknown",
120
+ result: "output" in part ? part.output : undefined,
121
+ };
122
+ }
123
+ if (part.type === "tool-result" && typeof part.toolCallId === "string") {
124
+ return {
125
+ type: "tool-result",
126
+ toolCallId: part.toolCallId,
127
+ toolName: typeof part.toolName === "string" ? part.toolName : "unknown",
128
+ result: "result" in part ? part.result : undefined,
129
+ };
130
+ }
131
+ return null;
132
+ }
133
+ function normalizeMessages(messages) {
134
+ return messages.map((message) => ({
135
+ id: message.id,
136
+ role: message.role,
137
+ parts: message.parts
138
+ .map((part) => normalizeMessagePart(part))
139
+ .filter((part) => part !== null),
140
+ ...(message.createdAt ? { timestamp: Date.parse(message.createdAt) || undefined } : {}),
141
+ ...(message.metadata ? { metadata: message.metadata } : {}),
142
+ }));
143
+ }
144
+ function isRequest(obj) {
145
+ return (typeof obj === "object" &&
146
+ obj !== null &&
147
+ "json" in obj &&
148
+ typeof obj.json === "function" &&
149
+ "url" in obj &&
150
+ typeof obj.url === "string" &&
151
+ "method" in obj &&
152
+ typeof obj.method === "string");
153
+ }
154
+ function extractRequest(requestOrCtx) {
155
+ if (isRequest(requestOrCtx))
156
+ return requestOrCtx;
157
+ if (typeof requestOrCtx === "object" && requestOrCtx !== null && "request" in requestOrCtx) {
158
+ const candidate = requestOrCtx.request;
159
+ if (isRequest(candidate))
160
+ return candidate;
161
+ }
162
+ throw INVALID_ARGUMENT.create({
163
+ detail: "Invalid handler argument: expected Request or APIContext",
164
+ });
165
+ }
166
+ function generateRunId() {
167
+ return `run_${dntShim.crypto.randomUUID().replaceAll("-", "")}`;
168
+ }
169
+ function buildStreamContext(request, baseContext, threadId, runId) {
170
+ return {
171
+ ...baseContext,
172
+ threadId,
173
+ runId,
174
+ agUi: {
175
+ context: request.context,
176
+ forwardedProps: request.forwardedProps,
177
+ },
178
+ };
179
+ }
180
+ function closeController(controller) {
181
+ try {
182
+ controller.close();
183
+ }
184
+ catch {
185
+ return;
186
+ }
187
+ }
188
+ function enqueueEvent(controller, event, payload) {
189
+ try {
190
+ controller.enqueue(formatAgUiEvent(event, payload));
191
+ return true;
192
+ }
193
+ catch {
194
+ return false;
195
+ }
196
+ }
197
+ async function createAgUiStreamResponse(agent, request, baseContext) {
198
+ const threadId = request.threadId ?? dntShim.crypto.randomUUID();
199
+ const runId = request.runId ?? generateRunId();
200
+ await agent.clearMemory();
201
+ const result = await agent.stream({
202
+ messages: normalizeMessages(request.messages),
203
+ context: buildStreamContext(request, baseContext, threadId, runId),
204
+ ...(request.model ? { model: request.model } : {}),
205
+ ...(request.maxOutputTokens ? { maxOutputTokens: request.maxOutputTokens } : {}),
206
+ });
207
+ const upstream = result.toDataStreamResponse();
208
+ const upstreamBody = upstream.body;
209
+ const stream = new ReadableStream({
210
+ start: async (controller) => {
211
+ const state = createStreamTransformState();
212
+ let reader = null;
213
+ let remainder = "";
214
+ const decoder = new TextDecoder();
215
+ if (!enqueueEvent(controller, "RunStarted", { runId, threadId, agentId: agent.id })) {
216
+ return;
217
+ }
218
+ try {
219
+ if (!upstreamBody) {
220
+ for (const event of finalizeRunEvents(state, null)) {
221
+ if (!enqueueEvent(controller, event.event, event.payload)) {
222
+ return;
223
+ }
224
+ }
225
+ closeController(controller);
226
+ return;
227
+ }
228
+ reader = upstreamBody.getReader();
229
+ while (true) {
230
+ const { done, value } = await reader.read();
231
+ if (done)
232
+ break;
233
+ remainder += decoder.decode(value, { stream: true });
234
+ const parsed = parseSseJsonEvents(remainder);
235
+ remainder = parsed.remainder;
236
+ for (const event of parsed.events) {
237
+ for (const mapped of mapRuntimeEventToAgUi(state, event)) {
238
+ if (!enqueueEvent(controller, mapped.event, mapped.payload)) {
239
+ return;
240
+ }
241
+ }
242
+ }
243
+ }
244
+ remainder += decoder.decode();
245
+ const parsed = parseSseJsonEvents(remainder);
246
+ for (const event of parsed.events) {
247
+ for (const mapped of mapRuntimeEventToAgUi(state, event)) {
248
+ if (!enqueueEvent(controller, mapped.event, mapped.payload)) {
249
+ return;
250
+ }
251
+ }
252
+ }
253
+ for (const event of finalizeRunEvents(state, null)) {
254
+ if (!enqueueEvent(controller, event.event, event.payload)) {
255
+ return;
256
+ }
257
+ }
258
+ }
259
+ catch (error) {
260
+ enqueueEvent(controller, "RunError", {
261
+ message: error instanceof Error ? error.message : "Agent run failed",
262
+ });
263
+ }
264
+ finally {
265
+ await reader?.cancel().catch(() => undefined);
266
+ closeController(controller);
267
+ }
268
+ },
269
+ });
270
+ return new dntShim.Response(stream, {
271
+ status: upstream.status,
272
+ statusText: upstream.statusText,
273
+ headers: { ...AG_UI_HEADERS },
274
+ });
275
+ }
276
+ function mergeConfig(config, options) {
277
+ if (!options)
278
+ return config;
279
+ return { ...options, ...config };
280
+ }
281
+ export function createAgUiHandler(agentIdOrConfig, options) {
282
+ return async function POST(requestOrCtx) {
283
+ const request = extractRequest(requestOrCtx);
284
+ let agent;
285
+ if (typeof agentIdOrConfig === "object" &&
286
+ agentIdOrConfig !== null &&
287
+ "agent" in agentIdOrConfig) {
288
+ const config = mergeConfig(agentIdOrConfig, options);
289
+ agent = config.agent;
290
+ options = config;
291
+ }
292
+ else {
293
+ const agentId = agentIdOrConfig;
294
+ try {
295
+ agent = getAgent(agentId);
296
+ }
297
+ catch {
298
+ return dntShim.Response.json({ error: "Agent not found" }, { status: 404 });
299
+ }
300
+ }
301
+ if (!agent) {
302
+ return dntShim.Response.json({ error: "Agent not found" }, { status: 404 });
303
+ }
304
+ try {
305
+ const parsed = AgUiRequestSchema.parse(await request.json());
306
+ if (parsed.tools.length > 0) {
307
+ return dntShim.Response.json({
308
+ error: "Injected AG-UI tools are not supported by createAgUiHandler yet. Use package-level wait/resume runtime primitives instead.",
309
+ }, { status: 501 });
310
+ }
311
+ const context = typeof options?.context === "function"
312
+ ? await options.context(request)
313
+ : options?.context ?? {};
314
+ return await createAgUiStreamResponse(agent, parsed, context);
315
+ }
316
+ catch (error) {
317
+ if (error instanceof z.ZodError) {
318
+ return dntShim.Response.json({
319
+ error: "Invalid AG-UI request",
320
+ details: error.issues.map((issue) => ({
321
+ path: issue.path,
322
+ message: issue.message,
323
+ })),
324
+ }, { status: 400 });
325
+ }
326
+ return dntShim.Response.json({
327
+ error: error instanceof Error ? error.message : "Internal server error",
328
+ }, { status: 500 });
329
+ }
330
+ };
331
+ }
@@ -84,6 +84,7 @@ export { getTextFromParts, getToolArguments, hasArgs, hasInput } from "./types.j
84
84
  export { BufferMemory, ConversationMemory, createMemory, createRedisMemory, type Memory, type MemoryPersistence, type MemoryStats, type RedisClient, RedisMemory, type RedisMemoryConfig, SummaryMemory, } from "./memory/index.js";
85
85
  export { agentAsTool, createWorkflow, getAgent, getAgentsAsTools, getAllAgentIds, registerAgent, type WorkflowConfig, type WorkflowResult, type WorkflowStep, } from "./composition/index.js";
86
86
  export { agent } from "./factory.js";
87
+ export { type AgUiContextItem, type AgUiHandlerConfigWithAgent, type AgUiHandlerOptions, type AgUiInjectedTool, type AgUiRequest, AgUiRequestSchema, createAgUiHandler, } from "./ag-ui-handler.js";
87
88
  export { type ChatHandlerBeforeStream, type ChatHandlerBeforeStreamContext, type ChatHandlerBeforeStreamResult, type ChatHandlerConfigWithAgent, type ChatHandlerMessageInput, type ChatHandlerOptions, createChatHandler, } from "./chat-handler.js";
88
- export { AgentRuntime } from "./runtime/index.js";
89
+ export { AgentRuntime, RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, type RunResumeSessionManagerOptions, type RunSessionStatus, type SubmitResumeValueOutcome, WaitConflictError, WaitNotPendingError, } from "./runtime/index.js";
89
90
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,WAAW,EACX,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,iBAAiB,EACtB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,yBAAyB,CAAC;AAGjC,YAAY,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,OAAO,IAAI,YAAY,EACvB,WAAW,EACX,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,iBAAiB,EACtB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,8BAA8B,EACnC,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
@@ -83,5 +83,6 @@ export { getTextFromParts, getToolArguments, hasArgs, hasInput } from "./types.j
83
83
  export { BufferMemory, ConversationMemory, createMemory, createRedisMemory, RedisMemory, SummaryMemory, } from "./memory/index.js";
84
84
  export { agentAsTool, createWorkflow, getAgent, getAgentsAsTools, getAllAgentIds, registerAgent, } from "./composition/index.js";
85
85
  export { agent } from "./factory.js";
86
+ export { AgUiRequestSchema, createAgUiHandler, } from "./ag-ui-handler.js";
86
87
  export { createChatHandler, } from "./chat-handler.js";
87
- export { AgentRuntime } from "./runtime/index.js";
88
+ export { AgentRuntime, RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, WaitConflictError, WaitNotPendingError, } from "./runtime/index.js";
@@ -13,6 +13,8 @@
13
13
  import { type AgentConfig, type AgentResponse, type Message, type ToolCall } from "../types.js";
14
14
  import { type Memory } from "../memory/index.js";
15
15
  export { closeSSEStream, generateMessageId, sendSSE } from "./sse-utils.js";
16
+ export { RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, WaitConflictError, WaitNotPendingError, } from "./resume-session.js";
17
+ export type { RunResumeSessionManagerOptions, RunSessionStatus, SubmitResumeValueOutcome, } from "./resume-session.js";
16
18
  export { executeConfiguredTool, getAvailableTools, isDynamicTool, parseToolArgs, } from "./tool-helpers.js";
17
19
  export type { ParsedToolArgs, ToolConfigEntry } from "./tool-helpers.js";
18
20
  export { accumulateUsage, getMaxSteps, normalizeInput } from "./input-utils.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAGlB,KAAK,OAAO,EAEZ,KAAK,QAAQ,EACd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAiB/D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACb,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,aA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EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,CAAC,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,aAAa,CAAC;IAgDzB;;;OAGG;IACG,MAAM,CACV,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,SAAS,CAAC,EAAE;QACV,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;QAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QAClC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;KAC9C,EACD,aAAa,CAAC,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,EAChC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAsHtC;;OAEG;YACW,gBAAgB;IA+O9B;;;;OAIG;YACW,yBAAyB;IA2RvC;;OAEG;YACW,eAAe;IAqC7B;;OAEG;YACW,mBAAmB;IAOjC;;OAEG;IACH,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,sBAAsB;IAY9B;;OAEG;IACH,SAAS,IAAI,MAAM,CAAC,OAAO,CAAC;IAI5B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC;QAC9B,aAAa,EAAE,MAAM,CAAC;QACtB,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IAIF;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAGnC"}
@@ -27,6 +27,7 @@ import { AGENT_DEFAULTS } from "../ai-defaults.js";
27
27
  import { tryGetCacheKeyContext } from "../../cache/cache-key-builder.js";
28
28
  // Re-export from submodules
29
29
  export { closeSSEStream, generateMessageId, sendSSE } from "./sse-utils.js";
30
+ export { RunAlreadyExistsError, RunCancelledError, RunNotActiveError, RunResumeSessionManager, WaitConflictError, WaitNotPendingError, } from "./resume-session.js";
30
31
  export { executeConfiguredTool, getAvailableTools, isDynamicTool, parseToolArgs, } from "./tool-helpers.js";
31
32
  export { accumulateUsage, getMaxSteps, normalizeInput } from "./input-utils.js";
32
33
  export { createStreamState, processStream } from "./ai-stream-handler.js";
@@ -182,7 +183,11 @@ export class AgentRuntime {
182
183
  platform: detectPlatform(),
183
184
  };
184
185
  const chain = new MiddlewareChain(this.config.middleware);
185
- return chain.execute(agentContext, () => this.executeAgentLoop(systemPrompt, messages, resolvedModelString, maxOutputTokensOverride));
186
+ return chain.execute(agentContext, () => this.executeAgentLoop(systemPrompt, messages, {
187
+ agentId: this.id,
188
+ projectId: tryGetCacheKeyContext()?.projectId,
189
+ ...context,
190
+ }, resolvedModelString, maxOutputTokensOverride));
186
191
  });
187
192
  }
188
193
  /**
@@ -288,7 +293,7 @@ export class AgentRuntime {
288
293
  /**
289
294
  * Execute agent loop (with tool calling)
290
295
  */
291
- async executeAgentLoop(systemPrompt, messages, modelString, maxOutputTokensOverride) {
296
+ async executeAgentLoop(systemPrompt, messages, toolContext, modelString, maxOutputTokensOverride) {
292
297
  return withSpan("agent.execution_loop", async (loopSpan) => {
293
298
  const { maxAgentSteps } = getPlatformCapabilities();
294
299
  const maxSteps = this.computeMaxSteps(maxAgentSteps);
@@ -314,6 +319,8 @@ export class AgentRuntime {
314
319
  let tools = isLocal ? [] : await getAvailableTools(this.config.tools, {
315
320
  includeSkillTools: Boolean(this.config.skills),
316
321
  allowedRemoteToolNames,
322
+ remoteToolSources: this.config.remoteTools,
323
+ remoteToolContext: toolContext,
317
324
  });
318
325
  // Layer 1: Filter tools based on active skill policy (planning-time)
319
326
  if (activeSkillPolicy) {
@@ -416,10 +423,10 @@ export class AgentRuntime {
416
423
  const startTime = Date.now();
417
424
  const cacheCtx = tryGetCacheKeyContext();
418
425
  const result = await executeConfiguredTool(tc.toolName, toolCall.args, this.config.tools, {
419
- agentId: this.id,
420
426
  toolCallId: tc.toolCallId,
421
- projectId: cacheCtx?.projectId,
422
- }, allowedRemoteToolNames);
427
+ ...toolContext,
428
+ projectId: cacheCtx?.projectId ?? toolContext?.projectId,
429
+ }, allowedRemoteToolNames, this.config.remoteTools);
423
430
  toolCall.status = "completed";
424
431
  toolCall.result = result;
425
432
  toolCall.executionTime = Date.now() - startTime;
@@ -513,6 +520,8 @@ export class AgentRuntime {
513
520
  let tools = isLocalStreaming ? [] : await getAvailableTools(this.config.tools, {
514
521
  includeSkillTools: Boolean(this.config.skills),
515
522
  allowedRemoteToolNames,
523
+ remoteToolSources: this.config.remoteTools,
524
+ remoteToolContext: toolContext,
516
525
  });
517
526
  // Layer 1: Filter tools based on active skill policy (planning-time)
518
527
  if (activeSkillPolicy) {
@@ -635,10 +644,9 @@ export class AgentRuntime {
635
644
  const startTime = Date.now();
636
645
  callbacks?.onToolCall?.(toolCall);
637
646
  const result = await executeConfiguredTool(tc.name, toolCall.args, this.config.tools, {
638
- agentId: this.id,
639
647
  toolCallId: tc.id,
640
648
  ...toolContext,
641
- }, allowedRemoteToolNames);
649
+ }, allowedRemoteToolNames, this.config.remoteTools);
642
650
  throwIfAborted(abortSignal);
643
651
  toolCall.status = "completed";
644
652
  toolCall.result = result;
@@ -0,0 +1,61 @@
1
+ import * as dntShim from "../../../_dnt.shims.js";
2
+ export type RunSessionStatus = "running" | "waiting" | "completed" | "cancelled" | "failed";
3
+ export declare class RunCancelledError extends Error {
4
+ constructor(message?: string);
5
+ }
6
+ export declare class RunAlreadyExistsError extends Error {
7
+ constructor(runId: string);
8
+ }
9
+ export declare class RunNotActiveError extends Error {
10
+ constructor(runId: string);
11
+ }
12
+ export declare class WaitNotPendingError extends Error {
13
+ constructor(runId: string, waitKey: string);
14
+ }
15
+ export declare class WaitConflictError extends Error {
16
+ constructor(runId: string, waitKey: string);
17
+ }
18
+ export interface SubmitResumeValueOutcome {
19
+ accepted: true;
20
+ duplicate?: true;
21
+ }
22
+ export interface RunResumeSessionManagerOptions<T> {
23
+ waitingTtlMs?: number;
24
+ sessionTtlMs?: number | null;
25
+ maxConcurrentSessions?: number;
26
+ setTimeoutFn?: typeof dntShim.setTimeout;
27
+ clearTimeoutFn?: typeof clearTimeout;
28
+ getConflictKey?: (value: T) => string;
29
+ }
30
+ export declare class RunResumeSessionManager<T> {
31
+ private readonly options;
32
+ private readonly sessions;
33
+ constructor(options?: RunResumeSessionManagerOptions<T>);
34
+ private get waitingTtlMs();
35
+ private get sessionTtlMs();
36
+ private get maxConcurrentSessions();
37
+ private get setTimeoutFn();
38
+ private get clearTimeoutFn();
39
+ private getConflictKey;
40
+ private clearWaitingTimeout;
41
+ private clearSessionTimeout;
42
+ private scheduleSessionTimeout;
43
+ private scheduleWaitingTimeout;
44
+ private touchSession;
45
+ private finalizeSession;
46
+ startRun(input: {
47
+ runId: string;
48
+ threadId: string;
49
+ }): AbortSignal;
50
+ waitForSignal(runId: string, waitKey: string): Promise<T>;
51
+ submitSignal(runId: string, input: {
52
+ waitKey: string;
53
+ value: T;
54
+ }): SubmitResumeValueOutcome;
55
+ cancelRun(runId: string): boolean;
56
+ completeRun(runId: string): void;
57
+ failRun(runId: string): void;
58
+ getRunStatus(runId: string): RunSessionStatus | null;
59
+ reset(): void;
60
+ }
61
+ //# sourceMappingURL=resume-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume-session.d.ts","sourceRoot":"","sources":["../../../../src/src/agent/runtime/resume-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAClD,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE5F,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,SAAkB;CAItC;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,KAAK,EAAE,MAAM;CAI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