@docyrus/docyrus 0.0.71 → 0.0.73

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.73",
4
4
  "private": false,
5
5
  "description": "Docyrus API CLI",
6
6
  "main": "./main.js",
package/server-loader.js CHANGED
@@ -18625,6 +18625,7 @@ var import_picocolors2 = __toESM(require_picocolors());
18625
18625
  // src/agent/envStore.ts
18626
18626
  var import_promises = require("node:fs/promises");
18627
18627
  var import_node_path = require("node:path");
18628
+ var LEGACY_AZURE_OPENAI_DEFAULT_API_VERSION = "2025-04-01-preview";
18628
18629
  function createDefaultState() {
18629
18630
  return {
18630
18631
  version: 1,
@@ -18639,6 +18640,9 @@ function normalizeState(state) {
18639
18640
  if (!normalizedKey || !normalizedValue) {
18640
18641
  continue;
18641
18642
  }
18643
+ if (normalizedKey === "AZURE_OPENAI_API_VERSION" && normalizedValue === LEGACY_AZURE_OPENAI_DEFAULT_API_VERSION) {
18644
+ continue;
18645
+ }
18642
18646
  values[normalizedKey] = normalizedValue;
18643
18647
  }
18644
18648
  return {
@@ -43164,8 +43168,7 @@ function getProviderFormFields(params) {
43164
43168
  name: "apiVersion",
43165
43169
  title: "API version",
43166
43170
  component: "text",
43167
- defaultValue: "2025-04-01-preview",
43168
- placeholder: "2025-04-01-preview"
43171
+ placeholder: "Leave blank to use pi default (v1)"
43169
43172
  }
43170
43173
  ];
43171
43174
  case "amazon-bedrock":
@@ -45366,88 +45369,11 @@ async function createAgentServer(params) {
45366
45369
  modelIdsByProvider: getModelIdsByProvider()
45367
45370
  });
45368
45371
  }
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
- }
45372
+ function createPromptStreamResponse(promptText, sessionId) {
45447
45373
  const messageId = generateMessageId();
45448
45374
  const encoder = new TextEncoder();
45449
45375
  const stream = new ReadableStream({
45450
- start(controller) {
45376
+ async start(controller) {
45451
45377
  let closed = false;
45452
45378
  function writeChunk(chunk) {
45453
45379
  if (closed) {
@@ -45471,6 +45397,10 @@ async function createAgentServer(params) {
45471
45397
  } catch {
45472
45398
  }
45473
45399
  }
45400
+ if (activeSession.isStreaming) {
45401
+ await activeSession.abort();
45402
+ await waitForIdle(activeSession);
45403
+ }
45474
45404
  writeChunk({ type: "start" });
45475
45405
  writeChunk({ type: "start-step" });
45476
45406
  let extensionUICleanup;
@@ -45550,7 +45480,7 @@ async function createAgentServer(params) {
45550
45480
  });
45551
45481
  }
45552
45482
  });
45553
- return c.body(stream, {
45483
+ return new Response(stream, {
45554
45484
  headers: {
45555
45485
  "Content-Type": "text/event-stream",
45556
45486
  "Cache-Control": "no-cache",
@@ -45558,6 +45488,119 @@ async function createAgentServer(params) {
45558
45488
  "x-vercel-ai-ui-message-stream": "v1"
45559
45489
  }
45560
45490
  });
45491
+ }
45492
+ app.use("/*", cors({ origin: "*" }));
45493
+ app.use("/*", async (c, next) => {
45494
+ const unauthorizedResponse = authorizeServerRequest(c.req.raw, authToken);
45495
+ if (unauthorizedResponse) {
45496
+ return unauthorizedResponse;
45497
+ }
45498
+ await next();
45499
+ });
45500
+ app.get("/api/health", (c) => {
45501
+ return c.json({ ok: true });
45502
+ });
45503
+ app.get("/api/status", (c) => {
45504
+ return c.json({
45505
+ isStreaming: activeSession.isStreaming,
45506
+ model: activeSession.model ? { provider: activeSession.model.provider, id: activeSession.model.id } : null,
45507
+ mode: sessionMode
45508
+ });
45509
+ });
45510
+ app.post("/api/chat", async (c) => {
45511
+ const body2 = await c.req.json();
45512
+ const messages = body2.messages ?? [];
45513
+ if (body2.sessionId && body2.sessionId.trim() !== activeSession.id?.trim()) {
45514
+ try {
45515
+ activeSession = await onResumeSession(body2.sessionId);
45516
+ sessionMode = "normal";
45517
+ } catch (error48) {
45518
+ const msg = error48 instanceof Error ? error48.message : String(error48);
45519
+ return c.json({ error: `Failed to resume session: ${msg}` }, 400);
45520
+ }
45521
+ }
45522
+ const chatUnavailableReason = getChatUnavailableReason({ session: activeSession });
45523
+ if (chatUnavailableReason) {
45524
+ return c.json({ error: chatUnavailableReason }, 409);
45525
+ }
45526
+ const sessionId = body2.sessionId?.trim() || activeSession.id?.trim() || "active";
45527
+ const askUserResponse = extractAskUserToolResponse(messages);
45528
+ const pendingAskUser = pendingAskUserRequests.get(sessionId);
45529
+ const userMessage = askUserResponse ? pendingAskUser && pendingAskUser.toolCallId === askUserResponse.toolCallId ? formatAskUserResponsePrompt(askUserResponse.response) : void 0 : extractLastUserText(messages);
45530
+ if (!userMessage) {
45531
+ return c.json({
45532
+ error: askUserResponse ? "No matching pending ask_user request found" : "No user message found"
45533
+ }, 400);
45534
+ }
45535
+ if (askUserResponse) {
45536
+ pendingAskUserRequests.delete(sessionId);
45537
+ }
45538
+ let promptText = userMessage;
45539
+ if (!askUserResponse) {
45540
+ const modeCmd = parseModeSlashCommand(userMessage);
45541
+ if (modeCmd) {
45542
+ if (activeSession.isStreaming) {
45543
+ await activeSession.abort();
45544
+ await waitForIdle(activeSession);
45545
+ }
45546
+ await activeSession.prompt(`/${modeCmd.command}`);
45547
+ sessionMode = SESSION_MODE_COMMANDS[modeCmd.command] ?? sessionMode;
45548
+ if (!modeCmd.remainder) {
45549
+ const notifEncoder = new TextEncoder();
45550
+ const notifMessageId = generateMessageId();
45551
+ return c.body(
45552
+ makeModeNotificationStream({ command: modeCmd.command, messageId: notifMessageId, encoder: notifEncoder }),
45553
+ {
45554
+ headers: {
45555
+ "Content-Type": "text/event-stream",
45556
+ "Cache-Control": "no-cache",
45557
+ "Connection": "keep-alive",
45558
+ "x-vercel-ai-ui-message-stream": "v1"
45559
+ }
45560
+ }
45561
+ );
45562
+ }
45563
+ promptText = modeCmd.remainder;
45564
+ }
45565
+ }
45566
+ return createPromptStreamResponse(promptText, sessionId);
45567
+ });
45568
+ app.post("/api/chat/retry", async (c) => {
45569
+ const body2 = await c.req.json().catch(() => ({}));
45570
+ if (body2.sessionId && body2.sessionId.trim() !== activeSession.id?.trim()) {
45571
+ try {
45572
+ activeSession = await onResumeSession(body2.sessionId);
45573
+ sessionMode = "normal";
45574
+ } catch (error48) {
45575
+ const msg = error48 instanceof Error ? error48.message : String(error48);
45576
+ return c.json({ error: `Failed to resume session: ${msg}` }, 400);
45577
+ }
45578
+ }
45579
+ const chatUnavailableReason = getChatUnavailableReason({ session: activeSession });
45580
+ if (chatUnavailableReason) {
45581
+ return c.json({ error: chatUnavailableReason }, 409);
45582
+ }
45583
+ const userMessages = activeSession.getUserMessagesForForking();
45584
+ const lastUserMessage = userMessages[userMessages.length - 1];
45585
+ if (!lastUserMessage) {
45586
+ return c.json({ error: "Session has no user message to retry" }, 404);
45587
+ }
45588
+ if (activeSession.isStreaming) {
45589
+ await activeSession.abort();
45590
+ await waitForIdle(activeSession);
45591
+ }
45592
+ try {
45593
+ const navigation = await activeSession.navigateTree(lastUserMessage.entryId);
45594
+ if (navigation.cancelled) {
45595
+ return c.json({ error: "Retry cancelled by session" }, 409);
45596
+ }
45597
+ } catch (error48) {
45598
+ const msg = error48 instanceof Error ? error48.message : String(error48);
45599
+ return c.json({ error: `Failed to rewind session for retry: ${msg}` }, 500);
45600
+ }
45601
+ const sessionId = body2.sessionId?.trim() || activeSession.id?.trim() || "active";
45602
+ pendingAskUserRequests.delete(sessionId);
45603
+ return createPromptStreamResponse(lastUserMessage.text, sessionId);
45561
45604
  });
45562
45605
  app.post("/api/chat/abort", async (c) => {
45563
45606
  if (!activeSession.isStreaming) {
@@ -47406,6 +47449,8 @@ async function createAgentServer(params) {
47406
47449
 
47407
47450
  `);
47408
47451
  process.stderr.write(` POST /api/chat \u2014 send chat messages (SSE UIMessage stream)
47452
+ `);
47453
+ process.stderr.write(` POST /api/chat/retry \u2014 retry the last user message after an error
47409
47454
  `);
47410
47455
  process.stderr.write(` POST /api/chat/abort \u2014 abort active chat stream
47411
47456
  `);
@@ -47651,6 +47696,12 @@ var SERVER_MODE_ALLOWED_MODEL_IDS_BY_PROVIDER = {
47651
47696
  minimax: [
47652
47697
  "MiniMax-M2.7",
47653
47698
  "MiniMax-M2.7-highspeed"
47699
+ ],
47700
+ moonshotai: [
47701
+ "kimi-k2.6"
47702
+ ],
47703
+ deepseek: [
47704
+ "deepseek-v4-pro"
47654
47705
  ]
47655
47706
  };
47656
47707
  var ALLOWED_MODEL_IDS_BY_PROVIDER = Object.fromEntries(
@@ -47735,6 +47786,17 @@ function createServerSessionAdapter(params) {
47735
47786
  listCommands() {
47736
47787
  const getCommands = params.extensionsResult.runtime.getCommands;
47737
47788
  return typeof getCommands === "function" ? getCommands() : [];
47789
+ },
47790
+ getUserMessagesForForking() {
47791
+ const fn = params.session.getUserMessagesForForking;
47792
+ return typeof fn === "function" ? fn.call(params.session) : [];
47793
+ },
47794
+ navigateTree(targetId, options) {
47795
+ const fn = params.session.navigateTree;
47796
+ if (typeof fn !== "function") {
47797
+ return Promise.resolve({ cancelled: true });
47798
+ }
47799
+ return fn.call(params.session, targetId, options);
47738
47800
  }
47739
47801
  };
47740
47802
  }