@dudousxd/nestjs-agent 1.36.2 → 1.37.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.
@@ -167,6 +167,22 @@ interface ChatParams {
167
167
  interface ThreadDefaultAgentReader {
168
168
  defaultAgentForThread(threadId: string): Promise<string | null>;
169
169
  }
170
+ /** What {@link AgentService.forkThread} takes past the thread and the message to copy up to. */
171
+ interface ForkThreadParams {
172
+ /**
173
+ * The HOST already decided this actor may read the thread — "continue this conversation" from a
174
+ * link its owner shared. Skips the ownership check, and the copy belongs to the CALLER, not the
175
+ * source's owner; the original is left as it was. Never set it from a request's own claim: the
176
+ * `POST /threads/:id/fork-from/:messageId` route never does, so it stays owner-only.
177
+ */
178
+ authorized?: boolean;
179
+ /**
180
+ * The copy's tenant — see `ForkThreadOptions.tenantRef`. Absent keeps the SOURCE's, even when the
181
+ * copy now belongs to someone else; forking across tenants, pass the caller's
182
+ * (`actor.tenantRef ?? null`). `null` clears it.
183
+ */
184
+ tenantRef?: string | null;
185
+ }
170
186
  /** Like {@link ThreadDefaultAgentReader}, for the thread's pinned model. */
171
187
  interface ThreadModelReader {
172
188
  modelForThread(threadId: string): Promise<string | null>;
@@ -430,7 +446,12 @@ declare class AgentService {
430
446
  listThreads(actorRef: string): Promise<ThreadSummary[]>;
431
447
  getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
432
448
  deleteThread(actor: Actor, threadId: string): Promise<void>;
433
- forkThread(actor: Actor, threadId: string, fromMessageId: string): Promise<ThreadSummary>;
449
+ /**
450
+ * Copy a thread up to `fromMessageId` (inclusive) into a new one. By default only the thread's
451
+ * owner may, and the copy is theirs. With `params.authorized`, the host has vouched for `actor`
452
+ * (a share link it checked) and the copy is `actor`'s — see {@link ForkThreadParams}.
453
+ */
454
+ forkThread(actor: Actor, threadId: string, fromMessageId: string, params?: ForkThreadParams): Promise<ThreadSummary>;
434
455
  /** Kept for source compatibility — a thin wrapper over the more general `updateThread`. */
435
456
  renameThread(actor: Actor, threadId: string, title: string): Promise<void>;
436
457
  /**
@@ -647,4 +668,4 @@ declare class A2uiRunHandler {
647
668
  */
648
669
  declare function a2uiAdapter(options?: A2uiAdapterOptions): AgentProtocolAdapter;
649
670
 
650
- export { AgentService as A, type ChatParams as C, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES as D, MAX_ATTACHMENTS_PER_MESSAGE as M, NO_USER_MESSAGE_CODE as N, type QueuedSend as Q, type ThreadDefaultAgentReader as T, ActionProposalService as a, type A2uiAdapterOptions as b, A2uiRunHandler as c, type AttachmentLimits as d, type ChatSendMode as e, type ChatSendResult as f, DEFAULT_MAX_ATTACHMENT_BYTES as g, type ThreadModelReader as h, a2uiAdapter as i, attachmentLimits as j };
671
+ export { AgentService as A, type ChatParams as C, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES as D, type ForkThreadParams as F, MAX_ATTACHMENTS_PER_MESSAGE as M, NO_USER_MESSAGE_CODE as N, type QueuedSend as Q, type ThreadDefaultAgentReader as T, ActionProposalService as a, type A2uiAdapterOptions as b, A2uiRunHandler as c, type AttachmentLimits as d, type ChatSendMode as e, type ChatSendResult as f, DEFAULT_MAX_ATTACHMENT_BYTES as g, type ThreadModelReader as h, a2uiAdapter as i, attachmentLimits as j };
@@ -167,6 +167,22 @@ interface ChatParams {
167
167
  interface ThreadDefaultAgentReader {
168
168
  defaultAgentForThread(threadId: string): Promise<string | null>;
169
169
  }
170
+ /** What {@link AgentService.forkThread} takes past the thread and the message to copy up to. */
171
+ interface ForkThreadParams {
172
+ /**
173
+ * The HOST already decided this actor may read the thread — "continue this conversation" from a
174
+ * link its owner shared. Skips the ownership check, and the copy belongs to the CALLER, not the
175
+ * source's owner; the original is left as it was. Never set it from a request's own claim: the
176
+ * `POST /threads/:id/fork-from/:messageId` route never does, so it stays owner-only.
177
+ */
178
+ authorized?: boolean;
179
+ /**
180
+ * The copy's tenant — see `ForkThreadOptions.tenantRef`. Absent keeps the SOURCE's, even when the
181
+ * copy now belongs to someone else; forking across tenants, pass the caller's
182
+ * (`actor.tenantRef ?? null`). `null` clears it.
183
+ */
184
+ tenantRef?: string | null;
185
+ }
170
186
  /** Like {@link ThreadDefaultAgentReader}, for the thread's pinned model. */
171
187
  interface ThreadModelReader {
172
188
  modelForThread(threadId: string): Promise<string | null>;
@@ -430,7 +446,12 @@ declare class AgentService {
430
446
  listThreads(actorRef: string): Promise<ThreadSummary[]>;
431
447
  getThread(actor: Actor, threadId: string): Promise<ThreadDetail | null>;
432
448
  deleteThread(actor: Actor, threadId: string): Promise<void>;
433
- forkThread(actor: Actor, threadId: string, fromMessageId: string): Promise<ThreadSummary>;
449
+ /**
450
+ * Copy a thread up to `fromMessageId` (inclusive) into a new one. By default only the thread's
451
+ * owner may, and the copy is theirs. With `params.authorized`, the host has vouched for `actor`
452
+ * (a share link it checked) and the copy is `actor`'s — see {@link ForkThreadParams}.
453
+ */
454
+ forkThread(actor: Actor, threadId: string, fromMessageId: string, params?: ForkThreadParams): Promise<ThreadSummary>;
434
455
  /** Kept for source compatibility — a thin wrapper over the more general `updateThread`. */
435
456
  renameThread(actor: Actor, threadId: string, title: string): Promise<void>;
436
457
  /**
@@ -647,4 +668,4 @@ declare class A2uiRunHandler {
647
668
  */
648
669
  declare function a2uiAdapter(options?: A2uiAdapterOptions): AgentProtocolAdapter;
649
670
 
650
- export { AgentService as A, type ChatParams as C, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES as D, MAX_ATTACHMENTS_PER_MESSAGE as M, NO_USER_MESSAGE_CODE as N, type QueuedSend as Q, type ThreadDefaultAgentReader as T, ActionProposalService as a, type A2uiAdapterOptions as b, A2uiRunHandler as c, type AttachmentLimits as d, type ChatSendMode as e, type ChatSendResult as f, DEFAULT_MAX_ATTACHMENT_BYTES as g, type ThreadModelReader as h, a2uiAdapter as i, attachmentLimits as j };
671
+ export { AgentService as A, type ChatParams as C, DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES as D, type ForkThreadParams as F, MAX_ATTACHMENTS_PER_MESSAGE as M, NO_USER_MESSAGE_CODE as N, type QueuedSend as Q, type ThreadDefaultAgentReader as T, ActionProposalService as a, type A2uiAdapterOptions as b, A2uiRunHandler as c, type AttachmentLimits as d, type ChatSendMode as e, type ChatSendResult as f, DEFAULT_MAX_ATTACHMENT_BYTES as g, type ThreadModelReader as h, a2uiAdapter as i, attachmentLimits as j };
package/dist/index.cjs CHANGED
@@ -2550,9 +2550,28 @@ var AgentService2 = class {
2550
2550
  await this.assertOwnsThread(actor, threadId);
2551
2551
  return this.store.softDeleteThread(threadId);
2552
2552
  }
2553
- async forkThread(actor, threadId, fromMessageId) {
2554
- await this.assertOwnsThread(actor, threadId);
2555
- return this.store.forkThread(threadId, fromMessageId);
2553
+ /**
2554
+ * Copy a thread up to `fromMessageId` (inclusive) into a new one. By default only the thread's
2555
+ * owner may, and the copy is theirs. With `params.authorized`, the host has vouched for `actor`
2556
+ * (a share link it checked) and the copy is `actor`'s — see {@link ForkThreadParams}.
2557
+ */
2558
+ async forkThread(actor, threadId, fromMessageId, params = {}) {
2559
+ if (params.authorized === true) {
2560
+ if (await this.store.ownerOfThread(threadId) === null) {
2561
+ throw new import_common6.NotFoundException(`thread ${threadId} not found`);
2562
+ }
2563
+ } else {
2564
+ await this.assertOwnsThread(actor, threadId);
2565
+ }
2566
+ const options = {
2567
+ ...params.authorized === true ? {
2568
+ actorRef: actor.id
2569
+ } : {},
2570
+ ...params.tenantRef !== void 0 ? {
2571
+ tenantRef: params.tenantRef
2572
+ } : {}
2573
+ };
2574
+ return this.store.forkThread(threadId, fromMessageId, options);
2556
2575
  }
2557
2576
  /** Kept for source compatibility — a thin wrapper over the more general `updateThread`. */
2558
2577
  async renameThread(actor, threadId, title) {