@musnows/scriverse 0.8.0 → 0.8.1

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
@@ -5617,6 +5617,7 @@ export class AiManager {
5617
5617
  });
5618
5618
  let activeSecrets = [];
5619
5619
  let streamedContent = "";
5620
+ let streamedPartialContent = "";
5620
5621
  let trackedInputTokens = 0;
5621
5622
  let trackedOutputTokens = 0;
5622
5623
  let trackedCachedInputTokens = 0;
@@ -5694,6 +5695,7 @@ export class AiManager {
5694
5695
  traceRound.attempts.push(traceAttempt);
5695
5696
  saveTrace();
5696
5697
  logger.info("ai.call.attempt_started", { callId, attempt, maximumAttempts, toolChoice, purpose });
5698
+ let streamedRoundContent = "";
5697
5699
  try {
5698
5700
  const candidate = await this.scheduleProviderRequest(provider, input.signal, async () => {
5699
5701
  const controller = new AbortController();
@@ -5748,7 +5750,8 @@ export class AiManager {
5748
5750
  }
5749
5751
  const payload = await this.readCompletionStream(response, protocol, activeSecrets, (delta) => {
5750
5752
  attemptEmitted = true;
5751
- streamedContent += delta;
5753
+ streamedRoundContent += delta;
5754
+ streamedPartialContent += delta;
5752
5755
  onDelta?.(delta);
5753
5756
  }, (delta) => {
5754
5757
  attemptEmitted = true;
@@ -5801,6 +5804,23 @@ export class AiManager {
5801
5804
  if (candidate.ok) {
5802
5805
  const parsed = candidate.payload;
5803
5806
  completionDelivery.set(parsed, candidate.delivery);
5807
+ if (candidate.delivery === "sse" && purpose === "generation" && streamedRoundContent.length > 0) {
5808
+ const currentChoice = parsed.choices?.[0];
5809
+ if (currentChoice?.message?.tool_calls?.length) {
5810
+ const step = {
5811
+ id: id("process"),
5812
+ type: "intermediate",
5813
+ round: processRound,
5814
+ content: streamedRoundContent,
5815
+ createdAt: now()
5816
+ };
5817
+ processSteps.push(step);
5818
+ input.onProcessStep?.(step);
5819
+ }
5820
+ else {
5821
+ streamedContent += streamedRoundContent;
5822
+ }
5823
+ }
5804
5824
  traceAttempt.completedAt = now();
5805
5825
  traceAttempt.status = "completed";
5806
5826
  traceAttempt.httpStatus = candidate.status;
@@ -6141,7 +6161,7 @@ export class AiManager {
6141
6161
  SET status = 'failed', failure = ?, output_chars = ?, input_tokens = ?, output_tokens = ?,
6142
6162
  cached_input_tokens = ?, cache_eligible_input_tokens = ?, cache_usage_available = ?,
6143
6163
  token_usage_source = ?, completed_at = ?
6144
- WHERE id = ?`, message, streamedContent.length, trackedInputTokens, trackedOutputTokens, trackedCachedInputTokens, trackedCacheEligibleInputTokens, trackedCacheEligibleInputTokens > 0 ? 1 : 0, trackedUsageSource(), now(), callId);
6164
+ WHERE id = ?`, message, (streamedPartialContent || streamedContent).length, trackedInputTokens, trackedOutputTokens, trackedCachedInputTokens, trackedCacheEligibleInputTokens, trackedCacheEligibleInputTokens > 0 ? 1 : 0, trackedUsageSource(), now(), callId);
6145
6165
  logger.error("ai.call.failed", {
6146
6166
  callId,
6147
6167
  workId: input.workId,