@musnows/scriverse 1.0.2 → 1.0.3

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/ai.js CHANGED
@@ -5259,7 +5259,7 @@ export class AiManager {
5259
5259
  ...(conversationMessage ? { conversationMessage } : {})
5260
5260
  };
5261
5261
  }
5262
- async resumeUserQuestion(input) {
5262
+ async resumeUserQuestion(input, stream = {}) {
5263
5263
  const answeredItems = (input.answers ?? []).map((answer) => ({
5264
5264
  question: String(answer.question ?? ""),
5265
5265
  answer: String(answer.answer ?? ""),
@@ -5292,7 +5292,20 @@ export class AiManager {
5292
5292
  round: input.round,
5293
5293
  toolMessages: input.toolMessages
5294
5294
  });
5295
+ stream.onStart?.({
5296
+ conversationId: input.conversationId,
5297
+ messageId: toolContinuation.assistantMessageId,
5298
+ toolCalls: toolContinuation.previousToolCalls.map((toolCall) => toolCall.id === toolCallId ? { ...toolCall, result: toolResult } : toolCall),
5299
+ processSteps: toolContinuation.previousProcessSteps.map((step) => step.type === "tool" && step.toolCall.id === toolCallId
5300
+ ? { ...step, toolCall: { ...step.toolCall, result: toolResult } }
5301
+ : step),
5302
+ processDurationMs: toolContinuation.previousProcessDurationMs
5303
+ });
5295
5304
  return this.createStreamingChat({
5305
+ signal: stream.signal,
5306
+ onToolCall: stream.onToolCall,
5307
+ onProcessStep: stream.onProcessStep,
5308
+ onContextCompacted: stream.onContextCompacted,
5296
5309
  workId: input.workId,
5297
5310
  conversationId: input.conversationId,
5298
5311
  assistantMessageRequestId: toolContinuation.assistantMessageRequestId,
@@ -5301,7 +5314,7 @@ export class AiManager {
5301
5314
  ...(input.modelId ? { modelId: input.modelId } : {}),
5302
5315
  disableTools: input.status !== "answered",
5303
5316
  toolContinuation
5304
- }, () => undefined);
5317
+ }, stream.onDelta ?? (() => undefined));
5305
5318
  }
5306
5319
  resolveQuestionToolContinuation(input) {
5307
5320
  const rows = this.store.db.all(`SELECT id, request_id, metadata_json FROM ai_conversation_messages
@@ -5447,7 +5460,11 @@ export class AiManager {
5447
5460
  });
5448
5461
  }
5449
5462
  catch (error) {
5450
- const failure = error instanceof Error ? error.message : "一致性检查失败";
5463
+ const errorDetails = error instanceof AppError && error.details && typeof error.details === "object"
5464
+ ? error.details
5465
+ : null;
5466
+ const detailedFailure = typeof errorDetails?.failure === "string" ? errorDetails.failure.trim() : "";
5467
+ const failure = detailedFailure || (error instanceof Error ? error.message : "一致性检查失败");
5451
5468
  const callId = error instanceof AppError && error.details && typeof error.details === "object" && "callId" in error.details
5452
5469
  ? String(error.details.callId)
5453
5470
  : null;
@@ -8910,7 +8927,7 @@ export class AiManager {
8910
8927
  let totalCachedInputTokens = 0;
8911
8928
  const processSteps = [];
8912
8929
  const completionDelivery = new WeakMap();
8913
- let streamingGenerationRound = 0;
8930
+ let streamingGenerationRound = input.toolContinuation?.round ?? 0;
8914
8931
  const requestCompletion = async (toolChoice, options = {}) => {
8915
8932
  const requestMessages = options.messages ?? completionMessages;
8916
8933
  const requestParameters = options.parameters ?? parameters;