@dudousxd/nestjs-agent-react 0.23.0 → 0.24.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/dist/index.cjs +47 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +47 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1340,6 +1340,8 @@ interface AgentMessageMetadata extends Partial<StoredTurnMetadata> {
|
|
|
1340
1340
|
costUsd?: number | null;
|
|
1341
1341
|
/** ISO timestamp: the stored row's `createdAt` (a merged turn: its first row's), or when a live turn started streaming. */
|
|
1342
1342
|
createdAt?: string;
|
|
1343
|
+
/** Host-defined keys: `StoredMessage.metadata` and the stream's `message-metadata` frames. */
|
|
1344
|
+
[key: string]: unknown;
|
|
1343
1345
|
}
|
|
1344
1346
|
/**
|
|
1345
1347
|
* Convert a thread's full `StoredMessage[]` history into `UIMessage[]`, merging consecutive
|
|
@@ -1505,6 +1507,8 @@ interface ChatModels {
|
|
|
1505
1507
|
readonly providers: ModelsState['providers'];
|
|
1506
1508
|
/** What the next turn runs on: the `model` option, the pick, the thread's pin, else the default. */
|
|
1507
1509
|
selected: string | null;
|
|
1510
|
+
/** The catalog's default — what a turn runs on when nothing is picked or pinned (`null` until loaded). */
|
|
1511
|
+
readonly defaultModel: string | null;
|
|
1508
1512
|
/** Run the following turns on `id` (sent as the body's `model`). */
|
|
1509
1513
|
select: (id: string) => void;
|
|
1510
1514
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1340,6 +1340,8 @@ interface AgentMessageMetadata extends Partial<StoredTurnMetadata> {
|
|
|
1340
1340
|
costUsd?: number | null;
|
|
1341
1341
|
/** ISO timestamp: the stored row's `createdAt` (a merged turn: its first row's), or when a live turn started streaming. */
|
|
1342
1342
|
createdAt?: string;
|
|
1343
|
+
/** Host-defined keys: `StoredMessage.metadata` and the stream's `message-metadata` frames. */
|
|
1344
|
+
[key: string]: unknown;
|
|
1343
1345
|
}
|
|
1344
1346
|
/**
|
|
1345
1347
|
* Convert a thread's full `StoredMessage[]` history into `UIMessage[]`, merging consecutive
|
|
@@ -1505,6 +1507,8 @@ interface ChatModels {
|
|
|
1505
1507
|
readonly providers: ModelsState['providers'];
|
|
1506
1508
|
/** What the next turn runs on: the `model` option, the pick, the thread's pin, else the default. */
|
|
1507
1509
|
selected: string | null;
|
|
1510
|
+
/** The catalog's default — what a turn runs on when nothing is picked or pinned (`null` until loaded). */
|
|
1511
|
+
readonly defaultModel: string | null;
|
|
1508
1512
|
/** Run the following turns on `id` (sent as the body's `model`). */
|
|
1509
1513
|
select: (id: string) => void;
|
|
1510
1514
|
/**
|
package/dist/index.js
CHANGED
|
@@ -864,6 +864,13 @@ var AgentChatTransport = class {
|
|
|
864
864
|
}
|
|
865
865
|
});
|
|
866
866
|
break;
|
|
867
|
+
case "message-metadata":
|
|
868
|
+
ensureStarted();
|
|
869
|
+
controller.enqueue({
|
|
870
|
+
type: "message-metadata",
|
|
871
|
+
messageMetadata: event.metadata
|
|
872
|
+
});
|
|
873
|
+
break;
|
|
867
874
|
case "title":
|
|
868
875
|
case "cancelled":
|
|
869
876
|
forwardAsData(event, true);
|
|
@@ -5018,13 +5025,19 @@ function storedMessageToUiMessage(message) {
|
|
|
5018
5025
|
for (const call of message.toolCalls ?? []) {
|
|
5019
5026
|
const result = message.toolResults?.find((candidate) => candidate.id === call.id);
|
|
5020
5027
|
const toolKind2 = call.kind;
|
|
5028
|
+
const toolMetadata = {
|
|
5029
|
+
...toolKind2 !== void 0 ? {
|
|
5030
|
+
toolKind: toolKind2
|
|
5031
|
+
} : {},
|
|
5032
|
+
...call.parentId !== void 0 ? {
|
|
5033
|
+
parentId: call.parentId
|
|
5034
|
+
} : {}
|
|
5035
|
+
};
|
|
5021
5036
|
parts.push({
|
|
5022
5037
|
type: `tool-${call.name}`,
|
|
5023
5038
|
toolCallId: call.id,
|
|
5024
|
-
...
|
|
5025
|
-
toolMetadata
|
|
5026
|
-
toolKind: toolKind2
|
|
5027
|
-
}
|
|
5039
|
+
...Object.keys(toolMetadata).length > 0 ? {
|
|
5040
|
+
toolMetadata
|
|
5028
5041
|
} : {},
|
|
5029
5042
|
...result !== void 0 ? isRefusal(result) ? {
|
|
5030
5043
|
// A declined action is NOT an available output. Reloading a thread used to bring one
|
|
@@ -5052,6 +5065,8 @@ function storedMessageToUiMessage(message) {
|
|
|
5052
5065
|
parts.push(...pushedByCall.get(call.id) ?? []);
|
|
5053
5066
|
}
|
|
5054
5067
|
const metadata = {
|
|
5068
|
+
// The host's own facts first: the library's keys win on a clash.
|
|
5069
|
+
...message.metadata,
|
|
5055
5070
|
...message.feedback !== void 0 ? {
|
|
5056
5071
|
feedback: message.feedback
|
|
5057
5072
|
} : {},
|
|
@@ -5111,6 +5126,8 @@ function mergeTurn(rows) {
|
|
|
5111
5126
|
const feedback = lastRow.feedback;
|
|
5112
5127
|
const createdAt = rows[0]?.createdAt;
|
|
5113
5128
|
const metadata = {
|
|
5129
|
+
// Host facts of every row, a later row's winning (the turn's final state), under the library's.
|
|
5130
|
+
...Object.assign({}, ...rows.map((row) => row.metadata ?? {})),
|
|
5114
5131
|
...usage !== void 0 ? {
|
|
5115
5132
|
usage
|
|
5116
5133
|
} : {},
|
|
@@ -5232,6 +5249,11 @@ function useAgentChat(options = {}) {
|
|
|
5232
5249
|
const threadId = currentThreadId();
|
|
5233
5250
|
const model = current.model ?? pickedModelRef.current;
|
|
5234
5251
|
return {
|
|
5252
|
+
// Read per send: a host that switches agents before the first message (a picker on a
|
|
5253
|
+
// new chat) sends the one picked now, not the one this chat mounted with.
|
|
5254
|
+
...current.agent !== void 0 ? {
|
|
5255
|
+
agent: current.agent
|
|
5256
|
+
} : {},
|
|
5235
5257
|
...threadId !== void 0 ? {
|
|
5236
5258
|
threadId
|
|
5237
5259
|
} : {},
|
|
@@ -5605,6 +5627,10 @@ function useAgentChat(options = {}) {
|
|
|
5605
5627
|
return catalog.providers;
|
|
5606
5628
|
},
|
|
5607
5629
|
selected: options.model ?? pickedModel ?? threadModel ?? catalog.defaultModel ?? null,
|
|
5630
|
+
get defaultModel() {
|
|
5631
|
+
wantModels();
|
|
5632
|
+
return catalog.defaultModel;
|
|
5633
|
+
},
|
|
5608
5634
|
select: selectModel,
|
|
5609
5635
|
pinToThread,
|
|
5610
5636
|
isLoading: modelsWanted && catalog.isLoading,
|
|
@@ -5632,10 +5658,26 @@ function useAgentChat(options = {}) {
|
|
|
5632
5658
|
const current = composerRef.current;
|
|
5633
5659
|
if (current.blockedBy !== null) return;
|
|
5634
5660
|
const refs = current.files.refs;
|
|
5661
|
+
const files2 = current.files.items.flatMap((item) => item.status === "ready" && item.attachment !== void 0 ? [
|
|
5662
|
+
{
|
|
5663
|
+
type: "file",
|
|
5664
|
+
mediaType: item.attachment.contentType,
|
|
5665
|
+
filename: item.attachment.name,
|
|
5666
|
+
url: item.attachment.url,
|
|
5667
|
+
providerMetadata: {
|
|
5668
|
+
agent: {
|
|
5669
|
+
mediaId: item.attachment.mediaId
|
|
5670
|
+
}
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5673
|
+
] : []);
|
|
5635
5674
|
const draft = current.text.trim();
|
|
5636
5675
|
setText("");
|
|
5637
5676
|
current.files.clear();
|
|
5638
|
-
await sendMessage({
|
|
5677
|
+
await sendMessage(files2.length > 0 ? {
|
|
5678
|
+
text: draft,
|
|
5679
|
+
files: files2
|
|
5680
|
+
} : {
|
|
5639
5681
|
text: draft
|
|
5640
5682
|
}, refs.length > 0 ? {
|
|
5641
5683
|
body: {
|