@docyrus/docyrus 0.0.71 → 0.0.72

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docyrus/docyrus",
3
- "version": "0.0.71",
3
+ "version": "0.0.72",
4
4
  "private": false,
5
5
  "description": "Docyrus API CLI",
6
6
  "main": "./main.js",
package/server-loader.js CHANGED
@@ -45366,88 +45366,11 @@ async function createAgentServer(params) {
45366
45366
  modelIdsByProvider: getModelIdsByProvider()
45367
45367
  });
45368
45368
  }
45369
- app.use("/*", cors({ origin: "*" }));
45370
- app.use("/*", async (c, next) => {
45371
- const unauthorizedResponse = authorizeServerRequest(c.req.raw, authToken);
45372
- if (unauthorizedResponse) {
45373
- return unauthorizedResponse;
45374
- }
45375
- await next();
45376
- });
45377
- app.get("/api/health", (c) => {
45378
- return c.json({ ok: true });
45379
- });
45380
- app.get("/api/status", (c) => {
45381
- return c.json({
45382
- isStreaming: activeSession.isStreaming,
45383
- model: activeSession.model ? { provider: activeSession.model.provider, id: activeSession.model.id } : null,
45384
- mode: sessionMode
45385
- });
45386
- });
45387
- app.post("/api/chat", async (c) => {
45388
- const body2 = await c.req.json();
45389
- const messages = body2.messages ?? [];
45390
- if (body2.sessionId && body2.sessionId.trim() !== activeSession.id?.trim()) {
45391
- try {
45392
- activeSession = await onResumeSession(body2.sessionId);
45393
- sessionMode = "normal";
45394
- } catch (error48) {
45395
- const msg = error48 instanceof Error ? error48.message : String(error48);
45396
- return c.json({ error: `Failed to resume session: ${msg}` }, 400);
45397
- }
45398
- }
45399
- const chatUnavailableReason = getChatUnavailableReason({ session: activeSession });
45400
- if (chatUnavailableReason) {
45401
- return c.json({ error: chatUnavailableReason }, 409);
45402
- }
45403
- const sessionId = body2.sessionId?.trim() || activeSession.id?.trim() || "active";
45404
- const askUserResponse = extractAskUserToolResponse(messages);
45405
- const pendingAskUser = pendingAskUserRequests.get(sessionId);
45406
- const userMessage = askUserResponse ? pendingAskUser && pendingAskUser.toolCallId === askUserResponse.toolCallId ? formatAskUserResponsePrompt(askUserResponse.response) : void 0 : extractLastUserText(messages);
45407
- if (!userMessage) {
45408
- return c.json({
45409
- error: askUserResponse ? "No matching pending ask_user request found" : "No user message found"
45410
- }, 400);
45411
- }
45412
- if (askUserResponse) {
45413
- pendingAskUserRequests.delete(sessionId);
45414
- }
45415
- let promptText = userMessage;
45416
- if (!askUserResponse) {
45417
- const modeCmd = parseModeSlashCommand(userMessage);
45418
- if (modeCmd) {
45419
- if (activeSession.isStreaming) {
45420
- await activeSession.abort();
45421
- await waitForIdle(activeSession);
45422
- }
45423
- await activeSession.prompt(`/${modeCmd.command}`);
45424
- sessionMode = SESSION_MODE_COMMANDS[modeCmd.command] ?? sessionMode;
45425
- if (!modeCmd.remainder) {
45426
- const notifEncoder = new TextEncoder();
45427
- const notifMessageId = generateMessageId();
45428
- return c.body(
45429
- makeModeNotificationStream({ command: modeCmd.command, messageId: notifMessageId, encoder: notifEncoder }),
45430
- {
45431
- headers: {
45432
- "Content-Type": "text/event-stream",
45433
- "Cache-Control": "no-cache",
45434
- "Connection": "keep-alive",
45435
- "x-vercel-ai-ui-message-stream": "v1"
45436
- }
45437
- }
45438
- );
45439
- }
45440
- promptText = modeCmd.remainder;
45441
- }
45442
- }
45443
- if (activeSession.isStreaming) {
45444
- await activeSession.abort();
45445
- await waitForIdle(activeSession);
45446
- }
45369
+ function createPromptStreamResponse(promptText, sessionId) {
45447
45370
  const messageId = generateMessageId();
45448
45371
  const encoder = new TextEncoder();
45449
45372
  const stream = new ReadableStream({
45450
- start(controller) {
45373
+ async start(controller) {
45451
45374
  let closed = false;
45452
45375
  function writeChunk(chunk) {
45453
45376
  if (closed) {
@@ -45471,6 +45394,10 @@ async function createAgentServer(params) {
45471
45394
  } catch {
45472
45395
  }
45473
45396
  }
45397
+ if (activeSession.isStreaming) {
45398
+ await activeSession.abort();
45399
+ await waitForIdle(activeSession);
45400
+ }
45474
45401
  writeChunk({ type: "start" });
45475
45402
  writeChunk({ type: "start-step" });
45476
45403
  let extensionUICleanup;
@@ -45550,7 +45477,7 @@ async function createAgentServer(params) {
45550
45477
  });
45551
45478
  }
45552
45479
  });
45553
- return c.body(stream, {
45480
+ return new Response(stream, {
45554
45481
  headers: {
45555
45482
  "Content-Type": "text/event-stream",
45556
45483
  "Cache-Control": "no-cache",
@@ -45558,6 +45485,119 @@ async function createAgentServer(params) {
45558
45485
  "x-vercel-ai-ui-message-stream": "v1"
45559
45486
  }
45560
45487
  });
45488
+ }
45489
+ app.use("/*", cors({ origin: "*" }));
45490
+ app.use("/*", async (c, next) => {
45491
+ const unauthorizedResponse = authorizeServerRequest(c.req.raw, authToken);
45492
+ if (unauthorizedResponse) {
45493
+ return unauthorizedResponse;
45494
+ }
45495
+ await next();
45496
+ });
45497
+ app.get("/api/health", (c) => {
45498
+ return c.json({ ok: true });
45499
+ });
45500
+ app.get("/api/status", (c) => {
45501
+ return c.json({
45502
+ isStreaming: activeSession.isStreaming,
45503
+ model: activeSession.model ? { provider: activeSession.model.provider, id: activeSession.model.id } : null,
45504
+ mode: sessionMode
45505
+ });
45506
+ });
45507
+ app.post("/api/chat", async (c) => {
45508
+ const body2 = await c.req.json();
45509
+ const messages = body2.messages ?? [];
45510
+ if (body2.sessionId && body2.sessionId.trim() !== activeSession.id?.trim()) {
45511
+ try {
45512
+ activeSession = await onResumeSession(body2.sessionId);
45513
+ sessionMode = "normal";
45514
+ } catch (error48) {
45515
+ const msg = error48 instanceof Error ? error48.message : String(error48);
45516
+ return c.json({ error: `Failed to resume session: ${msg}` }, 400);
45517
+ }
45518
+ }
45519
+ const chatUnavailableReason = getChatUnavailableReason({ session: activeSession });
45520
+ if (chatUnavailableReason) {
45521
+ return c.json({ error: chatUnavailableReason }, 409);
45522
+ }
45523
+ const sessionId = body2.sessionId?.trim() || activeSession.id?.trim() || "active";
45524
+ const askUserResponse = extractAskUserToolResponse(messages);
45525
+ const pendingAskUser = pendingAskUserRequests.get(sessionId);
45526
+ const userMessage = askUserResponse ? pendingAskUser && pendingAskUser.toolCallId === askUserResponse.toolCallId ? formatAskUserResponsePrompt(askUserResponse.response) : void 0 : extractLastUserText(messages);
45527
+ if (!userMessage) {
45528
+ return c.json({
45529
+ error: askUserResponse ? "No matching pending ask_user request found" : "No user message found"
45530
+ }, 400);
45531
+ }
45532
+ if (askUserResponse) {
45533
+ pendingAskUserRequests.delete(sessionId);
45534
+ }
45535
+ let promptText = userMessage;
45536
+ if (!askUserResponse) {
45537
+ const modeCmd = parseModeSlashCommand(userMessage);
45538
+ if (modeCmd) {
45539
+ if (activeSession.isStreaming) {
45540
+ await activeSession.abort();
45541
+ await waitForIdle(activeSession);
45542
+ }
45543
+ await activeSession.prompt(`/${modeCmd.command}`);
45544
+ sessionMode = SESSION_MODE_COMMANDS[modeCmd.command] ?? sessionMode;
45545
+ if (!modeCmd.remainder) {
45546
+ const notifEncoder = new TextEncoder();
45547
+ const notifMessageId = generateMessageId();
45548
+ return c.body(
45549
+ makeModeNotificationStream({ command: modeCmd.command, messageId: notifMessageId, encoder: notifEncoder }),
45550
+ {
45551
+ headers: {
45552
+ "Content-Type": "text/event-stream",
45553
+ "Cache-Control": "no-cache",
45554
+ "Connection": "keep-alive",
45555
+ "x-vercel-ai-ui-message-stream": "v1"
45556
+ }
45557
+ }
45558
+ );
45559
+ }
45560
+ promptText = modeCmd.remainder;
45561
+ }
45562
+ }
45563
+ return createPromptStreamResponse(promptText, sessionId);
45564
+ });
45565
+ app.post("/api/chat/retry", async (c) => {
45566
+ const body2 = await c.req.json().catch(() => ({}));
45567
+ if (body2.sessionId && body2.sessionId.trim() !== activeSession.id?.trim()) {
45568
+ try {
45569
+ activeSession = await onResumeSession(body2.sessionId);
45570
+ sessionMode = "normal";
45571
+ } catch (error48) {
45572
+ const msg = error48 instanceof Error ? error48.message : String(error48);
45573
+ return c.json({ error: `Failed to resume session: ${msg}` }, 400);
45574
+ }
45575
+ }
45576
+ const chatUnavailableReason = getChatUnavailableReason({ session: activeSession });
45577
+ if (chatUnavailableReason) {
45578
+ return c.json({ error: chatUnavailableReason }, 409);
45579
+ }
45580
+ const userMessages = activeSession.getUserMessagesForForking();
45581
+ const lastUserMessage = userMessages[userMessages.length - 1];
45582
+ if (!lastUserMessage) {
45583
+ return c.json({ error: "Session has no user message to retry" }, 404);
45584
+ }
45585
+ if (activeSession.isStreaming) {
45586
+ await activeSession.abort();
45587
+ await waitForIdle(activeSession);
45588
+ }
45589
+ try {
45590
+ const navigation = await activeSession.navigateTree(lastUserMessage.entryId);
45591
+ if (navigation.cancelled) {
45592
+ return c.json({ error: "Retry cancelled by session" }, 409);
45593
+ }
45594
+ } catch (error48) {
45595
+ const msg = error48 instanceof Error ? error48.message : String(error48);
45596
+ return c.json({ error: `Failed to rewind session for retry: ${msg}` }, 500);
45597
+ }
45598
+ const sessionId = body2.sessionId?.trim() || activeSession.id?.trim() || "active";
45599
+ pendingAskUserRequests.delete(sessionId);
45600
+ return createPromptStreamResponse(lastUserMessage.text, sessionId);
45561
45601
  });
45562
45602
  app.post("/api/chat/abort", async (c) => {
45563
45603
  if (!activeSession.isStreaming) {
@@ -47406,6 +47446,8 @@ async function createAgentServer(params) {
47406
47446
 
47407
47447
  `);
47408
47448
  process.stderr.write(` POST /api/chat \u2014 send chat messages (SSE UIMessage stream)
47449
+ `);
47450
+ process.stderr.write(` POST /api/chat/retry \u2014 retry the last user message after an error
47409
47451
  `);
47410
47452
  process.stderr.write(` POST /api/chat/abort \u2014 abort active chat stream
47411
47453
  `);
@@ -47651,6 +47693,12 @@ var SERVER_MODE_ALLOWED_MODEL_IDS_BY_PROVIDER = {
47651
47693
  minimax: [
47652
47694
  "MiniMax-M2.7",
47653
47695
  "MiniMax-M2.7-highspeed"
47696
+ ],
47697
+ moonshotai: [
47698
+ "kimi-k2.6"
47699
+ ],
47700
+ deepseek: [
47701
+ "deepseek-v4-pro"
47654
47702
  ]
47655
47703
  };
47656
47704
  var ALLOWED_MODEL_IDS_BY_PROVIDER = Object.fromEntries(
@@ -47735,6 +47783,17 @@ function createServerSessionAdapter(params) {
47735
47783
  listCommands() {
47736
47784
  const getCommands = params.extensionsResult.runtime.getCommands;
47737
47785
  return typeof getCommands === "function" ? getCommands() : [];
47786
+ },
47787
+ getUserMessagesForForking() {
47788
+ const fn = params.session.getUserMessagesForForking;
47789
+ return typeof fn === "function" ? fn.call(params.session) : [];
47790
+ },
47791
+ navigateTree(targetId, options) {
47792
+ const fn = params.session.navigateTree;
47793
+ if (typeof fn !== "function") {
47794
+ return Promise.resolve({ cancelled: true });
47795
+ }
47796
+ return fn.call(params.session, targetId, options);
47738
47797
  }
47739
47798
  };
47740
47799
  }