@dudousxd/nestjs-agent-core 0.45.0 → 0.45.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 +121 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +119 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -256,6 +256,8 @@ __export(src_exports, {
|
|
|
256
256
|
toActionProposalView: () => toActionProposalView,
|
|
257
257
|
toolCallApprovalFromRow: () => toolCallApprovalFromRow,
|
|
258
258
|
toolCallContext: () => toolCallContext,
|
|
259
|
+
toolCallUpdateForProposal: () => toolCallUpdateForProposal,
|
|
260
|
+
toolCallUpdateForTransition: () => toolCallUpdateForTransition,
|
|
259
261
|
traceLlmTurn: () => traceLlmTurn,
|
|
260
262
|
traceToolExecution: () => traceToolExecution,
|
|
261
263
|
transitionActionProposalClaim: () => transitionActionProposalClaim,
|
|
@@ -8096,6 +8098,98 @@ ${toolText}`;
|
|
|
8096
8098
|
}
|
|
8097
8099
|
__name(runAgentLoop, "runAgentLoop");
|
|
8098
8100
|
|
|
8101
|
+
// src/action-proposal-tool-call.ts
|
|
8102
|
+
function toolCallUpdateForProposal(proposal) {
|
|
8103
|
+
const audit = proposal.decisionAudit;
|
|
8104
|
+
const toolCallId = proposal.originToolCallId;
|
|
8105
|
+
const decidedBy = {
|
|
8106
|
+
...audit?.actorRef !== void 0 ? {
|
|
8107
|
+
executedByRef: audit.actorRef
|
|
8108
|
+
} : {},
|
|
8109
|
+
...audit?.via !== void 0 ? {
|
|
8110
|
+
decidedVia: audit.via
|
|
8111
|
+
} : {}
|
|
8112
|
+
};
|
|
8113
|
+
switch (proposal.decision) {
|
|
8114
|
+
case "rejected":
|
|
8115
|
+
return {
|
|
8116
|
+
toolCallId,
|
|
8117
|
+
status: "rejected",
|
|
8118
|
+
...decidedBy,
|
|
8119
|
+
...audit?.reason !== void 0 ? {
|
|
8120
|
+
error: storableText2(audit.reason)
|
|
8121
|
+
} : {}
|
|
8122
|
+
};
|
|
8123
|
+
case "expired":
|
|
8124
|
+
return {
|
|
8125
|
+
toolCallId,
|
|
8126
|
+
status: "expired",
|
|
8127
|
+
...audit?.via !== void 0 ? {
|
|
8128
|
+
decidedVia: audit.via
|
|
8129
|
+
} : {}
|
|
8130
|
+
};
|
|
8131
|
+
case "superseded":
|
|
8132
|
+
return {
|
|
8133
|
+
toolCallId,
|
|
8134
|
+
status: "expired",
|
|
8135
|
+
decidedVia: audit?.via ?? "supersession",
|
|
8136
|
+
error: proposal.supersededBy !== void 0 ? `superseded by proposal ${proposal.supersededBy}` : "superseded by a newer proposal"
|
|
8137
|
+
};
|
|
8138
|
+
case "approved": {
|
|
8139
|
+
const execution = proposal.execution;
|
|
8140
|
+
const remember = audit?.remember !== void 0 ? {
|
|
8141
|
+
remember: audit.remember
|
|
8142
|
+
} : {};
|
|
8143
|
+
if (execution?.status === "succeeded") {
|
|
8144
|
+
return {
|
|
8145
|
+
toolCallId,
|
|
8146
|
+
status: "executed",
|
|
8147
|
+
...storableOutput(execution.result) ? {
|
|
8148
|
+
output: execution.result
|
|
8149
|
+
} : {},
|
|
8150
|
+
...decidedBy,
|
|
8151
|
+
...remember
|
|
8152
|
+
};
|
|
8153
|
+
}
|
|
8154
|
+
if (execution?.status === "failed") {
|
|
8155
|
+
return {
|
|
8156
|
+
toolCallId,
|
|
8157
|
+
status: "failed",
|
|
8158
|
+
error: storableText2(execution.error ?? "the approved action failed"),
|
|
8159
|
+
...decidedBy,
|
|
8160
|
+
...remember
|
|
8161
|
+
};
|
|
8162
|
+
}
|
|
8163
|
+
return null;
|
|
8164
|
+
}
|
|
8165
|
+
default:
|
|
8166
|
+
return null;
|
|
8167
|
+
}
|
|
8168
|
+
}
|
|
8169
|
+
__name(toolCallUpdateForProposal, "toolCallUpdateForProposal");
|
|
8170
|
+
function toolCallUpdateForTransition(previous, next) {
|
|
8171
|
+
const update = toolCallUpdateForProposal(next);
|
|
8172
|
+
if (update === null) return null;
|
|
8173
|
+
const before = previous === void 0 ? null : toolCallUpdateForProposal(previous);
|
|
8174
|
+
return before?.status === update.status ? null : update;
|
|
8175
|
+
}
|
|
8176
|
+
__name(toolCallUpdateForTransition, "toolCallUpdateForTransition");
|
|
8177
|
+
function storableOutput(result2) {
|
|
8178
|
+
if (result2 === void 0) return false;
|
|
8179
|
+
let json;
|
|
8180
|
+
try {
|
|
8181
|
+
json = JSON.stringify(result2);
|
|
8182
|
+
} catch {
|
|
8183
|
+
return false;
|
|
8184
|
+
}
|
|
8185
|
+
return json !== void 0 && !/\\u0000|\\ud[89ab][0-9a-f]{2}(?!\\ud[c-f])|(?<!\\ud[89ab][0-9a-f]{2})\\ud[c-f][0-9a-f]{2}/i.test(json);
|
|
8186
|
+
}
|
|
8187
|
+
__name(storableOutput, "storableOutput");
|
|
8188
|
+
function storableText2(text) {
|
|
8189
|
+
return text.replaceAll("\0", "");
|
|
8190
|
+
}
|
|
8191
|
+
__name(storableText2, "storableText");
|
|
8192
|
+
|
|
8099
8193
|
// src/in-memory-action-proposal-store.ts
|
|
8100
8194
|
var import_node_crypto2 = require("crypto");
|
|
8101
8195
|
var InMemoryActionProposalStore = class {
|
|
@@ -8142,9 +8236,19 @@ var InMemoryActionProposalStore = class {
|
|
|
8142
8236
|
status: "not_found"
|
|
8143
8237
|
};
|
|
8144
8238
|
const result2 = transition(row2, this.clock());
|
|
8145
|
-
if (result2.proposal)
|
|
8239
|
+
if (result2.proposal) {
|
|
8240
|
+
this.rows.set(id, snapshotActionProposal(result2.proposal));
|
|
8241
|
+
this.proposalChanged(row2, result2.proposal);
|
|
8242
|
+
}
|
|
8146
8243
|
return result2;
|
|
8147
8244
|
}
|
|
8245
|
+
/**
|
|
8246
|
+
* Called after every proposal transition, with the row before and after — synchronously, so no
|
|
8247
|
+
* reader sees one without the other. {@link InMemoryAgentStore} settles the proposal's tool-call
|
|
8248
|
+
* record here (see `toolCallUpdateForTransition`).
|
|
8249
|
+
*/
|
|
8250
|
+
proposalChanged(_previous, _next) {
|
|
8251
|
+
}
|
|
8148
8252
|
async decideActionProposal(scope, id, command) {
|
|
8149
8253
|
return this.mutate(scope, id, (row2, now) => transitionActionProposalDecision(row2, command, now));
|
|
8150
8254
|
}
|
|
@@ -8225,7 +8329,11 @@ var InMemoryActionProposalStore = class {
|
|
|
8225
8329
|
if (result2.proposal) replacements.push(result2.proposal);
|
|
8226
8330
|
}
|
|
8227
8331
|
this.rows.set(proposal.id, proposal);
|
|
8228
|
-
for (const row2 of replacements)
|
|
8332
|
+
for (const row2 of replacements) {
|
|
8333
|
+
const previous = this.rows.get(row2.id);
|
|
8334
|
+
this.rows.set(row2.id, row2);
|
|
8335
|
+
if (previous) this.proposalChanged(previous, row2);
|
|
8336
|
+
}
|
|
8229
8337
|
return {
|
|
8230
8338
|
status: "created",
|
|
8231
8339
|
proposal: snapshotActionProposal(proposal)
|
|
@@ -8946,6 +9054,15 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
|
|
|
8946
9054
|
return settled;
|
|
8947
9055
|
}
|
|
8948
9056
|
async updateToolCall(input) {
|
|
9057
|
+
this.applyToolCallUpdate(input);
|
|
9058
|
+
}
|
|
9059
|
+
/** An independent proposal moved: its `proposed` tool-call record follows it. */
|
|
9060
|
+
proposalChanged(previous, next) {
|
|
9061
|
+
const update = toolCallUpdateForTransition(previous, next);
|
|
9062
|
+
if (update === null || this.toolCalls.get(update.toolCallId)?.proposalId !== next.id) return;
|
|
9063
|
+
this.applyToolCallUpdate(update);
|
|
9064
|
+
}
|
|
9065
|
+
applyToolCallUpdate(input) {
|
|
8949
9066
|
const row2 = this.toolCalls.get(input.toolCallId);
|
|
8950
9067
|
if (row2 === void 0) {
|
|
8951
9068
|
return;
|
|
@@ -10488,6 +10605,8 @@ __name(createFunctionalTool, "createFunctionalTool");
|
|
|
10488
10605
|
toActionProposalView,
|
|
10489
10606
|
toolCallApprovalFromRow,
|
|
10490
10607
|
toolCallContext,
|
|
10608
|
+
toolCallUpdateForProposal,
|
|
10609
|
+
toolCallUpdateForTransition,
|
|
10491
10610
|
traceLlmTurn,
|
|
10492
10611
|
traceToolExecution,
|
|
10493
10612
|
transitionActionProposalClaim,
|