@dsh-enhanced/assistant-delivery 0.1.63 → 0.1.64

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/lib/service.js CHANGED
@@ -67,6 +67,7 @@ const goalOutcomeFeedbackFooter = [
67
67
  ].join('\n');
68
68
  const goalWakeCompletionNotice = '目标已通过独立验收并完成。';
69
69
  const interruptedTurnNotice = '这次请求在执行过程中被中断,当前已停止等待;已有操作的结果尚未确认,因此没有自动重跑。你可以继续发送消息;涉及写入的任务需要先核对现有结果。';
70
+ const timedOutTurnNotice = '这次请求等待超时;已有操作的结果尚未确认,因此不会自动重跑。';
70
71
  function isGoalOutcomeFeedbackAuthority(value) {
71
72
  return typeof value === 'object' && value !== null
72
73
  && typeof value.issueOwnerGoalOutcomeFeedbackTarget === 'function'
@@ -282,6 +283,7 @@ const configSchema = Schema.object({
282
283
  })]),
283
284
  schedulerEnabled: Schema.boolean().default(true),
284
285
  tickIntervalMs: Schema.number().step(1).min(100).default(1_000),
286
+ agentTaskTimeoutMs: Schema.number().step(1).min(1_000).max(86_400_000).default(1_800_000),
285
287
  leaseMs: Schema.number().step(1).min(1_000).default(30_000),
286
288
  maxAttempts: Schema.number().step(1).min(1).max(100).default(5),
287
289
  maxConcurrency: Schema.number().step(1).min(1).max(100).default(4),
@@ -737,6 +739,24 @@ export class AssistantDeliveryService extends Service {
737
739
  return;
738
740
  this.deliveryStore.recordReceipt(receipt);
739
741
  },
742
+ progressJournal: {
743
+ begin: async (intent, fingerprint, sequence, showDetails) => this.progressAuthorized(intent)
744
+ ? this.deliveryStore.beginProgress(intent, fingerprint, sequence, showDetails) : undefined,
745
+ get: async (intent, fingerprint) => this.progressAuthorized(intent)
746
+ ? this.deliveryStore.getProgress(intent, fingerprint) : undefined,
747
+ created: async (intent, fingerprint, handle) => this.progressAuthorized(intent)
748
+ ? this.deliveryStore.attachProgressHandle(intent, fingerprint, handle) : undefined,
749
+ advance: async (intent, fingerprint) => this.progressAuthorized(intent)
750
+ ? this.deliveryStore.advanceProgress(intent, fingerprint) : undefined,
751
+ stageTerminal: async (intent, fingerprint) => this.progressAuthorized(intent)
752
+ ? this.deliveryStore.stageProgressTerminal(intent, fingerprint) : undefined,
753
+ delivered: async (intent, fingerprint) => {
754
+ if (this.progressAuthorized(intent))
755
+ this.deliveryStore.confirmProgressTerminal(intent, fingerprint);
756
+ },
757
+ recover: async (channel, account, fingerprint, limit) => this.active
758
+ ? this.deliveryStore.recoverProgress(channel, account, fingerprint, limit, (binding, inbox) => this.isInboundAuthorized(binding, inbox.envelope)) : [],
759
+ },
740
760
  });
741
761
  const imageMaterializer = new InboundImageMaterializer({
742
762
  store: this.deliveryStore,
@@ -782,6 +802,7 @@ export class AssistantDeliveryService extends Service {
782
802
  readOwnerApprovalStatus: agent => this.readOwnerApprovalStatus(agent),
783
803
  provider: config.agentProvider, model: config.agentModel, maxOutputTokens: config.agentMaxOutputTokens,
784
804
  maxAutoContinuationTurns: config.agentMaxAutoContinuationTurns,
805
+ taskTimeoutMs: config.agentTaskTimeoutMs,
785
806
  goalContinuationTimeoutMs: config.agentGoalContinuationTimeoutMs,
786
807
  maxTextBytes: config.maxTextBytes,
787
808
  prepareForegroundTaskAcceptance: (binding, envelope) => this.prepareForegroundTaskAcceptance(binding, envelope),
@@ -2650,6 +2671,14 @@ export class AssistantDeliveryService extends Service {
2650
2671
  void this.drainDeliveryPresentations();
2651
2672
  return stored;
2652
2673
  }
2674
+ progressAuthorized(intent) {
2675
+ if (!this.active)
2676
+ return false;
2677
+ const inbox = this.deliveryStore.getInboxByProviderEvent(intent.target.conversation.channel, intent.target.conversation.account, intent.eventId);
2678
+ const binding = this.deliveryStore.getBinding(intent.bindingId);
2679
+ return inbox !== undefined && binding !== undefined && inbox.bindingId === binding.id
2680
+ && this.isInboundAuthorized(binding, inbox.envelope);
2681
+ }
2653
2682
  isInboundAuthorized(binding, envelope) {
2654
2683
  if (!this.active)
2655
2684
  return false;
@@ -4124,7 +4153,9 @@ export class AssistantDeliveryService extends Service {
4124
4153
  const inboxId = key.slice('inbound:'.length, -':interrupted'.length);
4125
4154
  const inbox = this.deliveryStore.getInbox(inboxId);
4126
4155
  const binding = this.deliveryStore.getBinding(record.intent.bindingId);
4127
- if (record.intent.text !== interruptedTurnNotice || inbox === undefined || binding === undefined
4156
+ const expectedNotice = inbox?.failureCode === 'agent-task-timeout'
4157
+ ? timedOutTurnNotice : interruptedTurnNotice;
4158
+ if (record.intent.text !== expectedNotice || inbox === undefined || binding === undefined
4128
4159
  || !this.deliveryStore.canSendInterruptedInboxNotice(record)
4129
4160
  || !this.isInboundAuthorized(binding, inbox.envelope)) {
4130
4161
  throw new Error('interrupted Inbox authority changed');
@@ -5274,7 +5305,8 @@ export class AssistantDeliveryService extends Service {
5274
5305
  this.interruptedInboxNoticeAfterSequence = inbox.admissionCursor.sequence;
5275
5306
  try {
5276
5307
  const current = this.deliveryStore.getInbox(inbox.id);
5277
- if (current?.status !== 'dead_letter' || current.failureCode !== 'dispatch-ambiguous'
5308
+ if (current?.status !== 'dead_letter'
5309
+ || (current.failureCode !== 'dispatch-ambiguous' && current.failureCode !== 'agent-task-timeout')
5278
5310
  || current.bindingId === undefined
5279
5311
  || this.deliveryStore.getDeadLetterResolution({ kind: 'inbox', id: current.id,
5280
5312
  attemptCount: current.attemptCount }) !== undefined
@@ -5290,7 +5322,8 @@ export class AssistantDeliveryService extends Service {
5290
5322
  || this.registry.get(binding.conversation.channel, binding.conversation.account) === undefined)
5291
5323
  continue;
5292
5324
  this.replyCommand(binding, { idempotencyKey: `inbound:${current.id}:interrupted`,
5293
- interruptedInboxId: current.id, replyToEventId: current.eventId, text: interruptedTurnNotice });
5325
+ interruptedInboxId: current.id, replyToEventId: current.eventId,
5326
+ text: current.failureCode === 'agent-task-timeout' ? timedOutTurnNotice : interruptedTurnNotice });
5294
5327
  }
5295
5328
  catch (error) {
5296
5329
  if (!this.active)