@dudousxd/nestjs-agent 0.5.0 → 0.7.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.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DynamicModule, OnModuleInit, Type, OnApplicationBootstrap } from '@nestjs/common';
2
- import { a as AgentModuleOptions, b as AgentModuleAsyncOptions, A as AgentDepsFactory } from './agent-deps.factory-DGM0IVtA.cjs';
3
- export { c as AGENT_TOOL_BRAND, d as AgentAttachmentsOptions, e as AgentDeps, F as FunctionalTool, f as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-DGM0IVtA.cjs';
4
- import { AgentRunner, AgentStore, QuotaStore, Actor, MessageAttachment, PageContext, ThreadSummary, ThreadDetail, UpdateThreadInput, QuotaView, ActorResolver, AttachmentStagingStore, ToolRegistry, AgentRegistry, PromptContributor, AgentRunInput, Decision, TokenStreamSink, SinkWriter, QuotaState } from '@dudousxd/nestjs-agent-core';
2
+ import { a as AgentModuleOptions, b as AgentModuleAsyncOptions, A as AgentDepsFactory } from './agent-deps.factory-BlC9tumI.cjs';
3
+ export { c as AGENT_TOOL_BRAND, d as AgentAttachmentsOptions, e as AgentDeps, F as FunctionalTool, f as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-BlC9tumI.cjs';
4
+ import { AgentRunner, AgentStore, QuotaStore, Actor, MessageAttachment, PageContext, Decision, ThreadSummary, ThreadDetail, UpdateThreadInput, QuotaView, AgentApprovalPort, ActorResolver, AttachmentStagingStore, ToolRegistry, AgentRegistry, PromptContributor, AgentRunInput, TokenStreamSink, SinkWriter, QuotaState } 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';
@@ -42,6 +42,15 @@ declare class AgentService {
42
42
  subscribe(runId: string): AsyncIterable<Uint8Array>;
43
43
  approve(actor: Actor, toolCallId: string): Promise<void>;
44
44
  reject(actor: Actor, toolCallId: string, reason?: string): Promise<void>;
45
+ /**
46
+ * The decision core behind approve/reject, WITHOUT an ownership check: resolves the run
47
+ * currently awaiting `toolCallId` and signals it. `approve`/`reject` above call this after their
48
+ * own `assertOwnsToolCall` gate; the console `AgentApprovalPort` adapter (bound by `AgentModule`)
49
+ * calls it directly — a console caller is already authorized by the dashboard's own guards, and
50
+ * re-deriving thread ownership here would reject a legitimate operator decision (an operator is
51
+ * not the thread's own actor).
52
+ */
53
+ signalToolCall(toolCallId: string, decision: Decision): Promise<void>;
45
54
  cancel(actor: Actor, runId: string): Promise<void>;
46
55
  listThreads(actorRef: string): Promise<ThreadSummary[]>;
47
56
  getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
@@ -84,16 +93,46 @@ declare class AgentService {
84
93
  */
85
94
  private assertOwnsThread;
86
95
  /**
87
- * Authorization + routing seam for HITL approve/reject: assert the caller owns the tool call's
88
- * thread, then resolve the run currently awaiting that call (its thread's active stream). That run
89
- * is the sub-agent's own child run when the pending call belongs to a delegated agent — the client
90
- * never knows or supplies a runId; it is derived here from the tool call alone.
96
+ * Authorization seam for HITL approve/reject: the caller must own the tool call's thread. Split
97
+ * out from run resolution (see {@link resolveRunForToolCall}) so the console `AgentApprovalPort`
98
+ * adapter can resolve+signal a decision WITHOUT this check — it is authorized upstream instead.
91
99
  */
92
- private runForOwnedToolCall;
100
+ private assertOwnsToolCall;
101
+ /**
102
+ * Resolve the run currently awaiting `toolCallId` (its thread's active stream). That run is the
103
+ * sub-agent's own child run when the pending call belongs to a delegated agent — the client never
104
+ * knows or supplies a runId; it is derived here from the tool call alone.
105
+ */
106
+ private resolveRunForToolCall;
93
107
  /** Authorization seam for `cancel`: the caller must own the thread currently streaming this run. */
94
108
  private assertOwnsActiveStream;
95
109
  }
96
110
 
111
+ /**
112
+ * Binds `AGENT_APPROVAL_PORT` for the console's cross-thread approvals inbox to the SAME decision
113
+ * path chat approvals use — `AgentService.signalToolCall` (resolve the run awaiting `toolCallId`,
114
+ * then `AgentRunner.signal`, which is either the inline pending-promise map or the durable signal
115
+ * `tool:<runId>:<callId>`, depending on how the host configured `AgentModule`).
116
+ *
117
+ * Deliberately WITHOUT `AgentService.approve`/`reject`'s ownership check: a console caller reaches
118
+ * this port only through the dashboard's own guards (already authorized), not as the thread's own
119
+ * actor — re-deriving "does this actor own the thread" here would reject a legitimate operator
120
+ * decision. `opts.executedByRef` is an OPAQUE decider ref, not re-authorized against anything: it
121
+ * rides the `Decision` and the loop records it as the tool call's decider
122
+ * (`decision.executedByRef ?? input.actor.id`, on both the executed and rejected paths).
123
+ */
124
+ declare class AgentApprovalPortAdapter implements AgentApprovalPort {
125
+ private readonly agent;
126
+ constructor(agent: AgentService);
127
+ approve(toolCallId: string, opts?: {
128
+ executedByRef?: string;
129
+ }): Promise<void>;
130
+ reject(toolCallId: string, opts?: {
131
+ executedByRef?: string;
132
+ reason?: string;
133
+ }): Promise<void>;
134
+ }
135
+
97
136
  /** Default per-file size cap when `AgentModuleOptions.attachments.maxBytes` is omitted (20 MiB). */
98
137
  declare const DEFAULT_MAX_ATTACHMENT_BYTES: number;
99
138
  /**
@@ -332,4 +371,4 @@ declare class HeaderActorResolver implements ActorResolver {
332
371
  resolve(req: unknown): Actor;
333
372
  }
334
373
 
335
- export { AGENT_METADATA, AI_TOOL_METADATA, Agent, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AiTool, AiToolDiscoveryService, type AiToolOptions, AttachmentsController, type ChatParams, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, SystemPrompt, SystemPromptContributor, readAgentMetadata, readAiToolMetadata };
374
+ export { AGENT_METADATA, AI_TOOL_METADATA, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AiTool, AiToolDiscoveryService, type AiToolOptions, AttachmentsController, type ChatParams, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, SystemPrompt, SystemPromptContributor, readAgentMetadata, readAiToolMetadata };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DynamicModule, OnModuleInit, Type, OnApplicationBootstrap } from '@nestjs/common';
2
- import { a as AgentModuleOptions, b as AgentModuleAsyncOptions, A as AgentDepsFactory } from './agent-deps.factory-DGM0IVtA.js';
3
- export { c as AGENT_TOOL_BRAND, d as AgentAttachmentsOptions, e as AgentDeps, F as FunctionalTool, f as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-DGM0IVtA.js';
4
- import { AgentRunner, AgentStore, QuotaStore, Actor, MessageAttachment, PageContext, ThreadSummary, ThreadDetail, UpdateThreadInput, QuotaView, ActorResolver, AttachmentStagingStore, ToolRegistry, AgentRegistry, PromptContributor, AgentRunInput, Decision, TokenStreamSink, SinkWriter, QuotaState } from '@dudousxd/nestjs-agent-core';
2
+ import { a as AgentModuleOptions, b as AgentModuleAsyncOptions, A as AgentDepsFactory } from './agent-deps.factory-BlC9tumI.js';
3
+ export { c as AGENT_TOOL_BRAND, d as AgentAttachmentsOptions, e as AgentDeps, F as FunctionalTool, f as delegateToolName, p as provideAgentTool, u as utcDay } from './agent-deps.factory-BlC9tumI.js';
4
+ import { AgentRunner, AgentStore, QuotaStore, Actor, MessageAttachment, PageContext, Decision, ThreadSummary, ThreadDetail, UpdateThreadInput, QuotaView, AgentApprovalPort, ActorResolver, AttachmentStagingStore, ToolRegistry, AgentRegistry, PromptContributor, AgentRunInput, TokenStreamSink, SinkWriter, QuotaState } 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';
@@ -42,6 +42,15 @@ declare class AgentService {
42
42
  subscribe(runId: string): AsyncIterable<Uint8Array>;
43
43
  approve(actor: Actor, toolCallId: string): Promise<void>;
44
44
  reject(actor: Actor, toolCallId: string, reason?: string): Promise<void>;
45
+ /**
46
+ * The decision core behind approve/reject, WITHOUT an ownership check: resolves the run
47
+ * currently awaiting `toolCallId` and signals it. `approve`/`reject` above call this after their
48
+ * own `assertOwnsToolCall` gate; the console `AgentApprovalPort` adapter (bound by `AgentModule`)
49
+ * calls it directly — a console caller is already authorized by the dashboard's own guards, and
50
+ * re-deriving thread ownership here would reject a legitimate operator decision (an operator is
51
+ * not the thread's own actor).
52
+ */
53
+ signalToolCall(toolCallId: string, decision: Decision): Promise<void>;
45
54
  cancel(actor: Actor, runId: string): Promise<void>;
46
55
  listThreads(actorRef: string): Promise<ThreadSummary[]>;
47
56
  getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
@@ -84,16 +93,46 @@ declare class AgentService {
84
93
  */
85
94
  private assertOwnsThread;
86
95
  /**
87
- * Authorization + routing seam for HITL approve/reject: assert the caller owns the tool call's
88
- * thread, then resolve the run currently awaiting that call (its thread's active stream). That run
89
- * is the sub-agent's own child run when the pending call belongs to a delegated agent — the client
90
- * never knows or supplies a runId; it is derived here from the tool call alone.
96
+ * Authorization seam for HITL approve/reject: the caller must own the tool call's thread. Split
97
+ * out from run resolution (see {@link resolveRunForToolCall}) so the console `AgentApprovalPort`
98
+ * adapter can resolve+signal a decision WITHOUT this check — it is authorized upstream instead.
91
99
  */
92
- private runForOwnedToolCall;
100
+ private assertOwnsToolCall;
101
+ /**
102
+ * Resolve the run currently awaiting `toolCallId` (its thread's active stream). That run is the
103
+ * sub-agent's own child run when the pending call belongs to a delegated agent — the client never
104
+ * knows or supplies a runId; it is derived here from the tool call alone.
105
+ */
106
+ private resolveRunForToolCall;
93
107
  /** Authorization seam for `cancel`: the caller must own the thread currently streaming this run. */
94
108
  private assertOwnsActiveStream;
95
109
  }
96
110
 
111
+ /**
112
+ * Binds `AGENT_APPROVAL_PORT` for the console's cross-thread approvals inbox to the SAME decision
113
+ * path chat approvals use — `AgentService.signalToolCall` (resolve the run awaiting `toolCallId`,
114
+ * then `AgentRunner.signal`, which is either the inline pending-promise map or the durable signal
115
+ * `tool:<runId>:<callId>`, depending on how the host configured `AgentModule`).
116
+ *
117
+ * Deliberately WITHOUT `AgentService.approve`/`reject`'s ownership check: a console caller reaches
118
+ * this port only through the dashboard's own guards (already authorized), not as the thread's own
119
+ * actor — re-deriving "does this actor own the thread" here would reject a legitimate operator
120
+ * decision. `opts.executedByRef` is an OPAQUE decider ref, not re-authorized against anything: it
121
+ * rides the `Decision` and the loop records it as the tool call's decider
122
+ * (`decision.executedByRef ?? input.actor.id`, on both the executed and rejected paths).
123
+ */
124
+ declare class AgentApprovalPortAdapter implements AgentApprovalPort {
125
+ private readonly agent;
126
+ constructor(agent: AgentService);
127
+ approve(toolCallId: string, opts?: {
128
+ executedByRef?: string;
129
+ }): Promise<void>;
130
+ reject(toolCallId: string, opts?: {
131
+ executedByRef?: string;
132
+ reason?: string;
133
+ }): Promise<void>;
134
+ }
135
+
97
136
  /** Default per-file size cap when `AgentModuleOptions.attachments.maxBytes` is omitted (20 MiB). */
98
137
  declare const DEFAULT_MAX_ATTACHMENT_BYTES: number;
99
138
  /**
@@ -332,4 +371,4 @@ declare class HeaderActorResolver implements ActorResolver {
332
371
  resolve(req: unknown): Actor;
333
372
  }
334
373
 
335
- export { AGENT_METADATA, AI_TOOL_METADATA, Agent, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AiTool, AiToolDiscoveryService, type AiToolOptions, AttachmentsController, type ChatParams, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, SystemPrompt, SystemPromptContributor, readAgentMetadata, readAiToolMetadata };
374
+ export { AGENT_METADATA, AI_TOOL_METADATA, Agent, AgentApprovalPortAdapter, AgentDepsFactory, AgentDiscoveryService, AgentModule, AgentModuleAsyncOptions, AgentModuleOptions, type AgentOptions, AgentService, AiTool, AiToolDiscoveryService, type AiToolOptions, AttachmentsController, type ChatParams, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES, DEFAULT_MAX_ATTACHMENT_BYTES, HeaderActorResolver, InProcessTokenStreamSink, InlineAgentRunner, LedgerQuotaStore, SYSTEM_PROMPT_CONTRIBUTOR_METADATA, SYSTEM_PROMPT_METADATA, SystemPrompt, SystemPromptContributor, readAgentMetadata, readAiToolMetadata };