veryfront 0.1.63 → 0.1.65

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 (68) hide show
  1. package/esm/deno.js +1 -1
  2. package/esm/src/agent/runtime/index.d.ts +1 -0
  3. package/esm/src/agent/runtime/index.d.ts.map +1 -1
  4. package/esm/src/agent/runtime/index.js +10 -2
  5. package/esm/src/channels/control-plane.d.ts +259 -0
  6. package/esm/src/channels/control-plane.d.ts.map +1 -0
  7. package/esm/src/channels/control-plane.js +212 -0
  8. package/esm/src/channels/invoke.d.ts +71 -44
  9. package/esm/src/channels/invoke.d.ts.map +1 -1
  10. package/esm/src/channels/invoke.js +33 -114
  11. package/esm/src/integrations/endpoint-executor.d.ts +1 -0
  12. package/esm/src/integrations/endpoint-executor.d.ts.map +1 -1
  13. package/esm/src/integrations/endpoint-executor.js +44 -0
  14. package/esm/src/internal-agents/ag-ui-sse.d.ts +35 -0
  15. package/esm/src/internal-agents/ag-ui-sse.d.ts.map +1 -0
  16. package/esm/src/internal-agents/ag-ui-sse.js +263 -0
  17. package/esm/src/internal-agents/control-plane-auth.d.ts +20 -0
  18. package/esm/src/internal-agents/control-plane-auth.d.ts.map +1 -0
  19. package/esm/src/internal-agents/control-plane-auth.js +56 -0
  20. package/esm/src/internal-agents/request-body.d.ts +9 -0
  21. package/esm/src/internal-agents/request-body.d.ts.map +1 -0
  22. package/esm/src/internal-agents/request-body.js +28 -0
  23. package/esm/src/internal-agents/run-stream.d.ts +14 -0
  24. package/esm/src/internal-agents/run-stream.d.ts.map +1 -0
  25. package/esm/src/internal-agents/run-stream.js +259 -0
  26. package/esm/src/internal-agents/schema.d.ts +268 -0
  27. package/esm/src/internal-agents/schema.d.ts.map +1 -0
  28. package/esm/src/internal-agents/schema.js +71 -0
  29. package/esm/src/internal-agents/session-manager.d.ts +63 -0
  30. package/esm/src/internal-agents/session-manager.d.ts.map +1 -0
  31. package/esm/src/internal-agents/session-manager.js +258 -0
  32. package/esm/src/platform/adapters/runtime/deno/adapter.d.ts.map +1 -1
  33. package/esm/src/platform/adapters/runtime/deno/adapter.js +4 -13
  34. package/esm/src/platform/compat/process.d.ts.map +1 -1
  35. package/esm/src/platform/compat/process.js +42 -5
  36. package/esm/src/server/handlers/request/agent-run-cancel.handler.d.ts +11 -0
  37. package/esm/src/server/handlers/request/agent-run-cancel.handler.d.ts.map +1 -0
  38. package/esm/src/server/handlers/request/agent-run-cancel.handler.js +62 -0
  39. package/esm/src/server/handlers/request/agent-run-resume.handler.d.ts +11 -0
  40. package/esm/src/server/handlers/request/agent-run-resume.handler.d.ts.map +1 -0
  41. package/esm/src/server/handlers/request/agent-run-resume.handler.js +77 -0
  42. package/esm/src/server/handlers/request/agent-stream.handler.d.ts +14 -0
  43. package/esm/src/server/handlers/request/agent-stream.handler.d.ts.map +1 -0
  44. package/esm/src/server/handlers/request/agent-stream.handler.js +86 -0
  45. package/esm/src/server/handlers/request/internal-agents-list.handler.d.ts +11 -0
  46. package/esm/src/server/handlers/request/internal-agents-list.handler.d.ts.map +1 -0
  47. package/esm/src/server/handlers/request/internal-agents-list.handler.js +73 -0
  48. package/esm/src/server/runtime-handler/index.d.ts.map +1 -1
  49. package/esm/src/server/runtime-handler/index.js +8 -0
  50. package/package.json +1 -1
  51. package/src/deno.js +1 -1
  52. package/src/src/agent/runtime/index.ts +12 -2
  53. package/src/src/channels/control-plane.ts +332 -0
  54. package/src/src/channels/invoke.ts +44 -164
  55. package/src/src/integrations/endpoint-executor.ts +51 -0
  56. package/src/src/internal-agents/ag-ui-sse.ts +327 -0
  57. package/src/src/internal-agents/control-plane-auth.ts +82 -0
  58. package/src/src/internal-agents/request-body.ts +42 -0
  59. package/src/src/internal-agents/run-stream.ts +354 -0
  60. package/src/src/internal-agents/schema.ts +102 -0
  61. package/src/src/internal-agents/session-manager.ts +358 -0
  62. package/src/src/platform/adapters/runtime/deno/adapter.ts +9 -11
  63. package/src/src/platform/compat/process.ts +56 -3
  64. package/src/src/server/handlers/request/agent-run-cancel.handler.ts +86 -0
  65. package/src/src/server/handlers/request/agent-run-resume.handler.ts +108 -0
  66. package/src/src/server/handlers/request/agent-stream.handler.ts +125 -0
  67. package/src/src/server/handlers/request/internal-agents-list.handler.ts +100 -0
  68. package/src/src/server/runtime-handler/index.ts +8 -0
