@dudousxd/nestjs-agent 1.16.1 → 1.17.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/README.md +15 -0
- package/dist/durable/index.cjs +1686 -1616
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +1 -0
- package/dist/durable/index.d.ts +1 -0
- package/dist/durable/index.js +1012 -942
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +452 -392
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +73 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit, ConflictException } from '@nestjs/common';
|
|
2
2
|
import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentSkillsOptions } from './chat-queue.service-Bqq00NN1.cjs';
|
|
3
3
|
export { e as AGENT_TOOL_BRAND, f as AgentAttachmentsOptions, g as AgentDeps, h as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, i as QueueSettleOutcome, j as QueuedTurn, k as QueuedTurnStarter, l as QuotaLimits, m as QuotaWindowLimits, n as delegateToolName, p as provideAgentTool, o as provideAgentTools, u as utcDay } from './chat-queue.service-Bqq00NN1.cjs';
|
|
4
4
|
import { AgentRunner, AgentStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, AgentApprovalPort, ActorResolver, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolPresentation, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
|
|
@@ -249,6 +249,14 @@ declare class AgentService {
|
|
|
249
249
|
* not the thread's own actor).
|
|
250
250
|
*/
|
|
251
251
|
signalToolCall(toolCallId: string, reply: HumanReply): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Refuse a decision addressed at a run that is over (`409 run_not_active`). The runtime would take
|
|
254
|
+
* the signal and buffer it for a run that never comes back — the person's "yes" is accepted, the
|
|
255
|
+
* card says so, and nothing runs. Settles the calls the dead run left awaiting a decision on the
|
|
256
|
+
* way out, so the card stops asking. A runner that cannot say whether a run is alive is taken at
|
|
257
|
+
* its word that it is, and so is one that fails to answer.
|
|
258
|
+
*/
|
|
259
|
+
private assertRunWaiting;
|
|
252
260
|
cancel(actor: Actor, runId: string): Promise<void>;
|
|
253
261
|
listThreads(actorRef: string): Promise<ThreadSummary[]>;
|
|
254
262
|
getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
|
|
@@ -1078,6 +1086,15 @@ declare class QueueController {
|
|
|
1078
1086
|
remove(req: Request, messageId: string): Promise<ChatQueueState>;
|
|
1079
1087
|
}
|
|
1080
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* The thread message queue, as the durable runner and the `agent.run` workflow ask for it.
|
|
1091
|
+
*
|
|
1092
|
+
* A token rather than the `ChatQueueService` class: `@dudousxd/nestjs-agent/durable` is a separate
|
|
1093
|
+
* bundle with its own copy of every class it imports, so a class used as an injection token there
|
|
1094
|
+
* is not the class `AgentModule` provides. `Symbol.for` is the same value in every bundle.
|
|
1095
|
+
*/
|
|
1096
|
+
declare const AGENT_CHAT_QUEUE: unique symbol;
|
|
1097
|
+
|
|
1081
1098
|
/**
|
|
1082
1099
|
* The default `TokenStreamSink`: buffers chunks per run in-process so a reconnecting subscriber
|
|
1083
1100
|
* replays everything so far, then follows live.
|
|
@@ -1185,4 +1202,17 @@ declare function defaultRequestUserMapper(user: Record<string, unknown>): Actor;
|
|
|
1185
1202
|
*/
|
|
1186
1203
|
declare function requestUserActorResolver<TUser = Record<string, unknown>>(map?: RequestUserMapper<TUser>): ActorResolver;
|
|
1187
1204
|
|
|
1188
|
-
|
|
1205
|
+
/**
|
|
1206
|
+
* `approve` / `reject` / `answer` / `skip` addressed at a run that is no longer running — answered
|
|
1207
|
+
* `409 { code: 'run_not_active', message }`.
|
|
1208
|
+
*
|
|
1209
|
+
* The runtime would take the signal and buffer it for a run that never comes back: the person's
|
|
1210
|
+
* "yes" is accepted, the card says so, and nothing runs. Refusing it is what lets a client say so.
|
|
1211
|
+
*/
|
|
1212
|
+
declare class RunNotActiveException extends ConflictException {
|
|
1213
|
+
readonly runId: string;
|
|
1214
|
+
readonly code = "run_not_active";
|
|
1215
|
+
constructor(runId: string);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
export { AGENT_CHAT_QUEUE, AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, type AnonymousActorOptions, AnonymousActorResolver, type AttachmentLimits, AttachmentsController, type ChatParams, ChatQueueService, type ChatSendMode, type ChatSendResult, ConfigController, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, MAX_ATTACHMENTS_PER_MESSAGE, MemoriesController, MessagesController, ModelsController, QueueController, type QueuedSend, type RequestUserMapper, type ResolvedAiToolOptions, RunNotActiveException, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, type ThreadModelReader, ToolsController, attachmentLimits, declaredSkillProvider, defaultRequestUserMapper, readAgentMetadata, readAiToolMetadata, readSkillMetadata, requestUserActorResolver, resolveSkillsConfig, skillScope, toolNameFromClass };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit, ConflictException } from '@nestjs/common';
|
|
2
2
|
import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentSkillsOptions } from './chat-queue.service-Bqq00NN1.js';
|
|
3
3
|
export { e as AGENT_TOOL_BRAND, f as AgentAttachmentsOptions, g as AgentDeps, h as AgentMemoryOptions, a as AgentSurface, F as FunctionalTool, L as LedgerQuotaProvider, Q as QueuePlan, i as QueueSettleOutcome, j as QueuedTurn, k as QueuedTurnStarter, l as QuotaLimits, m as QuotaWindowLimits, n as delegateToolName, p as provideAgentTool, o as provideAgentTools, u as utcDay } from './chat-queue.service-Bqq00NN1.js';
|
|
4
4
|
import { AgentRunner, AgentStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, AgentApprovalPort, ActorResolver, MessageAttachment, AgentAttachmentConfig, AgentClientConfig, ToolPresentation, AgentHistoryWindow, AgentIntake, SkillContext, ToolRegistry, AgentRegistry, PromptContributor, SkillsConfig, SkillCatalogEntry, ToolCatalogEntry, MemoryConfig, MemoryDigestEntry, SkillProvider, AgentRunInput, AgentRunStartOptions, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
|
|
@@ -249,6 +249,14 @@ declare class AgentService {
|
|
|
249
249
|
* not the thread's own actor).
|
|
250
250
|
*/
|
|
251
251
|
signalToolCall(toolCallId: string, reply: HumanReply): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Refuse a decision addressed at a run that is over (`409 run_not_active`). The runtime would take
|
|
254
|
+
* the signal and buffer it for a run that never comes back — the person's "yes" is accepted, the
|
|
255
|
+
* card says so, and nothing runs. Settles the calls the dead run left awaiting a decision on the
|
|
256
|
+
* way out, so the card stops asking. A runner that cannot say whether a run is alive is taken at
|
|
257
|
+
* its word that it is, and so is one that fails to answer.
|
|
258
|
+
*/
|
|
259
|
+
private assertRunWaiting;
|
|
252
260
|
cancel(actor: Actor, runId: string): Promise<void>;
|
|
253
261
|
listThreads(actorRef: string): Promise<ThreadSummary[]>;
|
|
254
262
|
getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
|
|
@@ -1078,6 +1086,15 @@ declare class QueueController {
|
|
|
1078
1086
|
remove(req: Request, messageId: string): Promise<ChatQueueState>;
|
|
1079
1087
|
}
|
|
1080
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* The thread message queue, as the durable runner and the `agent.run` workflow ask for it.
|
|
1091
|
+
*
|
|
1092
|
+
* A token rather than the `ChatQueueService` class: `@dudousxd/nestjs-agent/durable` is a separate
|
|
1093
|
+
* bundle with its own copy of every class it imports, so a class used as an injection token there
|
|
1094
|
+
* is not the class `AgentModule` provides. `Symbol.for` is the same value in every bundle.
|
|
1095
|
+
*/
|
|
1096
|
+
declare const AGENT_CHAT_QUEUE: unique symbol;
|
|
1097
|
+
|
|
1081
1098
|
/**
|
|
1082
1099
|
* The default `TokenStreamSink`: buffers chunks per run in-process so a reconnecting subscriber
|
|
1083
1100
|
* replays everything so far, then follows live.
|
|
@@ -1185,4 +1202,17 @@ declare function defaultRequestUserMapper(user: Record<string, unknown>): Actor;
|
|
|
1185
1202
|
*/
|
|
1186
1203
|
declare function requestUserActorResolver<TUser = Record<string, unknown>>(map?: RequestUserMapper<TUser>): ActorResolver;
|
|
1187
1204
|
|
|
1188
|
-
|
|
1205
|
+
/**
|
|
1206
|
+
* `approve` / `reject` / `answer` / `skip` addressed at a run that is no longer running — answered
|
|
1207
|
+
* `409 { code: 'run_not_active', message }`.
|
|
1208
|
+
*
|
|
1209
|
+
* The runtime would take the signal and buffer it for a run that never comes back: the person's
|
|
1210
|
+
* "yes" is accepted, the card says so, and nothing runs. Refusing it is what lets a client say so.
|
|
1211
|
+
*/
|
|
1212
|
+
declare class RunNotActiveException extends ConflictException {
|
|
1213
|
+
readonly runId: string;
|
|
1214
|
+
readonly code = "run_not_active";
|
|
1215
|
+
constructor(runId: string);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
export { AGENT_CHAT_QUEUE, AGENT_METADATA, AI_TOOL_METADATA, ATTACHMENT_PAGE_SIZE, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AgentSkillsOptions, AiTool, AiToolDiscoveryService, type AiToolOptions, type AnonymousActorOptions, AnonymousActorResolver, type AttachmentLimits, AttachmentsController, type ChatParams, ChatQueueService, type ChatSendMode, type ChatSendResult, ConfigController, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, MAX_ATTACHMENTS_PER_MESSAGE, MemoriesController, MessagesController, ModelsController, QueueController, type QueuedSend, type RequestUserMapper, type ResolvedAiToolOptions, RunNotActiveException, SKILL_METADATA, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, Skill, type SkillBody, SkillDiscoveryService, type SkillOptions, SkillsController, SystemPrompt, SystemPromptContributor, type ThreadDefaultAgentReader, type ThreadModelReader, ToolsController, attachmentLimits, declaredSkillProvider, defaultRequestUserMapper, readAgentMetadata, readAiToolMetadata, readSkillMetadata, requestUserActorResolver, resolveSkillsConfig, skillScope, toolNameFromClass };
|
package/dist/index.js
CHANGED
|
@@ -265,8 +265,8 @@ AgentDepsFactory2 = _ts_decorate([
|
|
|
265
265
|
], AgentDepsFactory2);
|
|
266
266
|
|
|
267
267
|
// src/agent.service.ts
|
|
268
|
-
import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE3, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval, readElicitationQuestions, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
|
|
269
|
-
import { BadRequestException, ConflictException, ForbiddenException, GoneException, HttpException, HttpStatus, Inject as Inject3, Injectable as Injectable3, NotFoundException, NotImplementedException as NotImplementedException2, Optional as Optional3 } from "@nestjs/common";
|
|
268
|
+
import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE3, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval, readElicitationQuestions, settleDeadRun, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
|
|
269
|
+
import { BadRequestException, ConflictException as ConflictException2, ForbiddenException, GoneException, HttpException, HttpStatus, Inject as Inject3, Injectable as Injectable3, NotFoundException, NotImplementedException as NotImplementedException2, Optional as Optional3 } from "@nestjs/common";
|
|
270
270
|
|
|
271
271
|
// src/agent-deps.ts
|
|
272
272
|
function utcDay(date = /* @__PURE__ */ new Date()) {
|
|
@@ -711,6 +711,24 @@ function queueFrame(items, paused, started) {
|
|
|
711
711
|
}
|
|
712
712
|
__name(queueFrame, "queueFrame");
|
|
713
713
|
|
|
714
|
+
// src/run-not-active.exception.ts
|
|
715
|
+
import { RUN_NOT_ACTIVE_CODE, RUN_NOT_ACTIVE_MESSAGE } from "@dudousxd/nestjs-agent-core";
|
|
716
|
+
import { ConflictException } from "@nestjs/common";
|
|
717
|
+
var RunNotActiveException = class extends ConflictException {
|
|
718
|
+
static {
|
|
719
|
+
__name(this, "RunNotActiveException");
|
|
720
|
+
}
|
|
721
|
+
runId;
|
|
722
|
+
code = RUN_NOT_ACTIVE_CODE;
|
|
723
|
+
constructor(runId) {
|
|
724
|
+
super({
|
|
725
|
+
statusCode: 409,
|
|
726
|
+
code: RUN_NOT_ACTIVE_CODE,
|
|
727
|
+
message: RUN_NOT_ACTIVE_MESSAGE
|
|
728
|
+
}), this.runId = runId;
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
|
|
714
732
|
// src/agent.service.ts
|
|
715
733
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
716
734
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -908,7 +926,7 @@ var AgentService = class {
|
|
|
908
926
|
};
|
|
909
927
|
}
|
|
910
928
|
await this.requireQueue().publish(result.threadId);
|
|
911
|
-
throw new
|
|
929
|
+
throw new ConflictException2({
|
|
912
930
|
statusCode: 409,
|
|
913
931
|
code: "run_active",
|
|
914
932
|
message: `thread ${result.threadId} already has a turn running`
|
|
@@ -968,6 +986,11 @@ var AgentService = class {
|
|
|
968
986
|
}
|
|
969
987
|
const mode = params.mode ?? "auto";
|
|
970
988
|
const { live, stale } = await queue.holder(threadId, this.runner);
|
|
989
|
+
if (stale !== null) {
|
|
990
|
+
await settleDeadRun(this.store, {
|
|
991
|
+
runId: stale
|
|
992
|
+
});
|
|
993
|
+
}
|
|
971
994
|
if (live === null && mode !== "queue") {
|
|
972
995
|
const runId = crypto.randomUUID();
|
|
973
996
|
if (await queue.queueStore().claimActiveStream(threadId, runId, stale !== null ? {
|
|
@@ -980,7 +1003,7 @@ var AgentService = class {
|
|
|
980
1003
|
}
|
|
981
1004
|
}
|
|
982
1005
|
if (params.regenerate === true) {
|
|
983
|
-
throw new
|
|
1006
|
+
throw new ConflictException2({
|
|
984
1007
|
statusCode: 409,
|
|
985
1008
|
code: "run_active",
|
|
986
1009
|
message: "cannot regenerate while a turn is running on this thread"
|
|
@@ -1328,8 +1351,29 @@ var AgentService = class {
|
|
|
1328
1351
|
async signalToolCall(toolCallId2, reply) {
|
|
1329
1352
|
await this.assertNotExpired(toolCallId2);
|
|
1330
1353
|
const runId = await this.resolveRunForToolCall(toolCallId2);
|
|
1354
|
+
await this.assertRunWaiting(runId);
|
|
1331
1355
|
return this.runner.signal(runId, toolCallId2, reply);
|
|
1332
1356
|
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Refuse a decision addressed at a run that is over (`409 run_not_active`). The runtime would take
|
|
1359
|
+
* the signal and buffer it for a run that never comes back — the person's "yes" is accepted, the
|
|
1360
|
+
* card says so, and nothing runs. Settles the calls the dead run left awaiting a decision on the
|
|
1361
|
+
* way out, so the card stops asking. A runner that cannot say whether a run is alive is taken at
|
|
1362
|
+
* its word that it is, and so is one that fails to answer.
|
|
1363
|
+
*/
|
|
1364
|
+
async assertRunWaiting(runId) {
|
|
1365
|
+
if (typeof this.runner.isRunActive !== "function") {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
const active = await this.runner.isRunActive(runId).catch(() => true);
|
|
1369
|
+
if (active) {
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
await settleDeadRun(this.store, {
|
|
1373
|
+
runId
|
|
1374
|
+
});
|
|
1375
|
+
throw new RunNotActiveException(runId);
|
|
1376
|
+
}
|
|
1333
1377
|
async cancel(actor, runId) {
|
|
1334
1378
|
await this.assertOwnsActiveStream(actor, runId);
|
|
1335
1379
|
return this.runner.cancel(runId);
|
|
@@ -2013,7 +2057,7 @@ AttachmentsController = _ts_decorate6([
|
|
|
2013
2057
|
], AttachmentsController);
|
|
2014
2058
|
|
|
2015
2059
|
// src/controller/chat.controller.ts
|
|
2016
|
-
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER2, AgentStreamError } from "@dudousxd/nestjs-agent-core";
|
|
2060
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER2, AgentStreamError, streamFailure } from "@dudousxd/nestjs-agent-core";
|
|
2017
2061
|
import { BadRequestException as BadRequestException3, Body, Controller as Controller3, Get as Get3, Inject as Inject6, Param, Post as Post2, Query, Req as Req2, Res } from "@nestjs/common";
|
|
2018
2062
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
2019
2063
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2209,10 +2253,7 @@ data: ${line}
|
|
|
2209
2253
|
const payload = error instanceof AgentStreamError ? {
|
|
2210
2254
|
code: error.code,
|
|
2211
2255
|
message: error.message
|
|
2212
|
-
} :
|
|
2213
|
-
code: "run_failed",
|
|
2214
|
-
message: error instanceof Error ? error.message : "stream error"
|
|
2215
|
-
};
|
|
2256
|
+
} : streamFailure(error);
|
|
2216
2257
|
res.write(`event: error
|
|
2217
2258
|
data: ${JSON.stringify(payload)}
|
|
2218
2259
|
|
|
@@ -4227,8 +4268,11 @@ var LedgerQuotaProvider = class {
|
|
|
4227
4268
|
}
|
|
4228
4269
|
};
|
|
4229
4270
|
|
|
4271
|
+
// src/queue/chat-queue.token.ts
|
|
4272
|
+
var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
|
|
4273
|
+
|
|
4230
4274
|
// src/runner/inline-agent-runner.ts
|
|
4231
|
-
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_STORE as AGENT_STORE4, RunCancelledError, agentFailureCode, encodeStreamEvent as encodeStreamEvent2, publishAgentRunFailed, releaseThreadRun, runAgentLoop, settleAll, settleUnsettledDelegation } from "@dudousxd/nestjs-agent-core";
|
|
4275
|
+
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_STORE as AGENT_STORE4, RUN_ENDED_BEFORE_TOOL_CALL, RunCancelledError, agentFailureCode, encodeStreamEvent as encodeStreamEvent2, publishAgentRunFailed, releaseThreadRun, runAgentLoop, settleAll, settleUnsettledDelegation, streamFailure as streamFailure2 } from "@dudousxd/nestjs-agent-core";
|
|
4232
4276
|
import { Inject as Inject20, Injectable as Injectable8, Logger as Logger5, Optional as Optional8 } from "@nestjs/common";
|
|
4233
4277
|
function _ts_decorate21(decorators, target, key, desc) {
|
|
4234
4278
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -4283,7 +4327,15 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4283
4327
|
* that was running it is gone (a restart), and a thread it still holds is a stale claim.
|
|
4284
4328
|
*/
|
|
4285
4329
|
async isRunActive(runId) {
|
|
4286
|
-
|
|
4330
|
+
if (this.live.has(runId)) {
|
|
4331
|
+
return true;
|
|
4332
|
+
}
|
|
4333
|
+
for (const key of this.pending.keys()) {
|
|
4334
|
+
if (key.startsWith(`${runId}:`)) {
|
|
4335
|
+
return true;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
return false;
|
|
4287
4339
|
}
|
|
4288
4340
|
async start(input, options = {}) {
|
|
4289
4341
|
const runId = options.runId ?? crypto.randomUUID();
|
|
@@ -4326,13 +4378,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4326
4378
|
errorCode: code,
|
|
4327
4379
|
errorMessage: message
|
|
4328
4380
|
});
|
|
4381
|
+
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
|
|
4329
4382
|
const writer = await deps.sink.open(runId);
|
|
4330
4383
|
await this.settleQueue(writer, input, runId, "failed", message);
|
|
4331
4384
|
await releaseThreadRun(this.store, input.threadId, runId);
|
|
4332
|
-
await writer.fail(
|
|
4333
|
-
code,
|
|
4334
|
-
message
|
|
4335
|
-
});
|
|
4385
|
+
await writer.fail(streamFailure2(error));
|
|
4336
4386
|
}).finally(() => {
|
|
4337
4387
|
this.cancelled.delete(runId);
|
|
4338
4388
|
this.live.delete(runId);
|
|
@@ -4606,6 +4656,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
4606
4656
|
errorMessage: message
|
|
4607
4657
|
}
|
|
4608
4658
|
});
|
|
4659
|
+
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
|
|
4609
4660
|
await settleUnsettledDelegation({
|
|
4610
4661
|
store: this.store,
|
|
4611
4662
|
delivery: deliverTo,
|
|
@@ -4924,6 +4975,10 @@ function sharedProviders(durable) {
|
|
|
4924
4975
|
// The thread message queue — every surface, since both runners and the durable workflow settle
|
|
4925
4976
|
// into it, and the chat routes enqueue into it.
|
|
4926
4977
|
ChatQueueService,
|
|
4978
|
+
{
|
|
4979
|
+
provide: AGENT_CHAT_QUEUE,
|
|
4980
|
+
useExisting: ChatQueueService
|
|
4981
|
+
},
|
|
4927
4982
|
InlineAgentRunner,
|
|
4928
4983
|
AgentService,
|
|
4929
4984
|
// Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
|
|
@@ -4986,6 +5041,7 @@ function exportsFor() {
|
|
|
4986
5041
|
AgentDepsFactory2,
|
|
4987
5042
|
AgentService,
|
|
4988
5043
|
ChatQueueService,
|
|
5044
|
+
AGENT_CHAT_QUEUE,
|
|
4989
5045
|
InlineAgentRunner,
|
|
4990
5046
|
AGENT_APPROVAL_PORT
|
|
4991
5047
|
];
|
|
@@ -5177,6 +5233,7 @@ __name(requestUserActorResolver, "requestUserActorResolver");
|
|
|
5177
5233
|
// src/index.ts
|
|
5178
5234
|
export * from "@dudousxd/nestjs-agent-core";
|
|
5179
5235
|
export {
|
|
5236
|
+
AGENT_CHAT_QUEUE,
|
|
5180
5237
|
AGENT_METADATA,
|
|
5181
5238
|
AGENT_TOOL_BRAND,
|
|
5182
5239
|
AI_TOOL_METADATA,
|
|
@@ -5204,6 +5261,7 @@ export {
|
|
|
5204
5261
|
MessagesController,
|
|
5205
5262
|
ModelsController,
|
|
5206
5263
|
QueueController,
|
|
5264
|
+
RunNotActiveException,
|
|
5207
5265
|
SKILL_METADATA,
|
|
5208
5266
|
SYSTEM_PROMPT_CONTRIBUTOR_METADATA,
|
|
5209
5267
|
SYSTEM_PROMPT_METADATA,
|