@agents24/node 0.5.10 → 0.5.12

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 (39) hide show
  1. package/compatibility.json +7 -7
  2. package/dist/bff.cjs +80 -56
  3. package/dist/bff.cjs.map +1 -1
  4. package/dist/bff.d.cts +1 -1
  5. package/dist/bff.d.ts +1 -1
  6. package/dist/bff.js +80 -56
  7. package/dist/bff.js.map +1 -1
  8. package/dist/{client-xs_JXgvz.d.cts → client-DTdpRgGB.d.cts} +97 -1
  9. package/dist/{client-xs_JXgvz.d.ts → client-DTdpRgGB.d.ts} +97 -1
  10. package/dist/index.cjs +62 -17
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +2 -2
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +62 -17
  15. package/dist/index.js.map +1 -1
  16. package/dist/server.cjs +11 -1
  17. package/dist/server.cjs.map +1 -1
  18. package/dist/server.d.cts +6 -1
  19. package/dist/server.d.ts +6 -1
  20. package/dist/server.js +11 -2
  21. package/dist/server.js.map +1 -1
  22. package/dist/types/bff-values.d.ts +6 -0
  23. package/dist/types/bff-values.d.ts.map +1 -0
  24. package/dist/types/bff.d.ts.map +1 -1
  25. package/dist/types/client.d.ts +2 -0
  26. package/dist/types/client.d.ts.map +1 -1
  27. package/dist/types/delegations.d.ts +80 -0
  28. package/dist/types/delegations.d.ts.map +1 -0
  29. package/dist/types/generated/delegations.d.ts +18 -0
  30. package/dist/types/generated/delegations.d.ts.map +1 -0
  31. package/dist/types/generated/manifest.d.ts +1 -1
  32. package/dist/types/generated/manifest.d.ts.map +1 -1
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/server.d.ts +5 -0
  36. package/dist/types/server.d.ts.map +1 -1
  37. package/dist/types/types.d.ts +1 -0
  38. package/dist/types/types.d.ts.map +1 -1
  39. package/package.json +4 -4
package/dist/bff.js CHANGED
@@ -213,6 +213,44 @@ function reportFailureResponse(callback, request, operation, response) {
213
213
  return response;
214
214
  }
215
215
 
216
+ // src/bff-values.ts
217
+ function normalized(value, field) {
218
+ const result = String(value || "").trim();
219
+ if (!result || /[\r\n\0]/.test(result)) throw new Error(`${field} is required.`);
220
+ return result;
221
+ }
222
+ function stringValue(value) {
223
+ const result = typeof value === "string" ? value.trim() : "";
224
+ return result || void 0;
225
+ }
226
+ function stringList(value) {
227
+ return Array.isArray(value) ? value.map(stringValue).filter((item) => Boolean(item)) : [];
228
+ }
229
+ function objectValue(value) {
230
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
231
+ }
232
+ function bootstrapDocument(raw, agentVersionId) {
233
+ const features = objectValue(raw.features);
234
+ const selectable = objectValue(features.models).selectable === true;
235
+ const resolvedVersionId = stringValue(raw.agent_version_id) || agentVersionId || "";
236
+ const versionNumber = Number(raw.agent_version_number || 0);
237
+ return {
238
+ version: String(raw.version || "agents24.embed.bootstrap.v1"),
239
+ deployment: {
240
+ id: "server-embed",
241
+ name: normalized(String(raw.agent_name || ""), "agent_name"),
242
+ version_policy: agentVersionId ? { mode: "pinned", version_id: agentVersionId } : { mode: "latest_published" },
243
+ resolved_agent_version_id: resolvedVersionId,
244
+ resolved_agent_version_number: Number.isFinite(versionNumber) ? versionNumber : 0,
245
+ policy_epoch: 0
246
+ },
247
+ authentication: { modes: ["server_embed"], access_token_lifetime_seconds: 0, jwks_path: "" },
248
+ capabilities: ["attachments.read", "attachments.write", "feedback.write", ...selectable ? ["models.select"] : []],
249
+ features,
250
+ native_profiles: []
251
+ };
252
+ }
253
+
216
254
  // src/bff.ts
217
255
  var JSON_LIMIT_BYTES = 1048576;
218
256
  var MAX_INPUT_LENGTH = 2e5;
@@ -259,11 +297,6 @@ function createCustomerIdentityResolver(embed, integrationId, integrationName) {
259
297
  return value;
260
298
  };
