@dudousxd/nestjs-agent 1.23.0 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +35 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +35 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -539,7 +539,10 @@ declare class AgUiRunHandler {
|
|
|
539
539
|
protected readonly quietMs: number | undefined;
|
|
540
540
|
constructor(agent: AgentService, actorResolver: ActorResolver, options: AgentModuleOptions, staging: AttachmentStagingStore | undefined, quietMs: number | undefined);
|
|
541
541
|
handle(req: Request, res: Response, body: unknown): Promise<void>;
|
|
542
|
-
/**
|
|
542
|
+
/**
|
|
543
|
+
* The turn's attachments: the ones already staged (by mediaId), then its inline media staged
|
|
544
|
+
* through the bound store — all within the store's limits; say what was not used.
|
|
545
|
+
*/
|
|
543
546
|
private stage;
|
|
544
547
|
/**
|
|
545
548
|
* Deliver what a resume list decided, through the same calls the native decision routes make.
|
package/dist/index.d.ts
CHANGED
|
@@ -539,7 +539,10 @@ declare class AgUiRunHandler {
|
|
|
539
539
|
protected readonly quietMs: number | undefined;
|
|
540
540
|
constructor(agent: AgentService, actorResolver: ActorResolver, options: AgentModuleOptions, staging: AttachmentStagingStore | undefined, quietMs: number | undefined);
|
|
541
541
|
handle(req: Request, res: Response, body: unknown): Promise<void>;
|
|
542
|
-
/**
|
|
542
|
+
/**
|
|
543
|
+
* The turn's attachments: the ones already staged (by mediaId), then its inline media staged
|
|
544
|
+
* through the bound store — all within the store's limits; say what was not used.
|
|
545
|
+
*/
|
|
543
546
|
private stage;
|
|
544
547
|
/**
|
|
545
548
|
* Deliver what a resume list decided, through the same calls the native decision routes make.
|
package/dist/index.js
CHANGED
|
@@ -6369,7 +6369,10 @@ var AgUiRunHandler = class {
|
|
|
6369
6369
|
if (owner !== null && owner !== actor.id) {
|
|
6370
6370
|
throw new ForbiddenException4("thread belongs to another actor");
|
|
6371
6371
|
}
|
|
6372
|
-
if (
|
|
6372
|
+
if (forwarded.regenerate === true && owner === null) {
|
|
6373
|
+
throw invalid("invalid_input", "regenerate needs a thread that already has an exchange");
|
|
6374
|
+
}
|
|
6375
|
+
if (owner !== null && forwarded.regenerate !== true && turn.media.length === 0 && turn.staged.length === 0) {
|
|
6373
6376
|
const decision = await this.agent.handleTextDecision(input.threadId, actor, turn.text);
|
|
6374
6377
|
if ("proposalDecision" in decision) {
|
|
6375
6378
|
this.writeEvents(res, [
|
|
@@ -6384,7 +6387,7 @@ var AgUiRunHandler = class {
|
|
|
6384
6387
|
return;
|
|
6385
6388
|
}
|
|
6386
6389
|
}
|
|
6387
|
-
const refs = await this.stage(actor, turn.media, warnings);
|
|
6390
|
+
const refs = await this.stage(actor, turn.media, warnings, turn.staged);
|
|
6388
6391
|
if (turn.text.trim().length === 0 && refs.length === 0) {
|
|
6389
6392
|
throw invalid("no_user_message", "the user message to answer is empty");
|
|
6390
6393
|
}
|
|
@@ -6420,6 +6423,9 @@ var AgUiRunHandler = class {
|
|
|
6420
6423
|
} : {},
|
|
6421
6424
|
...refs.length > 0 ? {
|
|
6422
6425
|
attachments: refs
|
|
6426
|
+
} : {},
|
|
6427
|
+
...forwarded.regenerate === true ? {
|
|
6428
|
+
regenerate: true
|
|
6423
6429
|
} : {}
|
|
6424
6430
|
});
|
|
6425
6431
|
await this.pipe(res, started.runId, {
|
|
@@ -6431,10 +6437,25 @@ var AgUiRunHandler = class {
|
|
|
6431
6437
|
preamble: warningEvents(warnings)
|
|
6432
6438
|
});
|
|
6433
6439
|
}
|
|
6434
|
-
/**
|
|
6435
|
-
|
|
6440
|
+
/**
|
|
6441
|
+
* The turn's attachments: the ones already staged (by mediaId), then its inline media staged
|
|
6442
|
+
* through the bound store — all within the store's limits; say what was not used.
|
|
6443
|
+
*/
|
|
6444
|
+
async stage(actor, media, warnings, staged = []) {
|
|
6436
6445
|
const refs = [];
|
|
6437
6446
|
const limits = attachmentLimits(this.options, this.staging);
|
|
6447
|
+
for (const ref of staged) {
|
|
6448
|
+
const label = `The attachment ${ref.mediaId} was not used`;
|
|
6449
|
+
if (this.staging === void 0) {
|
|
6450
|
+
warnings.push(`${label}: attachments are not enabled on this agent.`);
|
|
6451
|
+
} else if (refs.length >= limits.maxPerMessage) {
|
|
6452
|
+
warnings.push(`${label}: a message carries at most ${limits.maxPerMessage} attachments.`);
|
|
6453
|
+
} else {
|
|
6454
|
+
refs.push({
|
|
6455
|
+
mediaId: ref.mediaId
|
|
6456
|
+
});
|
|
6457
|
+
}
|
|
6458
|
+
}
|
|
6438
6459
|
for (const item of media) {
|
|
6439
6460
|
const label = `The ${item.kind} "${item.filename}" was not used`;
|
|
6440
6461
|
if (this.staging === void 0) {
|
|
@@ -6447,7 +6468,7 @@ var AgUiRunHandler = class {
|
|
|
6447
6468
|
warnings.push(`${label}: it is larger than ${limits.maxBytes} bytes.`);
|
|
6448
6469
|
} else {
|
|
6449
6470
|
try {
|
|
6450
|
-
const
|
|
6471
|
+
const staged2 = await this.staging.stage({
|
|
6451
6472
|
data: item.data,
|
|
6452
6473
|
filename: item.filename,
|
|
6453
6474
|
contentType: item.contentType,
|
|
@@ -6455,7 +6476,7 @@ var AgUiRunHandler = class {
|
|
|
6455
6476
|
actor
|
|
6456
6477
|
});
|
|
6457
6478
|
refs.push({
|
|
6458
|
-
mediaId:
|
|
6479
|
+
mediaId: staged2.mediaId
|
|
6459
6480
|
});
|
|
6460
6481
|
} catch {
|
|
6461
6482
|
warnings.push(`${label}: it could not be stored.`);
|
|
@@ -6573,11 +6594,17 @@ var AgUiRunHandler = class {
|
|
|
6573
6594
|
res.setHeader("X-Agent-Run-Id", runId);
|
|
6574
6595
|
res.flushHeaders();
|
|
6575
6596
|
let terminal = false;
|
|
6597
|
+
const cursor = {
|
|
6598
|
+
seq: 0
|
|
6599
|
+
};
|
|
6576
6600
|
try {
|
|
6577
6601
|
const frames = agUiFramesFromNdjson(this.agent.subscribe(runId));
|
|
6578
|
-
for await (const event of agUiEvents(frames,
|
|
6602
|
+
for await (const event of agUiEvents(frames, {
|
|
6603
|
+
...options,
|
|
6604
|
+
cursor
|
|
6605
|
+
})) {
|
|
6579
6606
|
if (event.type === "RUN_FINISHED" || event.type === "RUN_ERROR") terminal = true;
|
|
6580
|
-
res.write(agUiSse(event));
|
|
6607
|
+
res.write(agUiSse(event, cursor.seq));
|
|
6581
6608
|
}
|
|
6582
6609
|
} catch {
|
|
6583
6610
|
if (!terminal) {
|