@dudousxd/nestjs-agent-core 0.39.0 → 0.41.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/README.md +7 -0
- package/dist/ag-ui/index.cjs +123 -9
- package/dist/ag-ui/index.cjs.map +1 -1
- package/dist/ag-ui/index.d.cts +19 -3
- package/dist/ag-ui/index.d.ts +19 -3
- package/dist/ag-ui/index.js +122 -9
- package/dist/ag-ui/index.js.map +1 -1
- package/dist/{catalog-CrzetM3_.d.cts → catalog-BKS3Yxo6.d.cts} +2 -0
- package/dist/{catalog-CrzetM3_.d.ts → catalog-BKS3Yxo6.d.ts} +2 -0
- package/dist/genui/builtins.cjs +2 -0
- package/dist/genui/builtins.cjs.map +1 -1
- package/dist/genui/builtins.d.cts +1 -1
- package/dist/genui/builtins.d.ts +1 -1
- package/dist/genui/builtins.js +2 -0
- package/dist/genui/builtins.js.map +1 -1
- package/dist/genui/index.cjs +780 -106
- package/dist/genui/index.cjs.map +1 -1
- package/dist/genui/index.d.cts +5 -5
- package/dist/genui/index.d.ts +5 -5
- package/dist/genui/index.js +770 -105
- package/dist/genui/index.js.map +1 -1
- package/dist/guardrails/index.cjs +3 -1
- package/dist/guardrails/index.cjs.map +1 -1
- package/dist/guardrails/index.d.cts +5 -4
- package/dist/guardrails/index.d.ts +5 -4
- package/dist/guardrails/index.js +3 -1
- package/dist/guardrails/index.js.map +1 -1
- package/dist/index.cjs +3324 -380
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +388 -96
- package/dist/index.d.ts +388 -96
- package/dist/index.js +3279 -377
- package/dist/index.js.map +1 -1
- package/dist/{processors-6p9nrqEi.d.cts → processors-BXM-MNga.d.cts} +1 -1
- package/dist/{processors-Bp5XmF6V.d.ts → processors-ByDr5POu.d.ts} +1 -1
- package/dist/{stream-events-CbVEowYb.d.cts → stream-events-BGKLD6RX.d.ts} +664 -86
- package/dist/{stream-events-CbVEowYb.d.ts → stream-events-CF-6-Y6L.d.cts} +664 -86
- package/package.json +1 -1
- package/dist/tool-DZYLEKnl.d.cts +0 -121
- package/dist/tool-_iq4xRyk.d.ts +0 -121
package/dist/ag-ui/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { A as AgentStreamEvent } from '../stream-events-
|
|
1
|
+
import { A as AgentStreamEvent, U as UiCapabilities } from '../stream-events-BGKLD6RX.js';
|
|
2
2
|
import '@standard-schema/spec';
|
|
3
|
+
import '../catalog-BKS3Yxo6.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The slice of AG-UI 1.0 (https://docs.ag-ui.com/spec/1.0) this producer writes and reads. Typed by
|
|
@@ -198,6 +199,8 @@ declare const AG_UI_CUSTOM: {
|
|
|
198
199
|
readonly elicitation: "agora.elicitation";
|
|
199
200
|
/** `{ usage, costUsd, reasoningMs }` of one model step. */
|
|
200
201
|
readonly stepUsage: "agora.step-usage";
|
|
202
|
+
/** A proposal decided by a text message or an interrupt resume, with no model run behind it. */
|
|
203
|
+
readonly actionProposalDecision: "agora.action-proposal-decision";
|
|
201
204
|
/** `{ message }` — input material this producer could not use and dropped. */
|
|
202
205
|
readonly warning: "agora.warning";
|
|
203
206
|
};
|
|
@@ -360,7 +363,8 @@ declare class AgUiEncoder {
|
|
|
360
363
|
* the native approve/answer routes do.
|
|
361
364
|
*/
|
|
362
365
|
interface InterruptAddress {
|
|
363
|
-
|
|
366
|
+
/** `proposal` — an independent proposal's approval, decided through the proposal service. */
|
|
367
|
+
kind: 'approval' | 'elicitation' | 'proposal';
|
|
364
368
|
/** The run to settle the call on. */
|
|
365
369
|
parked: string;
|
|
366
370
|
/** The run whose buffered stream the resume re-attaches to. */
|
|
@@ -368,6 +372,9 @@ interface InterruptAddress {
|
|
|
368
372
|
toolCallId: string;
|
|
369
373
|
/** Frames of `stream` already delivered when the run was reported interrupted. */
|
|
370
374
|
position: number;
|
|
375
|
+
/** `proposal` only: the proposal and the library thread it belongs to. */
|
|
376
|
+
proposalId?: string;
|
|
377
|
+
threadId?: string;
|
|
371
378
|
}
|
|
372
379
|
declare function encodeInterruptId(address: InterruptAddress): string;
|
|
373
380
|
/** The address an id names, or `null` for an id this producer did not mint. */
|
|
@@ -412,6 +419,7 @@ declare function readContext(context: readonly AgUiContext[] | undefined): AgUiC
|
|
|
412
419
|
* model: which agent, which model, which persona, and the page context the tools see.
|
|
413
420
|
*/
|
|
414
421
|
interface ForwardedOptions {
|
|
422
|
+
uiCapabilities?: UiCapabilities;
|
|
415
423
|
agent?: string;
|
|
416
424
|
model?: string;
|
|
417
425
|
persona?: string;
|
|
@@ -476,4 +484,12 @@ declare function agUiSse(event: AgUiEvent): string;
|
|
|
476
484
|
*/
|
|
477
485
|
declare function agUiFramesFromNdjson(chunks: AsyncIterable<Uint8Array>): AsyncGenerator<AgUiSourceFrame>;
|
|
478
486
|
|
|
479
|
-
|
|
487
|
+
/** A decision-only protocol invocation: no model run, stream holder or tool execution is created. */
|
|
488
|
+
declare function actionProposalDecisionEvents(input: {
|
|
489
|
+
threadId: string;
|
|
490
|
+
runId: string;
|
|
491
|
+
text: string;
|
|
492
|
+
proposalDecision: unknown;
|
|
493
|
+
}): AgUiEvent[];
|
|
494
|
+
|
|
495
|
+
export { AG_UI_CUSTOM, AG_UI_PROTOCOL_VERSION, type AgUiContentPart, type AgUiContext, AgUiEncoder, type AgUiEncoderOptions, type AgUiEvent, type AgUiInterrupt, type AgUiMessage, type AgUiMetadata, type AgUiPartSource, type AgUiResumeEntry, type AgUiRunInput, type AgUiRunOutcome, type AgUiSourceFrame, type AgUiStreamOptions, type AgUiTokenUsage, type ForwardedOptions, type InlineMedia, type InterruptAddress, type ResumeDecision, type ResumePlan, type UserTurn, actionProposalDecisionEvents, agUiEvents, agUiFramesFromNdjson, agUiSse, decodeInterruptId, encodeInterruptId, parseRunInput, planResume, readAnswersPayload, readApprovalPayload, readContext, readForwardedProps, readUserTurn };
|
package/dist/ag-ui/index.js
CHANGED
|
@@ -2,15 +2,21 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/ag-ui/interrupt-id.ts
|
|
5
|
+
var KIND_CODES = {
|
|
6
|
+
approval: "a",
|
|
7
|
+
elicitation: "e",
|
|
8
|
+
proposal: "p"
|
|
9
|
+
};
|
|
5
10
|
var PREFIX = "agora_";
|
|
6
11
|
function encodeInterruptId(address) {
|
|
7
12
|
const compact = [
|
|
8
|
-
address.kind
|
|
13
|
+
KIND_CODES[address.kind],
|
|
9
14
|
address.parked,
|
|
10
15
|
address.stream,
|
|
11
16
|
address.toolCallId,
|
|
12
17
|
address.position
|
|
13
18
|
];
|
|
19
|
+
if (address.kind === "proposal") compact.push(address.proposalId, address.threadId);
|
|
14
20
|
return PREFIX + Buffer.from(JSON.stringify(compact), "utf8").toString("base64url");
|
|
15
21
|
}
|
|
16
22
|
__name(encodeInterruptId, "encodeInterruptId");
|
|
@@ -18,17 +24,21 @@ function decodeInterruptId(id) {
|
|
|
18
24
|
if (typeof id !== "string" || !id.startsWith(PREFIX)) return null;
|
|
19
25
|
try {
|
|
20
26
|
const parsed = JSON.parse(Buffer.from(id.slice(PREFIX.length), "base64url").toString("utf8"));
|
|
21
|
-
if (!Array.isArray(parsed)
|
|
22
|
-
const [kind, parked, stream, toolCallId, position] = parsed;
|
|
23
|
-
if (kind !== "a" && kind !== "e" || typeof parked !== "string" || typeof stream !== "string" || typeof toolCallId !== "string" || typeof position !== "number" || !Number.isSafeInteger(position) || position < 0) {
|
|
27
|
+
if (!Array.isArray(parsed)) return null;
|
|
28
|
+
const [kind, parked, stream, toolCallId, position, proposalId, threadId] = parsed;
|
|
29
|
+
if (parsed.length !== (kind === "p" ? 7 : 5) || kind === "p" && (typeof proposalId !== "string" || typeof threadId !== "string") || kind !== "a" && kind !== "e" && kind !== "p" || typeof parked !== "string" || typeof stream !== "string" || typeof toolCallId !== "string" || typeof position !== "number" || !Number.isSafeInteger(position) || position < 0) {
|
|
24
30
|
return null;
|
|
25
31
|
}
|
|
26
32
|
return {
|
|
27
|
-
kind: kind === "a" ? "approval" : "elicitation",
|
|
33
|
+
kind: kind === "a" ? "approval" : kind === "e" ? "elicitation" : "proposal",
|
|
28
34
|
parked,
|
|
29
35
|
stream,
|
|
30
36
|
toolCallId,
|
|
31
|
-
position
|
|
37
|
+
position,
|
|
38
|
+
...kind === "p" ? {
|
|
39
|
+
proposalId,
|
|
40
|
+
threadId
|
|
41
|
+
} : {}
|
|
32
42
|
};
|
|
33
43
|
} catch {
|
|
34
44
|
return null;
|
|
@@ -52,6 +62,8 @@ var AG_UI_CUSTOM = {
|
|
|
52
62
|
elicitation: "agora.elicitation",
|
|
53
63
|
/** `{ usage, costUsd, reasoningMs }` of one model step. */
|
|
54
64
|
stepUsage: "agora.step-usage",
|
|
65
|
+
/** A proposal decided by a text message or an interrupt resume, with no model run behind it. */
|
|
66
|
+
actionProposalDecision: "agora.action-proposal-decision",
|
|
55
67
|
/** `{ message }` — input material this producer could not use and dropped. */
|
|
56
68
|
warning: "agora.warning"
|
|
57
69
|
};
|
|
@@ -239,6 +251,13 @@ var AgUiEncoder = class {
|
|
|
239
251
|
...event.version !== void 0 ? {
|
|
240
252
|
version: event.version
|
|
241
253
|
} : {},
|
|
254
|
+
// What a client that cannot draw the component shows instead.
|
|
255
|
+
...event.fallbackText !== void 0 ? {
|
|
256
|
+
fallbackText: event.fallbackText
|
|
257
|
+
} : {},
|
|
258
|
+
...event.componentVersions !== void 0 ? {
|
|
259
|
+
componentVersions: event.componentVersions
|
|
260
|
+
} : {},
|
|
242
261
|
...event.toolCallId !== void 0 ? {
|
|
243
262
|
toolCallId: event.toolCallId
|
|
244
263
|
} : {}
|
|
@@ -249,10 +268,14 @@ var AgUiEncoder = class {
|
|
|
249
268
|
const parked = event.runId ?? this.options.streamRunId;
|
|
250
269
|
const toolName = event.toolName ?? call?.name ?? "";
|
|
251
270
|
const input = event.input ?? call?.input ?? null;
|
|
271
|
+
const proposal = event.target?.kind === "proposal" ? event.target : void 0;
|
|
252
272
|
this.pending.set(event.id, {
|
|
253
|
-
kind: "approval",
|
|
273
|
+
kind: proposal !== void 0 ? "proposal" : "approval",
|
|
254
274
|
parked,
|
|
255
275
|
toolCallId: event.id,
|
|
276
|
+
...proposal !== void 0 ? {
|
|
277
|
+
proposalId: proposal.proposalId
|
|
278
|
+
} : {},
|
|
256
279
|
interrupt: {
|
|
257
280
|
reason: "tool_approval",
|
|
258
281
|
message: event.reason ?? (toolName.length > 0 ? `Approve ${toolName}?` : "Approve?"),
|
|
@@ -264,7 +287,10 @@ var AgUiEncoder = class {
|
|
|
264
287
|
metadata: {
|
|
265
288
|
"agora.toolName": toolName,
|
|
266
289
|
"agora.input": input,
|
|
267
|
-
"agora.approver": event.approver
|
|
290
|
+
"agora.approver": event.approver,
|
|
291
|
+
...event.target !== void 0 ? {
|
|
292
|
+
"agora.target": event.target
|
|
293
|
+
} : {}
|
|
268
294
|
}
|
|
269
295
|
}
|
|
270
296
|
});
|
|
@@ -275,6 +301,12 @@ var AgUiEncoder = class {
|
|
|
275
301
|
toolName,
|
|
276
302
|
input,
|
|
277
303
|
approver: event.approver,
|
|
304
|
+
...event.target !== void 0 ? {
|
|
305
|
+
target: event.target
|
|
306
|
+
} : {},
|
|
307
|
+
...event.confirmation !== void 0 ? {
|
|
308
|
+
confirmation: event.confirmation
|
|
309
|
+
} : {},
|
|
278
310
|
...event.expiresAt !== void 0 ? {
|
|
279
311
|
expiresAt: event.expiresAt
|
|
280
312
|
} : {},
|
|
@@ -502,7 +534,11 @@ var AgUiEncoder = class {
|
|
|
502
534
|
parked: entry.parked,
|
|
503
535
|
stream: this.options.streamRunId,
|
|
504
536
|
toolCallId: entry.toolCallId,
|
|
505
|
-
position: this.position
|
|
537
|
+
position: this.position,
|
|
538
|
+
...entry.proposalId !== void 0 ? {
|
|
539
|
+
proposalId: entry.proposalId,
|
|
540
|
+
threadId: this.options.streamThreadId ?? this.options.threadId
|
|
541
|
+
} : {}
|
|
506
542
|
}),
|
|
507
543
|
...entry.interrupt
|
|
508
544
|
}));
|
|
@@ -655,6 +691,31 @@ var AgUiEncoder = class {
|
|
|
655
691
|
}
|
|
656
692
|
};
|
|
657
693
|
|
|
694
|
+
// src/genui/catalog.ts
|
|
695
|
+
var COMPONENT_NAME = /^[A-Za-z][A-Za-z0-9]{0,63}$/;
|
|
696
|
+
|
|
697
|
+
// src/genui/capabilities.ts
|
|
698
|
+
function validateUiCapabilities(value) {
|
|
699
|
+
if (!record(value) || Object.keys(value).some((key) => key !== "components") || !Array.isArray(value.components)) throw new TypeError("Invalid UI capabilities");
|
|
700
|
+
const seen = /* @__PURE__ */ new Set();
|
|
701
|
+
const components = value.components.map((component) => {
|
|
702
|
+
if (!record(component) || Object.keys(component).some((key) => key !== "name" && key !== "version") || typeof component.name !== "string" || !COMPONENT_NAME.test(component.name) || !Number.isSafeInteger(component.version) || Number(component.version) <= 0 || seen.has(component.name)) throw new TypeError("Invalid UI component capability");
|
|
703
|
+
seen.add(component.name);
|
|
704
|
+
return {
|
|
705
|
+
name: component.name,
|
|
706
|
+
version: Number(component.version)
|
|
707
|
+
};
|
|
708
|
+
});
|
|
709
|
+
return {
|
|
710
|
+
components
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
__name(validateUiCapabilities, "validateUiCapabilities");
|
|
714
|
+
function record(value) {
|
|
715
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
716
|
+
}
|
|
717
|
+
__name(record, "record");
|
|
718
|
+
|
|
658
719
|
// src/ag-ui/input.ts
|
|
659
720
|
function isRecord(value) {
|
|
660
721
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -686,6 +747,13 @@ function parseRunInput(body) {
|
|
|
686
747
|
if (body.context !== void 0 && !Array.isArray(body.context)) {
|
|
687
748
|
return "context must be an array";
|
|
688
749
|
}
|
|
750
|
+
if (isRecord(body.forwardedProps) && Object.hasOwn(body.forwardedProps, "uiCapabilities")) {
|
|
751
|
+
try {
|
|
752
|
+
validateUiCapabilities(body.forwardedProps.uiCapabilities);
|
|
753
|
+
} catch {
|
|
754
|
+
return "forwardedProps.uiCapabilities must be valid UI capabilities";
|
|
755
|
+
}
|
|
756
|
+
}
|
|
689
757
|
return body;
|
|
690
758
|
}
|
|
691
759
|
__name(parseRunInput, "parseRunInput");
|
|
@@ -790,6 +858,9 @@ function readForwardedProps(forwarded) {
|
|
|
790
858
|
const model = pick("model");
|
|
791
859
|
const persona = pick("persona");
|
|
792
860
|
return {
|
|
861
|
+
...Object.hasOwn(forwarded, "uiCapabilities") ? {
|
|
862
|
+
uiCapabilities: validateUiCapabilities(forwarded.uiCapabilities)
|
|
863
|
+
} : {},
|
|
793
864
|
...agent !== void 0 ? {
|
|
794
865
|
agent
|
|
795
866
|
} : {},
|
|
@@ -1005,10 +1076,52 @@ async function* agUiFramesFromNdjson(chunks) {
|
|
|
1005
1076
|
}
|
|
1006
1077
|
}
|
|
1007
1078
|
__name(agUiFramesFromNdjson, "agUiFramesFromNdjson");
|
|
1079
|
+
|
|
1080
|
+
// src/ag-ui/proposal-decision.ts
|
|
1081
|
+
function actionProposalDecisionEvents(input) {
|
|
1082
|
+
const messageId = `${input.runId}:proposal-decision`;
|
|
1083
|
+
return [
|
|
1084
|
+
{
|
|
1085
|
+
type: "RUN_STARTED",
|
|
1086
|
+
threadId: input.threadId,
|
|
1087
|
+
runId: input.runId,
|
|
1088
|
+
protocolVersion: AG_UI_PROTOCOL_VERSION
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
type: "CUSTOM",
|
|
1092
|
+
name: AG_UI_CUSTOM.actionProposalDecision,
|
|
1093
|
+
value: {
|
|
1094
|
+
threadId: input.threadId,
|
|
1095
|
+
proposalDecision: input.proposalDecision
|
|
1096
|
+
}
|
|
1097
|
+
},
|
|
1098
|
+
{
|
|
1099
|
+
type: "TEXT_MESSAGE_START",
|
|
1100
|
+
messageId,
|
|
1101
|
+
role: "assistant"
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
type: "TEXT_MESSAGE_CONTENT",
|
|
1105
|
+
messageId,
|
|
1106
|
+
delta: input.text
|
|
1107
|
+
},
|
|
1108
|
+
{
|
|
1109
|
+
type: "TEXT_MESSAGE_END",
|
|
1110
|
+
messageId
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
type: "RUN_FINISHED",
|
|
1114
|
+
threadId: input.threadId,
|
|
1115
|
+
runId: input.runId
|
|
1116
|
+
}
|
|
1117
|
+
];
|
|
1118
|
+
}
|
|
1119
|
+
__name(actionProposalDecisionEvents, "actionProposalDecisionEvents");
|
|
1008
1120
|
export {
|
|
1009
1121
|
AG_UI_CUSTOM,
|
|
1010
1122
|
AG_UI_PROTOCOL_VERSION,
|
|
1011
1123
|
AgUiEncoder,
|
|
1124
|
+
actionProposalDecisionEvents,
|
|
1012
1125
|
agUiEvents,
|
|
1013
1126
|
agUiFramesFromNdjson,
|
|
1014
1127
|
agUiSse,
|