261
299
  }
262
- function normalized(value, field) {
263
- const result = String(value || "").trim();
264
- if (!result || /[\r\n\0]/.test(result)) throw new Error(`${field} is required.`);
265
- return result;
266
- }
267
300
  function normalizeBasePath(value) {
268
301
  const path = String(value || "/api/agents24").trim().replace(/\/+$/, "");
269
302
  if (!path.startsWith("/") || /[\r\n\0?#]/.test(path)) throw new Error("basePath must be an absolute path.");
@@ -311,16 +344,6 @@ var BffInputError = class extends Error {
311
344
  status;
312
345
  code;
313
346
  };
314
- function stringValue(value) {
315
- const result = typeof value === "string" ? value.trim() : "";
316
- return result || void 0;
317
- }
318
- function stringList(value) {
319
- return Array.isArray(value) ? value.map(stringValue).filter((item) => Boolean(item)) : [];
320
- }
321
- function objectValue(value) {
322
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
323
- }
324
347
  function routeId(path, pattern, field) {
325
348
  const match = pattern.exec(path);
326
349
  if (!match?.[1]) throw new BffInputError(404, "NOT_FOUND", "The requested BFF route does not exist.");
@@ -364,27 +387,6 @@ function sseResponse(execute, headers, failurePayload, onFailure) {
364
387
  }).finally(() => writer.close().catch(() => void 0));
365
388
  return new Response(stream.readable, { headers: sseHeaders(headers) });
366
389
  }
367
- function bootstrapDocument(raw, agentVersionId) {
368
- const features = objectValue(raw.features);
369
- const selectable = objectValue(features.models).selectable === true;
370
- const resolvedVersionId = stringValue(raw.agent_version_id) || agentVersionId || "";
371
- const versionNumber = Number(raw.agent_version_number || 0);
372
- return {
373
- version: String(raw.version || "agents24.embed.bootstrap.v1"),
374
- deployment: {
375
- id: "server-embed",
376
- name: normalized(String(raw.agent_name || ""), "agent_name"),
377
- version_policy: agentVersionId ? { mode: "pinned", version_id: agentVersionId } : { mode: "latest_published" },
378
- resolved_agent_version_id: resolvedVersionId,
379
- resolved_agent_version_number: Number.isFinite(versionNumber) ? versionNumber : 0,
380
- policy_epoch: 0
381
- },
382
- authentication: { modes: ["server_embed"], access_token_lifetime_seconds: 0, jwks_path: "" },
383
- capabilities: ["attachments.read", "attachments.write", "feedback.write", ...selectable ? ["models.select"] : []],
384
- features,
385
- native_profiles: []
386
- };
387
- }
388
390
  function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity) {
389
391
  const agentId = normalized(options.agentId, "agentId");
390
392
  const agentVersionId = stringValue(options.agentVersionId);
@@ -450,21 +452,32 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
450
452
  if (attachmentIds.length > MAX_ATTACHMENTS) {
451
453
  throw new BffInputError(400, "TOO_MANY_ATTACHMENTS", `At most ${MAX_ATTACHMENTS} attachments are allowed.`);
452
454
  }
455
+ const admission = await embed.startAgentRun(agentId, {
456
+ ...identity,
457
+ integration_id: integrationId,
458
+ ...agentVersionId ? { agent_version_id: agentVersionId } : {},
459
+ runtime_target: runtimeTarget,
460
+ ...input ? { input } : {},
461
+ attachment_ids: attachmentIds,
462
+ ...stringValue(body.threadId) ? { thread_id: stringValue(body.threadId) } : {},
463
+ ...stringValue(body.requestedModelId) ? { requested_model_id: stringValue(body.requestedModelId) } : {},
464
+ tool_inputs: objectValue(body.toolInputs),
465
+ metadata: objectValue(body.metadata),
466
+ client: objectValue(body.client)
467
+ }, { idempotencyKey });
453
468
  response = sseResponse(async (write) => {
454
- await embed.streamAgent(agentId, {
469
+ await embed.attachAgentRun(agentId, admission.run_id, {
455
470
  ...identity,
456
471
  integration_id: integrationId,
457
- ...agentVersionId ? { agent_version_id: agentVersionId } : {},
458
472
  runtime_target: runtimeTarget,
459
- ...input ? { input } : {},
460
- attachment_ids: attachmentIds,
461
- ...stringValue(body.threadId) ? { thread_id: stringValue(body.threadId) } : {},
462
- ...stringValue(body.requestedModelId) ? { requested_model_id: stringValue(body.requestedModelId) } : {},
463
- tool_inputs: objectValue(body.toolInputs),
464
473
  metadata: objectValue(body.metadata),
465
- client: objectValue(body.client)
466
- }, (event) => write(event), { idempotencyKey, signal: request.signal });
467
- }, void 0, void 0, streamFailure(request, "chat.stream"));
474
+ client: objectValue(body.client),
475
+ cursor: 0
476
+ }, (event) => write(event), { signal: request.signal });
477
+ }, {
478
+ "X-Run-ID": admission.run_id,
479
+ ...admission.thread_id ? { "X-Thread-ID": admission.thread_id } : {}
480
+ }, void 0, streamFailure(request, "chat.stream"));
468
481
  } else if (request.method === "POST" && /^\/runs\/[^/]+\/attach$/.test(path)) {
469
482
  const runId = routeId(path, /^\/runs\/([^/]+)\/attach$/, "runId");
470
483
  const body = await requestJson(request);
@@ -787,21 +800,32 @@ function createResolvedAgents24BffHandler(options) {
787
800
  if (!input && attachmentIds.length === 0) throw new BffInputError(400, "INPUT_REQUIRED", "A message or attachment is required.");
788
801
  if (input && input.length > MAX_INPUT_LENGTH) throw new BffInputError(413, "INPUT_TOO_LARGE", "The message is too large.");
789
802
  if (attachmentIds.length > MAX_ATTACHMENTS) throw new BffInputError(400, "TOO_MANY_ATTACHMENTS", `At most ${MAX_ATTACHMENTS} attachments are allowed.`);
803
+ const admission = await options.client.embed.startAgentRun(selected.agentId, {
804
+ ...identity,
805
+ ...selected.agentVersionId ? { agent_version_id: selected.agentVersionId } : {},
806
+ runtime_target: runtimeTarget,
807
+ integration_id: integrationId,
808
+ ...input ? { input } : {},
809
+ attachment_ids: attachmentIds,
810
+ ...stringValue(body.threadId) ? { thread_id: stringValue(body.threadId) } : {},
811
+ ...stringValue(body.requestedModelId) ? { requested_model_id: stringValue(body.requestedModelId) } : {},
812
+ tool_inputs: objectValue(body.toolInputs),
813
+ metadata: objectValue(body.metadata),
814
+ client: objectValue(body.client)
815
+ }, { idempotencyKey: stringValue(request.headers.get("idempotency-key")) });
790
816
  return mergeHeaders(sseResponse(async (write) => {
791
- await options.client.embed.streamAgent(selected.agentId, {
817
+ await options.client.embed.attachAgentRun(selected.agentId, admission.run_id, {
792
818
  ...identity,
793
- ...selected.agentVersionId ? { agent_version_id: selected.agentVersionId } : {},
794
819
  runtime_target: runtimeTarget,
795
820
  integration_id: integrationId,
796
- ...input ? { input } : {},
797
- attachment_ids: attachmentIds,
798
- ...stringValue(body.threadId) ? { thread_id: stringValue(body.threadId) } : {},
799
- ...stringValue(body.requestedModelId) ? { requested_model_id: stringValue(body.requestedModelId) } : {},
800
- tool_inputs: objectValue(body.toolInputs),
801
821
  metadata: objectValue(body.metadata),
802
- client: objectValue(body.client)
803
- }, (event) => write(event), { idempotencyKey: stringValue(request.headers.get("idempotency-key")), signal: request.signal });
804
- }, void 0, void 0, (error) => reportFailureResponse(options.onDiagnostic, request, "chat.stream", errorResponse(error))), resolution.responseHeaders);
822
+ client: objectValue(body.client),
823
+ cursor: 0
824
+ }, (event) => write(event), { signal: request.signal });
825
+ }, {
826
+ "X-Run-ID": admission.run_id,
827
+ ...admission.thread_id ? { "X-Thread-ID": admission.thread_id } : {}
828
+ }, void 0, (error) => reportFailureResponse(options.onDiagnostic, request, "chat.stream", errorResponse(error))), resolution.responseHeaders);
805
829
  }
806
830
  if (request.method === "GET" && path === "/threads") {
807
831
  const skip = Number(url.searchParams.get("skip") || 0);