@@ -1,11 +1,12 @@
1
1
  import type { Agent, AgentMessage as Message, AgentResponse } from "../agent/index.js";
2
2
  import type { HandlerContext } from "../types/index.js";
3
3
  import { z } from "zod";
4
+ import { type RuntimeAgentDiscoveryDeps } from "./control-plane.js";
4
5
  export declare const ChannelInvokeRequestSchema: z.ZodObject<{
5
6
  dispatchId: z.ZodString;
6
7
  conversationId: z.ZodString;
7
8
  projectId: z.ZodString;
8
- agentConfigId: z.ZodString;
9
+ assistantId: z.ZodString;
9
10
  platform: z.ZodLiteral<"slack">;
10
11
  inboundMessage: z.ZodObject<{
11
12
  text: z.ZodString;
@@ -97,7 +98,7 @@ export declare const ChannelInvokeRequestSchema: z.ZodObject<{
97
98
  projectId: string;
98
99
  dispatchId: string;
99
100
  conversationId: string;
100
- agentConfigId: string;
101
+ assistantId: string;
101
102
  inboundMessage: {
102
103
  text: string;
103
104
  userId: string;
@@ -128,7 +129,7 @@ export declare const ChannelInvokeRequestSchema: z.ZodObject<{
128
129
  projectId: string;
129
130
  dispatchId: string;
130
131
  conversationId: string;
131
- agentConfigId: string;
132
+ assistantId: string;
132
133
  inboundMessage: {
133
134
  text: string;
134
135
  userId: string;
@@ -155,6 +156,67 @@ export declare const ChannelInvokeRequestSchema: z.ZodObject<{
155
156
  maxResponseTokens?: number | undefined;
156
157
  } | undefined;
157
158
  }>;
159
+ export declare const ChannelAssistantsRequestSchema: z.ZodObject<{
160
+ requestId: z.ZodString;
161
+ projectId: z.ZodString;
162
+ platform: z.ZodLiteral<"slack">;
163
+ }, "strip", z.ZodTypeAny, {
164
+ requestId: string;
165
+ platform: "slack";
166
+ projectId: string;
167
+ }, {
168
+ requestId: string;
169
+ platform: "slack";
170
+ projectId: string;
171
+ }>;
172
+ export declare const ChannelAssistantSchema: z.ZodObject<{
173
+ id: z.ZodString;
174
+ name: z.ZodString;
175
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
176
+ model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
177
+ }, "strip", z.ZodTypeAny, {
178
+ name: string;
179
+ id: string;
180
+ description?: string | null | undefined;
181
+ model?: string | null | undefined;
182
+ }, {
183
+ name: string;
184
+ id: string;
185
+ description?: string | null | undefined;
186
+ model?: string | null | undefined;
187
+ }>;
188
+ export declare const ChannelAssistantsResponseSchema: z.ZodObject<{
189
+ assistants: z.ZodArray<z.ZodObject<{
190
+ id: z.ZodString;
191
+ name: z.ZodString;
192
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
193
+ model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
194
+ }, "strip", z.ZodTypeAny, {
195
+ name: string;
196
+ id: string;
197
+ description?: string | null | undefined;
198
+ model?: string | null | undefined;
199
+ }, {
200
+ name: string;
201
+ id: string;
202
+ description?: string | null | undefined;
203
+ model?: string | null | undefined;
204
+ }>, "many">;
205
+ }, "strip", z.ZodTypeAny, {
206
+ assistants: {
207
+ name: string;
208
+ id: string;
209
+ description?: string | null | undefined;
210
+ model?: string | null | undefined;
211
+ }[];
212
+ }, {
213
+ assistants: {
214
+ name: string;
215
+ id: string;
216
+ description?: string | null | undefined;
217
+ model?: string | null | undefined;
218
+ }[];
219
+ }>;
158
220
  export declare const ChannelResponsePartSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
159
221
  type: z.ZodLiteral<"text">;
160
222
  text: z.ZodString;
@@ -375,53 +437,18 @@ export declare const ChannelInvokeResponseSchema: z.ZodObject<{
375
437
  outputTokens?: number | undefined;
376
438
  } | undefined;
377
439
  }>;
378
- declare const dispatchClaimsSchema: z.ZodObject<{
379
- iss: z.ZodString;
380
- aud: z.ZodString;
381
- sub: z.ZodString;
382
- project_id: z.ZodString;
383
- platform: z.ZodString;
384
- body_sha256: z.ZodString;
385
- iat: z.ZodNumber;
386
- exp: z.ZodNumber;
387
- }, "strip", z.ZodTypeAny, {
388
- project_id: string;
389
- platform: string;
390
- sub: string;
391
- iss: string;
392
- aud: string;
393
- body_sha256: string;
394
- iat: number;
395
- exp: number;
396
- }, {
397
- project_id: string;
398
- platform: string;
399
- sub: string;
400
- iss: string;
401
- aud: string;
402
- body_sha256: string;
403
- iat: number;
404
- exp: number;
405
- }>;
406
440
  export type ChannelInvokeRequest = z.infer<typeof ChannelInvokeRequestSchema>;
407
441
  export type ChannelInvokeResponse = z.infer<typeof ChannelInvokeResponseSchema>;
442
+ export type ChannelAssistantsRequest = z.infer<typeof ChannelAssistantsRequestSchema>;
443
+ export type ChannelAssistantsResponse = z.infer<typeof ChannelAssistantsResponseSchema>;
408
444
  type ChannelResponsePart = z.infer<typeof ChannelResponsePartSchema>;
409
- type DispatchClaims = z.infer<typeof dispatchClaimsSchema>;
410
- export interface ChannelInvokeDeps {
411
- ensureProjectDiscovery: (ctx: HandlerContext) => Promise<void>;
412
- getAgent: (id: string) => Agent | undefined;
413
- getAllAgentIds: () => string[];
445
+ export interface ChannelInvokeDeps extends RuntimeAgentDiscoveryDeps {
414
446
  }
415
447
  export declare const defaultChannelInvokeDeps: ChannelInvokeDeps;
416
- export declare function verifyDispatchJws(jws: string, body: string, options: {
417
- audience: string;
418
- publicKeyPem: string;
419
- maxAgeSeconds: number;
420
- expectedProjectId?: string;
421
- }): Promise<DispatchClaims>;
448
+ export declare function listChannelAssistants(ctx: HandlerContext, deps: ChannelInvokeDeps): Promise<ChannelAssistantsResponse>;
449
+ export { verifyDispatchJws } from "./control-plane.js";
422
450
  export declare function normalizeConversationHistoryForRuntime(messages: ChannelInvokeRequest["conversationHistory"]): Message[];
423
- export declare function resolveChannelInvokeAgent(agentConfigId: string, deps: Pick<ChannelInvokeDeps, "getAgent" | "getAllAgentIds">): Agent | undefined;
451
+ export declare function resolveChannelInvokeAgent(assistantId: string, deps: Pick<ChannelInvokeDeps, "getAgent" | "getAllAgentIds">): Agent | undefined;
424
452
  export declare function buildChannelResponseParts(response: AgentResponse): ChannelResponsePart[];
425
453
  export declare function executeChannelInvoke(payload: ChannelInvokeRequest, ctx: HandlerContext, deps: ChannelInvokeDeps): Promise<ChannelInvokeResponse>;
426
- export {};
427
454
  //# sourceMappingURL=invoke.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../../src/src/channels/invoke.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,IAAI,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8BxB,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBrC,CAAC;AAiCH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMpC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYtC,CAAC;AAQH,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;EASxB,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,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,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AACtF,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAExF,KAAK,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AACrE,MAAM,WAAW,iBAAkB,SAAQ,yBAAyB;CAAG;AAEvE,eAAO,MAAM,wBAAwB,EAAE,iBAItC,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,yBAAyB,CAAC,CAYpC;AACD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAqCvD,wBAAgB,sCAAsC,CACpD,QAAQ,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,GACpD,OAAO,EAAE,CAUX;AAED,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,gBAAgB,CAAC,GAC3D,KAAK,GAAG,SAAS,CAEnB;AAsDD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,aAAa,GAAG,mBAAmB,EAAE,CAiDxF;AAgBD,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,EAC7B,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,qBAAqB,CAAC,CAkEhC"}
@@ -1,12 +1,10 @@
1
- import * as dntShim from "../../_dnt.shims.js";
2
1
  import { fromError } from "../errors/veryfront-error.js";
3
2
  import { serverLogger } from "../utils/index.js";
4
- import { base64urlEncodeBytes } from "../utils/base64url.js";
5
3
  import { z } from "zod";
6
4
  import { getAgent as getRegisteredAgent, getAllAgentIds as getRegisteredAgentIds, } from "../agent/composition/composition.js";
5
+ import { listRuntimeAgents } from "./control-plane.js";
7
6
  import { ensureProjectDiscovery as ensureProjectDiscoveryForProject } from "../server/handlers/request/api/project-discovery.js";
8
7
  const logger = serverLogger.component("channels-invoke");
9
- const SIGNATURE_SKEW_SECONDS = 5;
10
8
  const rawHistoryPartSchema = z.object({
11
9
  type: z.string(),
12
10
  }).passthrough();
@@ -24,11 +22,11 @@ const channelInvokeHistoryMessageSchema = z.object({
24
22
  metadata: z.record(z.unknown()).optional(),
25
23
  createdAt: z.string().optional(),
26
24
  });
27
- export const ChannelInvokeRequestSchema = z.object({
25
+ const channelInvokeRequestWireSchema = z.object({
28
26
  dispatchId: z.string().min(1),
29
27
  conversationId: z.string().min(1),
30
28
  projectId: z.string().min(1),
31
- agentConfigId: z.string().min(1),
29
+ assistantId: z.string().min(1),
32
30
  platform: z.literal("slack"),
33
31
  inboundMessage: z.object({
34
32
  text: z.string(),
@@ -42,6 +40,21 @@ export const ChannelInvokeRequestSchema = z.object({
42
40
  maxResponseTokens: z.number().int().positive().max(16384).optional(),
43
41
  }).optional(),
44
42
  });
43
+ export const ChannelInvokeRequestSchema = channelInvokeRequestWireSchema;
44
+ export const ChannelAssistantsRequestSchema = z.object({
45
+ requestId: z.string().min(1),
46
+ projectId: z.string().min(1),
47
+ platform: z.literal("slack"),
48
+ });
49
+ export const ChannelAssistantSchema = z.object({
50
+ id: z.string().min(1),
51
+ name: z.string().min(1),
52
+ description: z.string().nullable().optional(),
53
+ model: z.string().nullable().optional(),
54
+ });
55
+ export const ChannelAssistantsResponseSchema = z.object({
56
+ assistants: z.array(ChannelAssistantSchema),
57
+ });
45
58
  const channelTextPartSchema = z.object({
46
59
  type: z.literal("text"),
47
60
  text: z.string(),
@@ -88,97 +101,22 @@ export const ChannelInvokeResponseSchema = z.object({
88
101
  retryable: z.boolean(),
89
102
  }).optional(),
90
103
  });
91
- const dispatchHeaderSchema = z.object({
92
- alg: z.literal("EdDSA"),
93
- typ: z.string().optional(),
94
- kid: z.string().optional(),
95
- });
96
- const dispatchClaimsSchema = z.object({
97
- iss: z.string(),
98
- aud: z.string(),
99
- sub: z.string(),
100
- project_id: z.string(),
101
- platform: z.string(),
102
- body_sha256: z.string(),
103
- iat: z.number().int(),
104
- exp: z.number().int(),
105
- });
106
104
  export const defaultChannelInvokeDeps = {
107
105
  ensureProjectDiscovery: ensureProjectDiscoveryForProject,
108
106
  getAgent: getRegisteredAgent,
109
107
  getAllAgentIds: getRegisteredAgentIds,
110
108
  };
111
- function base64urlDecodeToBytes(input) {
112
- const normalized = input
113
- .replaceAll("-", "+")
114
- .replaceAll("_", "/")
115
- .padEnd(Math.ceil(input.length / 4) * 4, "=");
116
- return toArrayBuffer(Uint8Array.from(atob(normalized), (char) => char.charCodeAt(0)));
117
- }
118
- function toArrayBuffer(bytes) {
119
- const buffer = new ArrayBuffer(bytes.byteLength);
120
- new Uint8Array(buffer).set(bytes);
121
- return buffer;
122
- }
123
- function pemToDer(pem, label) {
124
- const body = pem
125
- .replace(`-----BEGIN ${label}-----`, "")
126
- .replace(`-----END ${label}-----`, "")
127
- .replace(/\s/g, "");
128
- return toArrayBuffer(Uint8Array.from(atob(body), (char) => char.charCodeAt(0)));
129
- }
130
- async function importEd25519PublicKey(pem) {
131
- return dntShim.crypto.subtle.importKey("spki", pemToDer(pem, "PUBLIC KEY"), "Ed25519", false, ["verify"]);
132
- }
133
- async function sha256Base64url(body) {
134
- const hash = await dntShim.crypto.subtle.digest("SHA-256", new TextEncoder().encode(body));
135
- return base64urlEncodeBytes(new Uint8Array(hash));
136
- }
137
- export async function verifyDispatchJws(jws, body, options) {
138
- const parts = jws.split(".");
139
- if (parts.length !== 3) {
140
- throw new Error("Channel dispatch signature must be a compact JWS");
141
- }
142
- const encodedHeader = parts[0];
143
- const encodedPayload = parts[1];
144
- const encodedSignature = parts[2];
145
- if (!encodedHeader || !encodedPayload || !encodedSignature) {
146
- throw new Error("Channel dispatch signature must include header, payload, and signature");
147
- }
148
- const header = dispatchHeaderSchema.parse(JSON.parse(new TextDecoder().decode(base64urlDecodeToBytes(encodedHeader))));
149
- const claims = dispatchClaimsSchema.parse(JSON.parse(new TextDecoder().decode(base64urlDecodeToBytes(encodedPayload))));
150
- if (header.alg !== "EdDSA") {
151
- throw new Error("Unsupported channel dispatch JWS algorithm");
152
- }
153
- const signingInput = new TextEncoder().encode(`${encodedHeader}.${encodedPayload}`);
154
- const signature = base64urlDecodeToBytes(encodedSignature);
155
- const publicKey = await importEd25519PublicKey(options.publicKeyPem);
156
- const verified = await dntShim.crypto.subtle.verify("Ed25519", publicKey, signature, signingInput);
157
- if (!verified) {
158
- throw new Error("Channel dispatch signature verification failed");
159
- }
160
- if (claims.aud !== options.audience) {
161
- throw new Error("Channel dispatch audience mismatch");
162
- }
163
- if (options.expectedProjectId && claims.project_id !== options.expectedProjectId) {
164
- throw new Error("Channel dispatch project mismatch");
165
- }
166
- const now = Math.floor(Date.now() / 1000);
167
- if (claims.exp <= now) {
168
- throw new Error("Channel dispatch signature expired");
169
- }
170
- if (claims.iat > now + SIGNATURE_SKEW_SECONDS) {
171
- throw new Error("Channel dispatch signature issued in the future");
172
- }
173
- if (now - claims.iat > options.maxAgeSeconds) {
174
- throw new Error("Channel dispatch signature is too old");
175
- }
176
- const bodySha256 = await sha256Base64url(body);
177
- if (claims.body_sha256 !== bodySha256) {
178
- throw new Error("Channel dispatch body hash mismatch");
179
- }
180
- return claims;
109
+ export async function listChannelAssistants(ctx, deps) {
110
+ const response = await listRuntimeAgents(ctx, deps);
111
+ const assistants = response.agents.map((agent) => ChannelAssistantSchema.parse({
112
+ id: agent.id,
113
+ name: agent.name,
114
+ description: agent.description ?? null,
115
+ model: agent.model ?? null,
116
+ }));
117
+ return ChannelAssistantsResponseSchema.parse({ assistants });
181
118
  }
119
+ export { verifyDispatchJws } from "./control-plane.js";
182
120
  function normalizeConversationPart(part) {
183
121
  if (part.type === "text" && typeof part.text === "string") {
184
122
  return { type: "text", text: part.text };
@@ -217,27 +155,8 @@ export function normalizeConversationHistoryForRuntime(messages) {
217
155
  ...(message.metadata ? { metadata: message.metadata } : {}),
218
156
  }));
219
157
  }
220
- export function resolveChannelInvokeAgent(agentConfigId, deps) {
221
- const exactAgent = deps.getAgent(agentConfigId);
222
- if (exactAgent) {
223
- return exactAgent;
224
- }
225
- const agentIds = deps.getAllAgentIds();
226
- if (agentIds.length !== 1) {
227
- return undefined;
228
- }
229
- const onlyAgentId = agentIds[0];
230
- if (!onlyAgentId) {
231
- return undefined;
232
- }
233
- const onlyAgent = deps.getAgent(onlyAgentId);
234
- if (onlyAgent) {
235
- logger.warn("Channel invoke fell back to the only discovered runtime agent because agentConfigId did not match a registry id", {
236
- requestedAgentConfigId: agentConfigId,
237
- resolvedAgentId: onlyAgentId,
238
- });
239
- }
240
- return onlyAgent;
158
+ export function resolveChannelInvokeAgent(assistantId, deps) {
159
+ return deps.getAgent(assistantId);
241
160
  }
242
161
  function normalizeToolCallState(status) {
243
162
  switch (status) {
@@ -338,10 +257,10 @@ function classifyRuntimeError(error) {
338
257
  }
339
258
  export async function executeChannelInvoke(payload, ctx, deps) {
340
259
  await deps.ensureProjectDiscovery(ctx);
341
- const agent = resolveChannelInvokeAgent(payload.agentConfigId, deps);
260
+ const agent = resolveChannelInvokeAgent(payload.assistantId, deps);
342
261
  if (!agent) {
343
262
  logger.error("Channel invoke could not resolve a runtime agent for the request", {
344
- requestedAgentConfigId: payload.agentConfigId,
263
+ requestedAssistantId: payload.assistantId,
345
264
  discoveredAgentIds: deps.getAllAgentIds(),
346
265
  projectSlug: ctx.projectSlug,
347
266
  projectId: ctx.projectId,
@@ -364,7 +283,7 @@ export async function executeChannelInvoke(payload, ctx, deps) {
364
283
  dispatchId: payload.dispatchId,
365
284
  conversationId: payload.conversationId,
366
285
  projectId: payload.projectId,
367
- agentConfigId: payload.agentConfigId,
286
+ assistantId: payload.assistantId,
368
287
  channel: payload.inboundMessage,
369
288
  },
370
289
  ...(payload.generation?.maxResponseTokens
@@ -1,4 +1,5 @@
1
1
  import type { IntegrationEndpoint } from "./types.js";
2
+ export declare function validateEndpointUrl(url: string): void;
2
3
  interface ExecutionContext {
3
4
  integration: string;
4
5
  toolId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-executor.d.ts","sourceRoot":"","sources":["../../../src/src/integrations/endpoint-executor.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGtD,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,mBAAmB,EAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAK9C"}
1
+ {"version":3,"file":"endpoint-executor.d.ts","sourceRoot":"","sources":["../../../src/src/integrations/endpoint-executor.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAetD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAiCrD;AAED,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,mBAAmB,EAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAK9C"}
@@ -8,6 +8,48 @@
8
8
  import * as dntShim from "../../_dnt.shims.js";
9
9
  import { logger } from "../utils/index.js";
10
10
  import { INVALID_ARGUMENT } from "../errors/index.js";
11
+ const PRIVATE_IP_RANGES = [
12
+ /^127\./, // 127.0.0.0/8
13
+ /^10\./, // 10.0.0.0/8
14
+ /^172\.(1[6-9]|2\d|3[01])\./, // 172.16.0.0/12
15
+ /^192\.168\./, // 192.168.0.0/16
16
+ /^169\.254\./, // 169.254.0.0/16
17
+ /^0\./, // 0.0.0.0/8
18
+ /^::1$/, // IPv6 loopback
19
+ /^f[cd][0-9a-f]{2}:/i, // IPv6 unique local (fc00::/7)
20
+ /^fe80:/i, // IPv6 link-local (fe80::/10)
21
+ ];
22
+ export function validateEndpointUrl(url) {
23
+ let parsed;
24
+ try {
25
+ parsed = new URL(url);
26
+ }
27
+ catch {
28
+ throw INVALID_ARGUMENT.create({ detail: `Invalid endpoint URL: ${url}` });
29
+ }
30
+ if (parsed.protocol !== "https:") {
31
+ throw INVALID_ARGUMENT.create({
32
+ detail: `Endpoint URL must use HTTPS: ${parsed.protocol}`,
33
+ });
34
+ }
35
+ const hostname = parsed.hostname.toLowerCase();
36
+ if (hostname === "localhost") {
37
+ throw INVALID_ARGUMENT.create({
38
+ detail: "Endpoint URL must not target localhost",
39
+ });
40
+ }
41
+ // Strip IPv6 brackets for regex matching
42
+ const bare = hostname.startsWith("[") && hostname.endsWith("]")
43
+ ? hostname.slice(1, -1)
44
+ : hostname;
45
+ for (const range of PRIVATE_IP_RANGES) {
46
+ if (range.test(bare)) {
47
+ throw INVALID_ARGUMENT.create({
48
+ detail: "Endpoint URL must not target private/internal networks",
49
+ });
50
+ }
51
+ }
52
+ }
11
53
  export async function executeEndpoint(endpoint, args, accessToken, ctx) {
12
54
  if (endpoint.type === "graphql") {
13
55
  return executeGraphQL(endpoint, args, accessToken, ctx);
@@ -40,6 +82,7 @@ async function executeGraphQL(endpoint, args, accessToken, ctx) {
40
82
  headers[key] = args[key] !== undefined ? String(args[key]) : String(def.default ?? "");
41
83
  }
42
84
  }
85
+ validateEndpointUrl(endpoint.url);
43
86
  logger.debug("Executing GraphQL endpoint", {
44
87
  integration: ctx.integration,
45
88
  tool: ctx.toolId,
@@ -112,6 +155,7 @@ async function executeRest(endpoint, args, accessToken, ctx) {
112
155
  body = JSON.stringify(bodyObj);
113
156
  headers["Content-Type"] = endpoint.contentType ?? "application/json";
114
157
  }
158
+ validateEndpointUrl(urlObj.toString());
115
159
  logger.debug("Executing REST endpoint", {
116
160
  integration: ctx.integration,
117
161
  tool: ctx.toolId,
@@ -0,0 +1,35 @@
1
+ import type { AgentResponse } from "../agent/index.js";
2
+ type RuntimeDataEvent = Record<string, unknown> & {
3
+ type: string;
4
+ };
5
+ export interface RunFinishedMetadata {
6
+ provider?: string;
7
+ model?: string;
8
+ inputTokens?: number;
9
+ outputTokens?: number;
10
+ totalTokens?: number;
11
+ finishReason?: string;
12
+ }
13
+ export interface StreamTransformState {
14
+ messageId: string | null;
15
+ textOpen: boolean;
16
+ stepIndex: number;
17
+ sawTerminalError: boolean;
18
+ metadata: RunFinishedMetadata;
19
+ }
20
+ export declare function createStreamTransformState(): StreamTransformState;
21
+ export declare function formatAgUiEvent(event: string, payload: Record<string, unknown>): Uint8Array;
22
+ export declare function parseSseJsonEvents(chunk: string): {
23
+ events: RuntimeDataEvent[];
24
+ remainder: string;
25
+ };
26
+ export declare function mapRuntimeEventToAgUi(state: StreamTransformState, event: RuntimeDataEvent): Array<{
27
+ event: string;
28
+ payload: Record<string, unknown>;
29
+ }>;
30
+ export declare function finalizeRunEvents(state: StreamTransformState, response: AgentResponse | null): Array<{
31
+ event: string;
32
+ payload: Record<string, unknown>;
33
+ }>;
34
+ export {};
35
+ //# sourceMappingURL=ag-ui-sse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ag-ui-sse.d.ts","sourceRoot":"","sources":["../../../src/src/internal-agents/ag-ui-sse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,E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