@dudousxd/nestjs-agent 1.35.1 → 1.36.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/durable/index.cjs +130 -20
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.js +134 -24
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +43 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -5815,7 +5815,7 @@ ActionProposalController = _ts_decorate25([
|
|
|
5815
5815
|
var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
|
|
5816
5816
|
|
|
5817
5817
|
// src/runner/inline-agent-runner.ts
|
|
5818
|
-
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE6, RUN_ENDED_BEFORE_TOOL_CALL, RunCancelledError, agentFailureCode, encodeStreamEvent as encodeStreamEvent2, publishAgentRunFailed, releaseThreadRun, runAgentLoop, settleAll, settleUnsettledDelegation, streamFailure as streamFailure2 } from "@dudousxd/nestjs-agent-core";
|
|
5818
|
+
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE6, RUN_ENDED_BEFORE_TOOL_CALL, RunCancelledError, agentFailureCode, agentRunContext, encodeStreamEvent as encodeStreamEvent2, publishAgentRunCancelled, publishAgentRunFailed, releaseThreadRun, runAgentLoop, runDurationMs, settleAll, settleUnsettledDelegation, streamFailure as streamFailure2 } from "@dudousxd/nestjs-agent-core";
|
|
5819
5819
|
import { Inject as Inject25, Injectable as Injectable11, Logger as Logger7, Optional as Optional10 } from "@nestjs/common";
|
|
5820
5820
|
function _ts_decorate26(decorators, target, key, desc) {
|
|
5821
5821
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -5908,8 +5908,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5908
5908
|
...deps,
|
|
5909
5909
|
day
|
|
5910
5910
|
}, input, hooks).then(() => releaseThreadRun(this.store, input.threadId, runId)).catch(async (error) => {
|
|
5911
|
+
const durationMs = runDurationMs(error);
|
|
5912
|
+
const timed = durationMs !== void 0 ? {
|
|
5913
|
+
durationMs
|
|
5914
|
+
} : {};
|
|
5911
5915
|
if (error instanceof RunCancelledError) {
|
|
5912
|
-
await this.settleCancelled(runId, input, deps);
|
|
5916
|
+
await this.settleCancelled(runId, input, deps, durationMs);
|
|
5913
5917
|
return;
|
|
5914
5918
|
}
|
|
5915
5919
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -5917,12 +5921,16 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5917
5921
|
this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
|
|
5918
5922
|
publishAgentRunFailed({
|
|
5919
5923
|
runId,
|
|
5924
|
+
threadId: input.threadId,
|
|
5920
5925
|
code,
|
|
5921
|
-
message
|
|
5926
|
+
message,
|
|
5927
|
+
...timed,
|
|
5928
|
+
context: agentRunContext(input)
|
|
5922
5929
|
});
|
|
5923
5930
|
await this.store.recordRunEnd?.({
|
|
5924
5931
|
runId,
|
|
5925
5932
|
status: "failed",
|
|
5933
|
+
...timed,
|
|
5926
5934
|
errorCode: code,
|
|
5927
5935
|
errorMessage: message
|
|
5928
5936
|
});
|
|
@@ -5994,8 +6002,17 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5994
6002
|
* the stream ENDED after a `cancelled` frame rather than failed, so a client that retries failed
|
|
5995
6003
|
* streams does not retry this one.
|
|
5996
6004
|
*/
|
|
5997
|
-
async settleCancelled(runId, input, deps) {
|
|
6005
|
+
async settleCancelled(runId, input, deps, durationMs) {
|
|
5998
6006
|
this.logger.log(`agent run ${runId} cancelled`);
|
|
6007
|
+
const timed = durationMs !== void 0 ? {
|
|
6008
|
+
durationMs
|
|
6009
|
+
} : {};
|
|
6010
|
+
publishAgentRunCancelled({
|
|
6011
|
+
runId,
|
|
6012
|
+
threadId: input.threadId,
|
|
6013
|
+
...timed,
|
|
6014
|
+
context: agentRunContext(input)
|
|
6015
|
+
});
|
|
5999
6016
|
const writer = await deps.sink.open(runId);
|
|
6000
6017
|
await this.settleQueue(writer, input, runId, "cancelled");
|
|
6001
6018
|
await releaseThreadRun(this.store, input.threadId, runId);
|
|
@@ -6005,7 +6022,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
6005
6022
|
await writer.end();
|
|
6006
6023
|
await this.store.recordRunEnd?.({
|
|
6007
6024
|
runId,
|
|
6008
|
-
status: "cancelled"
|
|
6025
|
+
status: "cancelled",
|
|
6026
|
+
...timed
|
|
6009
6027
|
});
|
|
6010
6028
|
}
|
|
6011
6029
|
/**
|
|
@@ -6191,10 +6209,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
6191
6209
|
}
|
|
6192
6210
|
}), "startAgent")
|
|
6193
6211
|
};
|
|
6194
|
-
|
|
6195
|
-
...deps,
|
|
6196
|
-
day
|
|
6197
|
-
}, {
|
|
6212
|
+
const childInput = {
|
|
6198
6213
|
threadId: subThread.id,
|
|
6199
6214
|
actor,
|
|
6200
6215
|
userText: task,
|
|
@@ -6204,13 +6219,29 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
6204
6219
|
delegationPath: path,
|
|
6205
6220
|
parentRunId,
|
|
6206
6221
|
deliverTo
|
|
6207
|
-
}
|
|
6222
|
+
};
|
|
6223
|
+
void runAgentLoop({
|
|
6224
|
+
...deps,
|
|
6225
|
+
day
|
|
6226
|
+
}, childInput, hooks).catch(async (error) => {
|
|
6208
6227
|
const cancelled = error instanceof RunCancelledError;
|
|
6209
6228
|
const message = error instanceof Error ? error.message : String(error);
|
|
6210
|
-
|
|
6229
|
+
const durationMs = runDurationMs(error);
|
|
6230
|
+
const timed = durationMs !== void 0 ? {
|
|
6231
|
+
durationMs
|
|
6232
|
+
} : {};
|
|
6233
|
+
const settled = {
|
|
6234
|
+
runId,
|
|
6235
|
+
threadId: subThread.id,
|
|
6236
|
+
...timed,
|
|
6237
|
+
context: agentRunContext(childInput)
|
|
6238
|
+
};
|
|
6239
|
+
if (cancelled) {
|
|
6240
|
+
publishAgentRunCancelled(settled);
|
|
6241
|
+
} else {
|
|
6211
6242
|
this.logger.error(`detached agent run ${runId} failed: ${message}`);
|
|
6212
6243
|
publishAgentRunFailed({
|
|
6213
|
-
|
|
6244
|
+
...settled,
|
|
6214
6245
|
code: agentFailureCode(error),
|
|
6215
6246
|
message
|
|
6216
6247
|
});
|
|
@@ -6218,6 +6249,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
6218
6249
|
await this.store.recordRunEnd?.({
|
|
6219
6250
|
runId,
|
|
6220
6251
|
status: cancelled ? "cancelled" : "failed",
|
|
6252
|
+
...timed,
|
|
6221
6253
|
...cancelled ? {} : {
|
|
6222
6254
|
errorCode: agentFailureCode(error),
|
|
6223
6255
|
errorMessage: message
|