@dudousxd/nestjs-agent 1.13.0 → 1.15.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 +19 -0
- package/dist/{agent-deps.factory-DkWvoWbD.d.cts → chat-queue.service-Bqq00NN1.d.cts} +131 -2
- package/dist/{agent-deps.factory-DkWvoWbD.d.ts → chat-queue.service-Bqq00NN1.d.ts} +131 -2
- package/dist/durable/index.cjs +1796 -759
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +26 -7
- package/dist/durable/index.d.ts +26 -7
- package/dist/durable/index.js +1628 -591
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +1598 -672
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -8
- package/dist/index.d.ts +133 -8
- package/dist/index.js +1412 -488
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, d as AgentSkillsOptions } from './
|
|
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
|
|
4
|
-
import { AgentRunner, AgentStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, 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, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
|
|
2
|
+
import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentSkillsOptions } from './chat-queue.service-Bqq00NN1.cjs';
|
|
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
|
+
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';
|
|
5
5
|
export * from '@dudousxd/nestjs-agent-core';
|
|
6
6
|
import { Request } from 'express';
|
|
7
7
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
@@ -12,6 +12,34 @@ declare class AgentModule {
|
|
|
12
12
|
static forRootAsync(options: AgentModuleAsyncOptions): DynamicModule;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* What a send does when its thread already has a turn running:
|
|
17
|
+
* - `'auto'` (default) — run now when the thread is idle, else wait in the thread's queue.
|
|
18
|
+
* - `'queue'` — always wait in the queue, behind whatever is already waiting (it still starts at
|
|
19
|
+
* once when nothing is running and nothing is ahead of it).
|
|
20
|
+
* - `'interrupt'` — cancel the running turn and run this one next, ahead of the queue.
|
|
21
|
+
*/
|
|
22
|
+
type ChatSendMode = 'auto' | 'queue' | 'interrupt';
|
|
23
|
+
/** A send that is waiting in its thread's queue instead of running. */
|
|
24
|
+
interface QueuedSend {
|
|
25
|
+
threadId: string;
|
|
26
|
+
queued: true;
|
|
27
|
+
/** The queued message's id — also the run id it will start under. */
|
|
28
|
+
messageId: string;
|
|
29
|
+
/** 0-based place in the queue at the time it was queued (`0` → next). */
|
|
30
|
+
position: number;
|
|
31
|
+
queue: ChatQueueState;
|
|
32
|
+
/** The turn it started under, when it started straight away (an idle thread). */
|
|
33
|
+
runId?: string;
|
|
34
|
+
/** The run an interrupt cancelled to make room for it. */
|
|
35
|
+
interrupting?: string;
|
|
36
|
+
}
|
|
37
|
+
/** What {@link AgentService.send} did: started a turn, or queued the message. */
|
|
38
|
+
type ChatSendResult = {
|
|
39
|
+
runId: string;
|
|
40
|
+
threadId: string;
|
|
41
|
+
queued?: undefined;
|
|
42
|
+
} | QueuedSend;
|
|
15
43
|
interface ChatParams {
|
|
16
44
|
actor: Actor;
|
|
17
45
|
message: string;
|
|
@@ -36,6 +64,8 @@ interface ChatParams {
|
|
|
36
64
|
* the thread list until the caller promotes it. Ignored when `threadId` is set.
|
|
37
65
|
*/
|
|
38
66
|
transient?: boolean;
|
|
67
|
+
/** What to do when the thread already has a turn running — see {@link ChatSendMode}. */
|
|
68
|
+
mode?: ChatSendMode;
|
|
39
69
|
}
|
|
40
70
|
/**
|
|
41
71
|
* A store that can answer a thread's default agent on its own, without materializing the thread.
|
|
@@ -60,7 +90,12 @@ declare class AgentService {
|
|
|
60
90
|
private readonly models?;
|
|
61
91
|
private readonly quotaProvider?;
|
|
62
92
|
private readonly options?;
|
|
63
|
-
|
|
93
|
+
private readonly queue?;
|
|
94
|
+
constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, staging?: AttachmentStagingStore | undefined, models?: ModelCatalog | undefined, quotaProvider?: QuotaProvider | undefined, options?: Pick<AgentModuleOptions, "quota"> | undefined, queue?: ChatQueueService | undefined);
|
|
95
|
+
/** The queue service when the bound store can hold a queue, else `undefined`. */
|
|
96
|
+
private queueing;
|
|
97
|
+
/** The queue service, or a 501 naming what is missing. */
|
|
98
|
+
private requireQueue;
|
|
64
99
|
/**
|
|
65
100
|
* The actor's budget across windows (`GET <base>/quota`) — the bound {@link QuotaProvider}'s
|
|
66
101
|
* report. Without one (a service built outside the module), a day window from the ledger.
|
|
@@ -89,10 +124,51 @@ declare class AgentService {
|
|
|
89
124
|
*/
|
|
90
125
|
private resolveModel;
|
|
91
126
|
private threadModel;
|
|
127
|
+
/**
|
|
128
|
+
* Start a turn — for in-process callers that need a run id back. A send that would have to wait
|
|
129
|
+
* (its thread already has a turn running) is refused with `409` instead; {@link send} is the form
|
|
130
|
+
* that queues it.
|
|
131
|
+
*/
|
|
92
132
|
chat(params: ChatParams): Promise<{
|
|
93
133
|
runId: string;
|
|
94
134
|
threadId: string;
|
|
95
135
|
}>;
|
|
136
|
+
/**
|
|
137
|
+
* Send a message: start a turn, or — when its thread already has one running — queue the message
|
|
138
|
+
* to run after it (see {@link ChatSendMode}). What `POST <base>/chat` calls.
|
|
139
|
+
*/
|
|
140
|
+
send(params: ChatParams): Promise<ChatSendResult>;
|
|
141
|
+
/**
|
|
142
|
+
* Start a turn the thread is already claimed for, under the claimed id. A runner that minted an
|
|
143
|
+
* id of its own anyway gets the thread re-pointed at it; one that fails to start frees the thread.
|
|
144
|
+
*/
|
|
145
|
+
private startClaimed;
|
|
146
|
+
/** Put a send in its thread's queue, then drain it if the thread turned out to be free. */
|
|
147
|
+
private enqueue;
|
|
148
|
+
/** `GET <base>/threads/:id/queue` — the thread's waiting messages and whether it drains. */
|
|
149
|
+
getQueue(actor: Actor, threadId: string): Promise<ChatQueueState>;
|
|
150
|
+
/**
|
|
151
|
+
* `PATCH <base>/queue/:messageId` — change a waiting message's text and/or attachments, and/or move
|
|
152
|
+
* it to `position` in the queue. Answers the thread's queue.
|
|
153
|
+
*/
|
|
154
|
+
updateQueuedMessage(actor: Actor, messageId: string, patch: {
|
|
155
|
+
message?: string;
|
|
156
|
+
attachments?: AttachmentRef[] | null;
|
|
157
|
+
position?: number;
|
|
158
|
+
}): Promise<ChatQueueState>;
|
|
159
|
+
/** `DELETE <base>/queue/:messageId` — drop a waiting message. Answers the thread's queue. */
|
|
160
|
+
removeQueuedMessage(actor: Actor, messageId: string): Promise<ChatQueueState>;
|
|
161
|
+
/** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
|
|
162
|
+
clearQueue(actor: Actor, threadId: string): Promise<ChatQueueState>;
|
|
163
|
+
/**
|
|
164
|
+
* `POST <base>/threads/:id/queue/resume` — lift a pause and start the head when nothing is
|
|
165
|
+
* running. Answers the queue, and the run the head started under, if it did.
|
|
166
|
+
*/
|
|
167
|
+
resumeQueue(actor: Actor, threadId: string): Promise<ChatQueueState & {
|
|
168
|
+
runId?: string;
|
|
169
|
+
}>;
|
|
170
|
+
/** The thread a queued message waits on, once the caller is shown to own it. */
|
|
171
|
+
private assertOwnsQueuedMessage;
|
|
96
172
|
/**
|
|
97
173
|
* Rebuild this turn's attachments from the staging store, keyed by the ids the caller claimed.
|
|
98
174
|
* The model provider fetches {@link MessageAttachment.url} verbatim, so that url is only ever
|
|
@@ -795,7 +871,11 @@ declare class ToolsController {
|
|
|
795
871
|
private readonly agents;
|
|
796
872
|
constructor(actorResolver: ActorResolver, depsFactory: AgentDepsFactory, agents: AgentRegistry);
|
|
797
873
|
list(req: Request,
|
|
798
|
-
/**
|
|
874
|
+
/**
|
|
875
|
+
* The agent whose tools to list. Omitted → the default agent, the one a turn naming none uses.
|
|
876
|
+
* `*` → every agent's: the union of what this actor reaches through any of them, each tool once
|
|
877
|
+
* — for a surface that shows several agents' conversations.
|
|
878
|
+
*/
|
|
799
879
|
agent?: string): Promise<ToolCatalogEntry[]>;
|
|
800
880
|
}
|
|
801
881
|
|
|
@@ -862,6 +942,7 @@ declare function resolveSkillsConfig(options: AgentSkillsOptions | undefined, de
|
|
|
862
942
|
declare class InlineAgentRunner implements AgentRunner {
|
|
863
943
|
private readonly factory;
|
|
864
944
|
private readonly store;
|
|
945
|
+
private readonly queue?;
|
|
865
946
|
private readonly logger;
|
|
866
947
|
private readonly pending;
|
|
867
948
|
/**
|
|
@@ -870,8 +951,15 @@ declare class InlineAgentRunner implements AgentRunner {
|
|
|
870
951
|
* running it. A cancelled id is dropped once the run settles, so the set tracks live runs only.
|
|
871
952
|
*/
|
|
872
953
|
private readonly cancelled;
|
|
873
|
-
|
|
874
|
-
|
|
954
|
+
/** Top-level runs this process is running now — what {@link isRunActive} answers from. */
|
|
955
|
+
private readonly live;
|
|
956
|
+
constructor(factory: AgentDepsFactory, store: AgentStore, queue?: ChatQueueService | undefined);
|
|
957
|
+
/**
|
|
958
|
+
* In-process, so exact: a run this process is not running is not running anywhere — the process
|
|
959
|
+
* that was running it is gone (a restart), and a thread it still holds is a stale claim.
|
|
960
|
+
*/
|
|
961
|
+
isRunActive(runId: string): Promise<boolean>;
|
|
962
|
+
start(input: AgentRunInput, options?: AgentRunStartOptions): Promise<{
|
|
875
963
|
runId: string;
|
|
876
964
|
}>;
|
|
877
965
|
signal(runId: string, toolCallId: string, reply: HumanReply): Promise<void>;
|
|
@@ -897,6 +985,15 @@ declare class InlineAgentRunner implements AgentRunner {
|
|
|
897
985
|
* streams does not retry this one.
|
|
898
986
|
*/
|
|
899
987
|
private settleCancelled;
|
|
988
|
+
/**
|
|
989
|
+
* Move the thread past a settling TOP-LEVEL run — to the next queued message, which starts here,
|
|
990
|
+
* or to a paused/empty queue — and write the resulting `queue` frame into this run's stream. A
|
|
991
|
+
* no-op without a queue-capable store, and for a run that is not a thread's own turn.
|
|
992
|
+
*
|
|
993
|
+
* Never throws: the run is settling either way, and a queue that could not be advanced is picked
|
|
994
|
+
* up by the next send or resume on the thread.
|
|
995
|
+
*/
|
|
996
|
+
private settleQueue;
|
|
900
997
|
/**
|
|
901
998
|
* Park a run on a human, keyed by run + tool call. One map for approvals and for question-set
|
|
902
999
|
* answers alike: both wait on the same key, and `signal` cannot tell (or need to tell) which
|
|
@@ -929,6 +1026,34 @@ declare class InlineAgentRunner implements AgentRunner {
|
|
|
929
1026
|
private runNested;
|
|
930
1027
|
}
|
|
931
1028
|
|
|
1029
|
+
interface UpdateQueuedMessageBody {
|
|
1030
|
+
/** The new text. */
|
|
1031
|
+
message?: unknown;
|
|
1032
|
+
/** `[{ mediaId }]` refs replacing the message's attachments; `null` or `[]` drops them. */
|
|
1033
|
+
attachments?: unknown;
|
|
1034
|
+
/** Move the message to this 0-based place in the queue. */
|
|
1035
|
+
position?: unknown;
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* The thread message queue: messages sent while a turn was running, waiting to run after it. Every
|
|
1039
|
+
* route is ownership-gated like the thread routes, and answers the thread's queue as it now stands
|
|
1040
|
+
* (`{ items, paused }`). A change is also announced to whoever is streaming the thread, as a `queue`
|
|
1041
|
+
* frame in the running turn's stream.
|
|
1042
|
+
*/
|
|
1043
|
+
declare class QueueController {
|
|
1044
|
+
private readonly agent;
|
|
1045
|
+
private readonly actorResolver;
|
|
1046
|
+
constructor(agent: AgentService, actorResolver: ActorResolver);
|
|
1047
|
+
list(req: Request, id: string): Promise<ChatQueueState>;
|
|
1048
|
+
clear(req: Request, id: string): Promise<ChatQueueState>;
|
|
1049
|
+
/** Lift a pause; the head starts when nothing is running. Carries `runId` when it started. */
|
|
1050
|
+
resume(req: Request, id: string): Promise<ChatQueueState & {
|
|
1051
|
+
runId?: string;
|
|
1052
|
+
}>;
|
|
1053
|
+
update(req: Request, messageId: string, body: UpdateQueuedMessageBody): Promise<ChatQueueState>;
|
|
1054
|
+
remove(req: Request, messageId: string): Promise<ChatQueueState>;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
932
1057
|
/**
|
|
933
1058
|
* The default `TokenStreamSink`: buffers chunks per run in-process so a reconnecting subscriber
|
|
934
1059
|
* replays everything so far, then follows live.
|
|
@@ -1036,4 +1161,4 @@ declare function defaultRequestUserMapper(user: Record<string, unknown>): Actor;
|
|
|
1036
1161
|
*/
|
|
1037
1162
|
declare function requestUserActorResolver<TUser = Record<string, unknown>>(map?: RequestUserMapper<TUser>): ActorResolver;
|
|
1038
1163
|
|
|
1039
|
-
export { 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, ConfigController, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, MAX_ATTACHMENTS_PER_MESSAGE, MemoriesController, MessagesController, ModelsController, type RequestUserMapper, type ResolvedAiToolOptions, 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 };
|
|
1164
|
+
export { 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, 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,7 +1,7 @@
|
|
|
1
1
|
import { DynamicModule, Type, OnApplicationBootstrap, OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, d as AgentSkillsOptions } from './
|
|
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
|
|
4
|
-
import { AgentRunner, AgentStore, AttachmentStagingStore, ModelCatalog, QuotaProvider, Actor, QuotaReport, ModelCatalogView, AttachmentRef, PageContext, 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, TokenStreamSink, SinkWriter } from '@dudousxd/nestjs-agent-core';
|
|
2
|
+
import { b as AgentModuleOptions, c as AgentModuleAsyncOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentSkillsOptions } from './chat-queue.service-Bqq00NN1.js';
|
|
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
|
+
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';
|
|
5
5
|
export * from '@dudousxd/nestjs-agent-core';
|
|
6
6
|
import { Request } from 'express';
|
|
7
7
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
@@ -12,6 +12,34 @@ declare class AgentModule {
|
|
|
12
12
|
static forRootAsync(options: AgentModuleAsyncOptions): DynamicModule;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* What a send does when its thread already has a turn running:
|
|
17
|
+
* - `'auto'` (default) — run now when the thread is idle, else wait in the thread's queue.
|
|
18
|
+
* - `'queue'` — always wait in the queue, behind whatever is already waiting (it still starts at
|
|
19
|
+
* once when nothing is running and nothing is ahead of it).
|
|
20
|
+
* - `'interrupt'` — cancel the running turn and run this one next, ahead of the queue.
|
|
21
|
+
*/
|
|
22
|
+
type ChatSendMode = 'auto' | 'queue' | 'interrupt';
|
|
23
|
+
/** A send that is waiting in its thread's queue instead of running. */
|
|
24
|
+
interface QueuedSend {
|
|
25
|
+
threadId: string;
|
|
26
|
+
queued: true;
|
|
27
|
+
/** The queued message's id — also the run id it will start under. */
|
|
28
|
+
messageId: string;
|
|
29
|
+
/** 0-based place in the queue at the time it was queued (`0` → next). */
|
|
30
|
+
position: number;
|
|
31
|
+
queue: ChatQueueState;
|
|
32
|
+
/** The turn it started under, when it started straight away (an idle thread). */
|
|
33
|
+
runId?: string;
|
|
34
|
+
/** The run an interrupt cancelled to make room for it. */
|
|
35
|
+
interrupting?: string;
|
|
36
|
+
}
|
|
37
|
+
/** What {@link AgentService.send} did: started a turn, or queued the message. */
|
|
38
|
+
type ChatSendResult = {
|
|
39
|
+
runId: string;
|
|
40
|
+
threadId: string;
|
|
41
|
+
queued?: undefined;
|
|
42
|
+
} | QueuedSend;
|
|
15
43
|
interface ChatParams {
|
|
16
44
|
actor: Actor;
|
|
17
45
|
message: string;
|
|
@@ -36,6 +64,8 @@ interface ChatParams {
|
|
|
36
64
|
* the thread list until the caller promotes it. Ignored when `threadId` is set.
|
|
37
65
|
*/
|
|
38
66
|
transient?: boolean;
|
|
67
|
+
/** What to do when the thread already has a turn running — see {@link ChatSendMode}. */
|
|
68
|
+
mode?: ChatSendMode;
|
|
39
69
|
}
|
|
40
70
|
/**
|
|
41
71
|
* A store that can answer a thread's default agent on its own, without materializing the thread.
|
|
@@ -60,7 +90,12 @@ declare class AgentService {
|
|
|
60
90
|
private readonly models?;
|
|
61
91
|
private readonly quotaProvider?;
|
|
62
92
|
private readonly options?;
|
|
63
|
-
|
|
93
|
+
private readonly queue?;
|
|
94
|
+
constructor(runner: AgentRunner, store: AgentStore, deps: AgentDepsFactory, staging?: AttachmentStagingStore | undefined, models?: ModelCatalog | undefined, quotaProvider?: QuotaProvider | undefined, options?: Pick<AgentModuleOptions, "quota"> | undefined, queue?: ChatQueueService | undefined);
|
|
95
|
+
/** The queue service when the bound store can hold a queue, else `undefined`. */
|
|
96
|
+
private queueing;
|
|
97
|
+
/** The queue service, or a 501 naming what is missing. */
|
|
98
|
+
private requireQueue;
|
|
64
99
|
/**
|
|
65
100
|
* The actor's budget across windows (`GET <base>/quota`) — the bound {@link QuotaProvider}'s
|
|
66
101
|
* report. Without one (a service built outside the module), a day window from the ledger.
|
|
@@ -89,10 +124,51 @@ declare class AgentService {
|
|
|
89
124
|
*/
|
|
90
125
|
private resolveModel;
|
|
91
126
|
private threadModel;
|
|
127
|
+
/**
|
|
128
|
+
* Start a turn — for in-process callers that need a run id back. A send that would have to wait
|
|
129
|
+
* (its thread already has a turn running) is refused with `409` instead; {@link send} is the form
|
|
130
|
+
* that queues it.
|
|
131
|
+
*/
|
|
92
132
|
chat(params: ChatParams): Promise<{
|
|
93
133
|
runId: string;
|
|
94
134
|
threadId: string;
|
|
95
135
|
}>;
|
|
136
|
+
/**
|
|
137
|
+
* Send a message: start a turn, or — when its thread already has one running — queue the message
|
|
138
|
+
* to run after it (see {@link ChatSendMode}). What `POST <base>/chat` calls.
|
|
139
|
+
*/
|
|
140
|
+
send(params: ChatParams): Promise<ChatSendResult>;
|
|
141
|
+
/**
|
|
142
|
+
* Start a turn the thread is already claimed for, under the claimed id. A runner that minted an
|
|
143
|
+
* id of its own anyway gets the thread re-pointed at it; one that fails to start frees the thread.
|
|
144
|
+
*/
|
|
145
|
+
private startClaimed;
|
|
146
|
+
/** Put a send in its thread's queue, then drain it if the thread turned out to be free. */
|
|
147
|
+
private enqueue;
|
|
148
|
+
/** `GET <base>/threads/:id/queue` — the thread's waiting messages and whether it drains. */
|
|
149
|
+
getQueue(actor: Actor, threadId: string): Promise<ChatQueueState>;
|
|
150
|
+
/**
|
|
151
|
+
* `PATCH <base>/queue/:messageId` — change a waiting message's text and/or attachments, and/or move
|
|
152
|
+
* it to `position` in the queue. Answers the thread's queue.
|
|
153
|
+
*/
|
|
154
|
+
updateQueuedMessage(actor: Actor, messageId: string, patch: {
|
|
155
|
+
message?: string;
|
|
156
|
+
attachments?: AttachmentRef[] | null;
|
|
157
|
+
position?: number;
|
|
158
|
+
}): Promise<ChatQueueState>;
|
|
159
|
+
/** `DELETE <base>/queue/:messageId` — drop a waiting message. Answers the thread's queue. */
|
|
160
|
+
removeQueuedMessage(actor: Actor, messageId: string): Promise<ChatQueueState>;
|
|
161
|
+
/** `DELETE <base>/threads/:id/queue` — drop every waiting message (and any pause). */
|
|
162
|
+
clearQueue(actor: Actor, threadId: string): Promise<ChatQueueState>;
|
|
163
|
+
/**
|
|
164
|
+
* `POST <base>/threads/:id/queue/resume` — lift a pause and start the head when nothing is
|
|
165
|
+
* running. Answers the queue, and the run the head started under, if it did.
|
|
166
|
+
*/
|
|
167
|
+
resumeQueue(actor: Actor, threadId: string): Promise<ChatQueueState & {
|
|
168
|
+
runId?: string;
|
|
169
|
+
}>;
|
|
170
|
+
/** The thread a queued message waits on, once the caller is shown to own it. */
|
|
171
|
+
private assertOwnsQueuedMessage;
|
|
96
172
|
/**
|
|
97
173
|
* Rebuild this turn's attachments from the staging store, keyed by the ids the caller claimed.
|
|
98
174
|
* The model provider fetches {@link MessageAttachment.url} verbatim, so that url is only ever
|
|
@@ -795,7 +871,11 @@ declare class ToolsController {
|
|
|
795
871
|
private readonly agents;
|
|
796
872
|
constructor(actorResolver: ActorResolver, depsFactory: AgentDepsFactory, agents: AgentRegistry);
|
|
797
873
|
list(req: Request,
|
|
798
|
-
/**
|
|
874
|
+
/**
|
|
875
|
+
* The agent whose tools to list. Omitted → the default agent, the one a turn naming none uses.
|
|
876
|
+
* `*` → every agent's: the union of what this actor reaches through any of them, each tool once
|
|
877
|
+
* — for a surface that shows several agents' conversations.
|
|
878
|
+
*/
|
|
799
879
|
agent?: string): Promise<ToolCatalogEntry[]>;
|
|
800
880
|
}
|
|
801
881
|
|
|
@@ -862,6 +942,7 @@ declare function resolveSkillsConfig(options: AgentSkillsOptions | undefined, de
|
|
|
862
942
|
declare class InlineAgentRunner implements AgentRunner {
|
|
863
943
|
private readonly factory;
|
|
864
944
|
private readonly store;
|
|
945
|
+
private readonly queue?;
|
|
865
946
|
private readonly logger;
|
|
866
947
|
private readonly pending;
|
|
867
948
|
/**
|
|
@@ -870,8 +951,15 @@ declare class InlineAgentRunner implements AgentRunner {
|
|
|
870
951
|
* running it. A cancelled id is dropped once the run settles, so the set tracks live runs only.
|
|
871
952
|
*/
|
|
872
953
|
private readonly cancelled;
|
|
873
|
-
|
|
874
|
-
|
|
954
|
+
/** Top-level runs this process is running now — what {@link isRunActive} answers from. */
|
|
955
|
+
private readonly live;
|
|
956
|
+
constructor(factory: AgentDepsFactory, store: AgentStore, queue?: ChatQueueService | undefined);
|
|
957
|
+
/**
|
|
958
|
+
* In-process, so exact: a run this process is not running is not running anywhere — the process
|
|
959
|
+
* that was running it is gone (a restart), and a thread it still holds is a stale claim.
|
|
960
|
+
*/
|
|
961
|
+
isRunActive(runId: string): Promise<boolean>;
|
|
962
|
+
start(input: AgentRunInput, options?: AgentRunStartOptions): Promise<{
|
|
875
963
|
runId: string;
|
|
876
964
|
}>;
|
|
877
965
|
signal(runId: string, toolCallId: string, reply: HumanReply): Promise<void>;
|
|
@@ -897,6 +985,15 @@ declare class InlineAgentRunner implements AgentRunner {
|
|
|
897
985
|
* streams does not retry this one.
|
|
898
986
|
*/
|
|
899
987
|
private settleCancelled;
|
|
988
|
+
/**
|
|
989
|
+
* Move the thread past a settling TOP-LEVEL run — to the next queued message, which starts here,
|
|
990
|
+
* or to a paused/empty queue — and write the resulting `queue` frame into this run's stream. A
|
|
991
|
+
* no-op without a queue-capable store, and for a run that is not a thread's own turn.
|
|
992
|
+
*
|
|
993
|
+
* Never throws: the run is settling either way, and a queue that could not be advanced is picked
|
|
994
|
+
* up by the next send or resume on the thread.
|
|
995
|
+
*/
|
|
996
|
+
private settleQueue;
|
|
900
997
|
/**
|
|
901
998
|
* Park a run on a human, keyed by run + tool call. One map for approvals and for question-set
|
|
902
999
|
* answers alike: both wait on the same key, and `signal` cannot tell (or need to tell) which
|
|
@@ -929,6 +1026,34 @@ declare class InlineAgentRunner implements AgentRunner {
|
|
|
929
1026
|
private runNested;
|
|
930
1027
|
}
|
|
931
1028
|
|
|
1029
|
+
interface UpdateQueuedMessageBody {
|
|
1030
|
+
/** The new text. */
|
|
1031
|
+
message?: unknown;
|
|
1032
|
+
/** `[{ mediaId }]` refs replacing the message's attachments; `null` or `[]` drops them. */
|
|
1033
|
+
attachments?: unknown;
|
|
1034
|
+
/** Move the message to this 0-based place in the queue. */
|
|
1035
|
+
position?: unknown;
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* The thread message queue: messages sent while a turn was running, waiting to run after it. Every
|
|
1039
|
+
* route is ownership-gated like the thread routes, and answers the thread's queue as it now stands
|
|
1040
|
+
* (`{ items, paused }`). A change is also announced to whoever is streaming the thread, as a `queue`
|
|
1041
|
+
* frame in the running turn's stream.
|
|
1042
|
+
*/
|
|
1043
|
+
declare class QueueController {
|
|
1044
|
+
private readonly agent;
|
|
1045
|
+
private readonly actorResolver;
|
|
1046
|
+
constructor(agent: AgentService, actorResolver: ActorResolver);
|
|
1047
|
+
list(req: Request, id: string): Promise<ChatQueueState>;
|
|
1048
|
+
clear(req: Request, id: string): Promise<ChatQueueState>;
|
|
1049
|
+
/** Lift a pause; the head starts when nothing is running. Carries `runId` when it started. */
|
|
1050
|
+
resume(req: Request, id: string): Promise<ChatQueueState & {
|
|
1051
|
+
runId?: string;
|
|
1052
|
+
}>;
|
|
1053
|
+
update(req: Request, messageId: string, body: UpdateQueuedMessageBody): Promise<ChatQueueState>;
|
|
1054
|
+
remove(req: Request, messageId: string): Promise<ChatQueueState>;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
932
1057
|
/**
|
|
933
1058
|
* The default `TokenStreamSink`: buffers chunks per run in-process so a reconnecting subscriber
|
|
934
1059
|
* replays everything so far, then follows live.
|
|
@@ -1036,4 +1161,4 @@ declare function defaultRequestUserMapper(user: Record<string, unknown>): Actor;
|
|
|
1036
1161
|
*/
|
|
1037
1162
|
declare function requestUserActorResolver<TUser = Record<string, unknown>>(map?: RequestUserMapper<TUser>): ActorResolver;
|
|
1038
1163
|
|
|
1039
|
-
export { 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, ConfigController, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, type DeclaredSkill, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, MAX_ATTACHMENTS_PER_MESSAGE, MemoriesController, MessagesController, ModelsController, type RequestUserMapper, type ResolvedAiToolOptions, 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 };
|
|
1164
|
+
export { 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, 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 };
|