@promptbook/cli 0.104.0-2 → 0.104.0-4

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.
Files changed (66) hide show
  1. package/apps/agents-server/package.json +3 -4
  2. package/apps/agents-server/public/swagger.json +115 -0
  3. package/apps/agents-server/scripts/generate-reserved-paths/generate-reserved-paths.ts +11 -7
  4. package/apps/agents-server/src/app/AddAgentButton.tsx +1 -2
  5. package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +221 -274
  6. package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +94 -137
  7. package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +8 -8
  8. package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +15 -1
  9. package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +1 -3
  10. package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +29 -16
  11. package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +3 -0
  12. package/apps/agents-server/src/app/agents/[agentName]/api/mcp/route.ts +6 -11
  13. package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +4 -1
  14. package/apps/agents-server/src/app/agents/[agentName]/code/api/route.ts +8 -6
  15. package/apps/agents-server/src/app/agents/[agentName]/code/page.tsx +33 -30
  16. package/apps/agents-server/src/app/api/agents/[agentName]/clone/route.ts +10 -12
  17. package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +1 -2
  18. package/apps/agents-server/src/app/api/agents/route.ts +1 -1
  19. package/apps/agents-server/src/app/api/api-tokens/route.ts +6 -7
  20. package/apps/agents-server/src/app/api/docs/book.md/route.ts +3 -0
  21. package/apps/agents-server/src/app/api/metadata/route.ts +5 -6
  22. package/apps/agents-server/src/app/api/upload/route.ts +9 -0
  23. package/apps/agents-server/src/app/page.tsx +1 -1
  24. package/apps/agents-server/src/app/swagger/page.tsx +14 -0
  25. package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +4 -2
  26. package/apps/agents-server/src/components/AgentProfile/QrCodeModal.tsx +0 -1
  27. package/apps/agents-server/src/components/Auth/AuthControls.tsx +5 -4
  28. package/apps/agents-server/src/components/Header/Header.tsx +27 -5
  29. package/apps/agents-server/src/components/Homepage/AgentCard.tsx +22 -3
  30. package/apps/agents-server/src/components/_utils/headlessParam.tsx +7 -3
  31. package/apps/agents-server/src/database/migrate.ts +34 -1
  32. package/apps/agents-server/src/database/migrations/2025-12-0402-message-table.sql +42 -0
  33. package/apps/agents-server/src/generated/reservedPaths.ts +6 -1
  34. package/apps/agents-server/src/message-providers/email/_common/Email.ts +73 -0
  35. package/apps/agents-server/src/message-providers/email/_common/utils/TODO.txt +1 -0
  36. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.test.ts.todo +108 -0
  37. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddress.ts +62 -0
  38. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.test.ts.todo +117 -0
  39. package/apps/agents-server/src/message-providers/email/_common/utils/parseEmailAddresses.ts +19 -0
  40. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.test.ts.todo +119 -0
  41. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddress.ts +19 -0
  42. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.test.ts.todo +74 -0
  43. package/apps/agents-server/src/message-providers/email/_common/utils/stringifyEmailAddresses.ts +14 -0
  44. package/apps/agents-server/src/message-providers/email/sendgrid/SendgridMessageProvider.ts +44 -0
  45. package/apps/agents-server/src/message-providers/email/zeptomail/ZeptomailMessageProvider.ts +43 -0
  46. package/apps/agents-server/src/message-providers/index.ts +13 -0
  47. package/apps/agents-server/src/message-providers/interfaces/MessageProvider.ts +11 -0
  48. package/apps/agents-server/src/middleware.ts +12 -3
  49. package/apps/agents-server/src/utils/auth.ts +117 -17
  50. package/apps/agents-server/src/utils/getUserIdFromRequest.ts +3 -1
  51. package/apps/agents-server/src/utils/handleChatCompletion.ts +9 -5
  52. package/apps/agents-server/src/utils/messages/sendMessage.ts +91 -0
  53. package/apps/agents-server/src/utils/normalization/filenameToPrompt.test.ts +36 -0
  54. package/apps/agents-server/src/utils/normalization/filenameToPrompt.ts +6 -2
  55. package/apps/agents-server/src/utils/validateApiKey.ts +5 -10
  56. package/esm/index.es.js +86 -9
  57. package/esm/index.es.js.map +1 -1
  58. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  59. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +7 -11
  60. package/esm/typings/src/llm-providers/_multiple/MultipleLlmExecutionTools.d.ts +6 -2
  61. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
  62. package/esm/typings/src/types/Message.d.ts +49 -0
  63. package/esm/typings/src/version.d.ts +1 -1
  64. package/package.json +1 -1
  65. package/umd/index.umd.js +86 -9
  66. package/umd/index.umd.js.map +1 -1
@@ -54,10 +54,7 @@ function getMessagePreview(message: unknown, maxLength = 120): string {
54
54
  }
55
55
 
56
56
  if (typeof message === 'object') {
57
- const content =
58
- (message as { content?: unknown }).content ??
59
- (message as { text?: unknown }).text ??
60
- message;
57
+ const content = (message as { content?: unknown }).content ?? (message as { text?: unknown }).text ?? message;
61
58
 
62
59
  let text: string;
63
60
 
@@ -303,11 +300,12 @@ export function ChatHistoryClient({ initialAgentName }: ChatHistoryClientProps)
303
300
  const message = row.message as { role?: string; content?: string };
304
301
  const role = (message.role || 'USER').toUpperCase();
305
302
  return {
303
+ // channel: 'PROMPTBOOK_CHAT',
306
304
  id: String(row.id),
307
- from: role === 'USER' ? 'USER' : 'ASSISTANT',
305
+ sender: role === 'USER' ? 'USER' : 'ASSISTANT',
308
306
  content: message.content || JSON.stringify(message),
309
307
  isComplete: true,
310
- date: new Date(row.createdAt),
308
+ createdAt: new Date(row.createdAt),
311
309
  } satisfies ChatMessage;
312
310
  });
313
311
  }, [items, viewMode]);
@@ -317,17 +315,9 @@ export function ChatHistoryClient({ initialAgentName }: ChatHistoryClientProps)
317
315
  <div>
318
316
  {total > 0 ? (
319
317
  <>
320
- Showing{' '}
321
- <span className="font-semibold">
322
- {Math.min((page - 1) * pageSize + 1, total)}
323
- </span>{' '}
324
- –{' '}
325
- <span className="font-semibold">
326
- {Math.min(page * pageSize, total)}
327
- </span>{' '}
328
- of{' '}
329
- <span className="font-semibold">{total}</span>{' '}
330
- messages
318
+ Showing <span className="font-semibold">{Math.min((page - 1) * pageSize + 1, total)}</span> –{' '}
319
+ <span className="font-semibold">{Math.min(page * pageSize, total)}</span> of{' '}
320
+ <span className="font-semibold">{total}</span> messages
331
321
  </>
332
322
  ) : (
333
323
  'No messages'
@@ -403,97 +393,90 @@ export function ChatHistoryClient({ initialAgentName }: ChatHistoryClientProps)
403
393
  </a>
404
394
  </div>
405
395
  <div>
406
- <div className="text-xl font-semibold text-gray-900">
407
- {total.toLocaleString()}
408
- </div>
409
- <div className="text-xs uppercase tracking-wide text-gray-400">
410
- Total messages
411
- </div>
396
+ <div className="text-xl font-semibold text-gray-900">{total.toLocaleString()}</div>
397
+ <div className="text-xs uppercase tracking-wide text-gray-400">Total messages</div>
412
398
  </div>
413
399
  </div>
414
400
  </div>
415
401
  <Card>
416
- <div className="flex flex-col gap-4 md:flex-row md:items-end md:justify-between">
417
- <form onSubmit={handleSearchSubmit} className="flex flex-col gap-2 md:flex-row md:items-end">
418
- <div className="flex flex-col gap-1">
419
- <label htmlFor="search" className="text-sm font-medium text-gray-700">
420
- Search
421
- </label>
422
- <input
423
- id="search"
424
- type="text"
425
- value={searchInput}
426
- onChange={(event) => setSearchInput(event.target.value)}
427
- placeholder="Search by agent name, URL or IP"
428
- className="w-full md:w-72 px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
429
- />
430
- </div>
431
- <button
432
- type="submit"
433
- className="mt-2 inline-flex items-center justify-center rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 md:mt-0 md:ml-3"
402
+ <div className="flex flex-col gap-4 md:flex-row md:items-end md:justify-between">
403
+ <form onSubmit={handleSearchSubmit} className="flex flex-col gap-2 md:flex-row md:items-end">
404
+ <div className="flex flex-col gap-1">
405
+ <label htmlFor="search" className="text-sm font-medium text-gray-700">
406
+ Search
407
+ </label>
408
+ <input
409
+ id="search"
410
+ type="text"
411
+ value={searchInput}
412
+ onChange={(event) => setSearchInput(event.target.value)}
413
+ placeholder="Search by agent name, URL or IP"
414
+ className="w-full md:w-72 px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
415
+ />
416
+ </div>
417
+ <button
418
+ type="submit"
419
+ className="mt-2 inline-flex items-center justify-center rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 md:mt-0 md:ml-3"
420
+ >
421
+ Apply
422
+ </button>
423
+ </form>
424
+
425
+ <div className="flex flex-col gap-2 md:flex-row md:items-end md:gap-4">
426
+ <div className="flex flex-col gap-1">
427
+ <label htmlFor="agentFilter" className="text-sm font-medium text-gray-700">
428
+ Agent filter
429
+ </label>
430
+ <select
431
+ id="agentFilter"
432
+ value={agentName}
433
+ onChange={handleAgentChange}
434
+ className="w-full md:w-64 px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
434
435
  >
435
- Apply
436
- </button>
437
- </form>
438
-
439
- <div className="flex flex-col gap-2 md:flex-row md:items-end md:gap-4">
440
- <div className="flex flex-col gap-1">
441
- <label htmlFor="agentFilter" className="text-sm font-medium text-gray-700">
442
- Agent filter
443
- </label>
444
- <select
445
- id="agentFilter"
446
- value={agentName}
447
- onChange={handleAgentChange}
448
- className="w-full md:w-64 px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
449
- >
450
- <option value="">All agents</option>
451
- {agents.map((agent) => (
452
- <option key={agent.agentName} value={agent.agentName}>
453
- {agent.fullname || agent.agentName}
454
- </option>
455
- ))}
456
- </select>
457
- {agentsLoading && (
458
- <span className="text-xs text-gray-400">Loading agents…</span>
459
- )}
460
- </div>
461
-
462
- <div className="flex flex-col gap-1">
463
- <label htmlFor="pageSize" className="text-sm font-medium text-gray-700">
464
- Page size
465
- </label>
466
- <select
467
- id="pageSize"
468
- value={pageSize}
469
- onChange={handlePageSizeChange}
470
- className="w-28 px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
471
- >
472
- <option value={10}>10</option>
473
- <option value={20}>20</option>
474
- <option value={50}>50</option>
475
- <option value={100}>100</option>
476
- </select>
477
- </div>
436
+ <option value="">All agents</option>
437
+ {agents.map((agent) => (
438
+ <option key={agent.agentName} value={agent.agentName}>
439
+ {agent.fullname || agent.agentName}
440
+ </option>
441
+ ))}
442
+ </select>
443
+ {agentsLoading && <span className="text-xs text-gray-400">Loading agents…</span>}
478
444
  </div>
479
- </div>
480
445
 
481
- {agentName && (
482
- <div className="mt-4 flex items-center justify-between gap-4 rounded-md border border-amber-200 bg-amber-50 px-4 py-3">
483
- <p className="text-sm text-amber-800">
484
- Showing chat history for agent{' '}
485
- <span className="font-semibold break-all">{agentName}</span>.
486
- </p>
487
- <button
488
- type="button"
489
- onClick={handleClearAgentHistory}
490
- className="inline-flex items-center justify-center rounded-md border border-red-300 bg-white px-3 py-1.5 text-xs font-medium text-red-700 hover:bg-red-50"
446
+ <div className="flex flex-col gap-1">
447
+ <label htmlFor="pageSize" className="text-sm font-medium text-gray-700">
448
+ Page size
449
+ </label>
450
+ <select
451
+ id="pageSize"
452
+ value={pageSize}
453
+ onChange={handlePageSizeChange}
454
+ className="w-28 px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
491
455
  >
492
- Clear history for this agent
493
- </button>
456
+ <option value={10}>10</option>
457
+ <option value={20}>20</option>
458
+ <option value={50}>50</option>
459
+ <option value={100}>100</option>
460
+ </select>
494
461
  </div>
495
- )}
496
- </Card>
462
+ </div>
463
+ </div>
464
+
465
+ {agentName && (
466
+ <div className="mt-4 flex items-center justify-between gap-4 rounded-md border border-amber-200 bg-amber-50 px-4 py-3">
467
+ <p className="text-sm text-amber-800">
468
+ Showing chat history for agent <span className="font-semibold break-all">{agentName}</span>.
469
+ </p>
470
+ <button
471
+ type="button"
472
+ onClick={handleClearAgentHistory}
473
+ className="inline-flex items-center justify-center rounded-md border border-red-300 bg-white px-3 py-1.5 text-xs font-medium text-red-700 hover:bg-red-50"
474
+ >
475
+ Clear history for this agent
476
+ </button>
477
+ </div>
478
+ )}
479
+ </Card>
497
480
 
498
481
  {viewMode === 'chat' ? (
499
482
  <div className="bg-white rounded-lg shadow border border-gray-200 overflow-hidden flex flex-col">
@@ -505,22 +488,14 @@ export function ChatHistoryClient({ initialAgentName }: ChatHistoryClientProps)
505
488
  isSaveButtonEnabled={true}
506
489
  />
507
490
  </div>
508
- <div className="p-4 bg-gray-50 border-t border-gray-200">
509
- {pagination}
510
- </div>
491
+ <div className="p-4 bg-gray-50 border-t border-gray-200">{pagination}</div>
511
492
  </div>
512
493
  ) : (
513
494
  <Card>
514
495
  <div className="flex items-center justify-between mb-4">
515
- <h2 className="text-lg font-medium text-gray-900">
516
- Messages ({total})
517
- </h2>
496
+ <h2 className="text-lg font-medium text-gray-900">Messages ({total})</h2>
518
497
  </div>
519
- {error && (
520
- <div className="mb-4 rounded-md bg-red-50 px-4 py-3 text-sm text-red-800">
521
- {error}
522
- </div>
523
- )}
498
+ {error && <div className="mb-4 rounded-md bg-red-50 px-4 py-3 text-sm text-red-800">{error}</div>}
524
499
 
525
500
  {loading && items.length === 0 ? (
526
501
  <div className="py-8 text-center text-gray-500">Loading chat history…</div>
@@ -555,27 +530,13 @@ export function ChatHistoryClient({ initialAgentName }: ChatHistoryClientProps)
555
530
  )}
556
531
  </button>
557
532
  </th>
558
- <th className="px-4 py-3 text-left font-medium text-gray-500">
559
- Role
560
- </th>
561
- <th className="px-4 py-3 text-left font-medium text-gray-500">
562
- Message
563
- </th>
564
- <th className="px-4 py-3 text-left font-medium text-gray-500">
565
- URL
566
- </th>
567
- <th className="px-4 py-3 text-left font-medium text-gray-500">
568
- IP
569
- </th>
570
- <th className="px-4 py-3 text-left font-medium text-gray-500">
571
- Language
572
- </th>
573
- <th className="px-4 py-3 text-left font-medium text-gray-500">
574
- Platform
575
- </th>
576
- <th className="px-4 py-3 text-right font-medium text-gray-500">
577
- Actions
578
- </th>
533
+ <th className="px-4 py-3 text-left font-medium text-gray-500">Role</th>
534
+ <th className="px-4 py-3 text-left font-medium text-gray-500">Message</th>
535
+ <th className="px-4 py-3 text-left font-medium text-gray-500">URL</th>
536
+ <th className="px-4 py-3 text-left font-medium text-gray-500">IP</th>
537
+ <th className="px-4 py-3 text-left font-medium text-gray-500">Language</th>
538
+ <th className="px-4 py-3 text-left font-medium text-gray-500">Platform</th>
539
+ <th className="px-4 py-3 text-right font-medium text-gray-500">Actions</th>
579
540
  </tr>
580
541
  </thead>
581
542
  <tbody className="divide-y divide-gray-200 bg-white">
@@ -596,9 +557,7 @@ export function ChatHistoryClient({ initialAgentName }: ChatHistoryClientProps)
596
557
  </div>
597
558
  </td>
598
559
  <td className="max-w-xs px-4 py-3 text-gray-500">
599
- <div className="truncate text-xs">
600
- {row.url || '-'}
601
- </div>
560
+ <div className="truncate text-xs">{row.url || '-'}</div>
602
561
  </td>
603
562
  <td className="whitespace-nowrap px-4 py-3 text-gray-500">
604
563
  {row.ip || '-'}
@@ -607,9 +566,7 @@ export function ChatHistoryClient({ initialAgentName }: ChatHistoryClientProps)
607
566
  {row.language || '-'}
608
567
  </td>
609
568
  <td className="max-w-xs px-4 py-3 text-gray-500">
610
- <div className="truncate text-xs">
611
- {row.platform || '-'}
612
- </div>
569
+ <div className="truncate text-xs">{row.platform || '-'}</div>
613
570
  </td>
614
571
  <td className="whitespace-nowrap px-4 py-3 text-right text-xs font-medium">
615
572
  <button
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { upload } from '@vercel/blob/client';
4
- import { FileText, Hash, Image, Shield, ToggleLeft, Type, Upload } from 'lucide-react';
4
+ import { FileTextIcon, HashIcon, ImageIcon, ShieldIcon, ToggleLeftIcon, TypeIcon, Upload } from 'lucide-react';
5
5
  import { useEffect, useRef, useState } from 'react';
6
6
  import { metadataDefaults, MetadataType } from '../../../database/metadataDefaults';
7
7
 
@@ -149,19 +149,19 @@ export function MetadataClient() {
149
149
  const getTypeIcon = (type?: MetadataType) => {
150
150
  switch (type) {
151
151
  case 'TEXT_SINGLE_LINE':
152
- return <Type className="w-4 h-4" />;
152
+ return <TypeIcon className="w-4 h-4" />;
153
153
  case 'TEXT':
154
- return <FileText className="w-4 h-4" />;
154
+ return <FileTextIcon className="w-4 h-4" />;
155
155
  case 'NUMBER':
156
- return <Hash className="w-4 h-4" />;
156
+ return <HashIcon className="w-4 h-4" />;
157
157
  case 'BOOLEAN':
158
- return <ToggleLeft className="w-4 h-4" />;
158
+ return <ToggleLeftIcon className="w-4 h-4" />;
159
159
  case 'IMAGE_URL':
160
- return <Image className="w-4 h-4" />;
160
+ return <ImageIcon className="w-4 h-4" />;
161
161
  case 'IP_RANGE':
162
- return <Shield className="w-4 h-4" />;
162
+ return <ShieldIcon className="w-4 h-4" />;
163
163
  default:
164
- return <Type className="w-4 h-4" />;
164
+ return <TypeIcon className="w-4 h-4" />;
165
165
  }
166
166
  };
167
167
 
@@ -3,7 +3,7 @@
3
3
  import { usePromise } from '@common/hooks/usePromise';
4
4
  import { AgentChat } from '@promptbook-local/components';
5
5
  import { RemoteAgent } from '@promptbook-local/core';
6
- import { useCallback, useMemo } from 'react';
6
+ import { useCallback, useEffect, useMemo } from 'react';
7
7
  import { string_agent_url } from '../../../../../../src/types/typeAliases';
8
8
 
9
9
  type AgentChatWrapperProps = {
@@ -58,6 +58,20 @@ export function AgentChatWrapper(props: AgentChatWrapperProps) {
58
58
  [agent, agentUrl],
59
59
  );
60
60
 
61
+ // Remove the 'message' query parameter from URL after auto-executing a message
62
+ useEffect(() => {
63
+ if (autoExecuteMessage && typeof window !== 'undefined') {
64
+ // Wait for the message to be processed, then remove the query parameter
65
+ const timer = setTimeout(() => {
66
+ const url = new URL(window.location.href);
67
+ url.searchParams.delete('message');
68
+ window.history.replaceState({}, '', url.toString());
69
+ }, 1000); // 1 second delay to ensure message processing is complete
70
+
71
+ return () => clearTimeout(timer);
72
+ }
73
+ }, [autoExecuteMessage]);
74
+
61
75
  if (!agent) {
62
76
  return <>{/* <- TODO: [🐱‍🚀] <PromptbookLoading /> */}</>;
63
77
  }
@@ -20,8 +20,8 @@ import {
20
20
  import { Barlow_Condensed } from 'next/font/google';
21
21
  import { useCallback, useEffect, useRef, useState } from 'react';
22
22
  import { string_agent_permanent_id, string_data_url, string_url_image } from '../../../../../../src/types/typeAliases';
23
- import { getAgentLinks } from './agentLinks';
24
23
  import { deleteAgent } from '../../recycle-bin/actions';
24
+ import { getAgentLinks } from './agentLinks';
25
25
 
26
26
  type BeforeInstallPromptEvent = Event & {
27
27
  prompt: () => Promise<void>;
@@ -52,9 +52,7 @@ export function AgentOptionsMenu({
52
52
  permanentId,
53
53
  agentUrl,
54
54
  agentEmail,
55
- brandColorHex,
56
55
  isAdmin = false,
57
- backgroundImage,
58
56
  onShowQrCode,
59
57
  }: AgentOptionsMenuProps) {
60
58
  const [isOpen, setIsOpen] = useState(false);
@@ -8,6 +8,7 @@ import { useRouter } from 'next/navigation';
8
8
  import { useCallback, useMemo, useState } from 'react';
9
9
  import spaceTrim from 'spacetrim';
10
10
  import { string_agent_url, string_color } from '../../../../../../src/types/typeAliases';
11
+ import { keepUnused } from '../../../../../../src/utils/organization/keepUnused';
11
12
  import { $createAgentFromBookAction } from '../../../app/actions';
12
13
  import { DeletedAgentBanner } from '../../../components/DeletedAgentBanner';
13
14
 
@@ -20,10 +21,19 @@ type AgentProfileChatProps = {
20
21
  isDeleted?: boolean;
21
22
  };
22
23
 
23
- export function AgentProfileChat({ agentUrl, agentName, fullname, brandColorHex, avatarSrc, isDeleted = false }: AgentProfileChatProps) {
24
+ export function AgentProfileChat({
25
+ agentUrl,
26
+ agentName,
27
+ fullname,
28
+ brandColorHex,
29
+ avatarSrc,
30
+ isDeleted = false,
31
+ }: AgentProfileChatProps) {
24
32
  const router = useRouter();
25
33
  const [isCreatingAgent, setIsCreatingAgent] = useState(false);
26
34
 
35
+ keepUnused(isCreatingAgent);
36
+
27
37
  const agentPromise = useMemo(
28
38
  () =>
29
39
  RemoteAgent.connect({
@@ -43,20 +53,23 @@ export function AgentProfileChat({ agentUrl, agentName, fullname, brandColorHex,
43
53
  [agentName, router],
44
54
  );
45
55
 
46
- const handleCreateAgent = useCallback(async (bookContent: string) => {
47
- setIsCreatingAgent(true);
48
- try {
49
- const { permanentId } = await $createAgentFromBookAction(bookContent as string_book);
50
- if (permanentId) {
51
- router.push(`/agents/${permanentId}`);
56
+ const handleCreateAgent = useCallback(
57
+ async (bookContent: string) => {
58
+ setIsCreatingAgent(true);
59
+ try {
60
+ const { permanentId } = await $createAgentFromBookAction(bookContent as string_book);
61
+ if (permanentId) {
62
+ router.push(`/agents/${permanentId}`);
63
+ }
64
+ } catch (error) {
65
+ console.error('Failed to create agent:', error);
66
+ alert('Failed to create agent. Please try again.');
67
+ } finally {
68
+ setIsCreatingAgent(false);
52
69
  }
53
- } catch (error) {
54
- console.error('Failed to create agent:', error);
55
- alert('Failed to create agent. Please try again.');
56
- } finally {
57
- setIsCreatingAgent(false);
58
- }
59
- }, [router]);
70
+ },
71
+ [router],
72
+ );
60
73
 
61
74
  const initialMessage = useMemo(() => {
62
75
  if (!agent) {
@@ -101,9 +114,9 @@ export function AgentProfileChat({ agentUrl, agentName, fullname, brandColorHex,
101
114
  ]}
102
115
  messages={[
103
116
  {
104
- from: 'AGENT',
117
+ sender: 'AGENT',
105
118
  content: initialMessage,
106
- date: new Date(),
119
+ createdAt: new Date(),
107
120
  id: 'initial-message',
108
121
  isComplete: true,
109
122
  },
@@ -5,6 +5,7 @@ import { $provideOpenAiAssistantExecutionToolsForServer } from '@/src/tools/$pro
5
5
  import { Agent, computeAgentHash, PROMPTBOOK_ENGINE_VERSION } from '@promptbook-local/core';
6
6
  import { computeHash, serializeError } from '@promptbook-local/utils';
7
7
  import { assertsError } from '../../../../../../../../src/errors/assertsError';
8
+ import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
8
9
  import { isAgentDeleted } from '../../_utils';
9
10
 
10
11
  /**
@@ -13,6 +14,8 @@ import { isAgentDeleted } from '../../_utils';
13
14
  export const maxDuration = 300;
14
15
 
15
16
  export async function OPTIONS(request: Request) {
17
+ keepUnused(request);
18
+
16
19
  return new Response(null, {
17
20
  status: 200,
18
21
  headers: {
@@ -4,7 +4,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
  import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
5
5
  import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
6
6
  import { Agent } from '@promptbook-local/core';
7
- import { ChatMessage, ChatPromptResult, Prompt, TODO_any } from '@promptbook-local/types';
7
+ import { ChatMessage, Prompt, TODO_any } from '@promptbook-local/types';
8
8
  import { NextRequest, NextResponse } from 'next/server';
9
9
  import { z } from 'zod';
10
10
 
@@ -51,10 +51,7 @@ class SSENextJsTransport implements Transport {
51
51
  }
52
52
  }
53
53
 
54
- export async function GET(
55
- request: NextRequest,
56
- { params }: { params: Promise<{ agentName: string }> },
57
- ) {
54
+ export async function GET(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
58
55
  const { agentName } = await params;
59
56
 
60
57
  // Check if agent exists
@@ -98,7 +95,7 @@ export async function GET(
98
95
  ),
99
96
  model: z.string().optional(),
100
97
  },
101
- async ({ messages, model }) => {
98
+ async ({ messages }) => {
102
99
  try {
103
100
  const collection = await $provideAgentCollectionForServer();
104
101
  const agentSource = await collection.getAgentSource(agentName);
@@ -115,8 +112,9 @@ export async function GET(
115
112
  const previousMessages = messages.slice(0, -1);
116
113
 
117
114
  const thread: ChatMessage[] = previousMessages.map((msg: TODO_any, index: number) => ({
115
+ // channel: 'PROMPTBOOK_CHAT',
118
116
  id: `msg-${index}`,
119
- from: msg.role === 'assistant' ? 'agent' : 'user', // Mapping standard roles
117
+ sender: msg.role === 'assistant' ? 'agent' : 'user', // Mapping standard roles
120
118
  content: msg.content,
121
119
  isComplete: true,
122
120
  date: new Date(),
@@ -177,10 +175,7 @@ export async function GET(
177
175
  });
178
176
  }
179
177
 
180
- export async function POST(
181
- request: NextRequest,
182
- { params }: { params: Promise<{ agentName: string }> },
183
- ) {
178
+ export async function POST(request: NextRequest /*, { params }: { params: Promise<{ agentName: string }> }*/) {
184
179
  const { searchParams } = new URL(request.url);
185
180
  const sessionId = searchParams.get('sessionId');
186
181
 
@@ -6,10 +6,13 @@ import { $provideOpenAiAssistantExecutionToolsForServer } from '@/src/tools/$pro
6
6
  import { Agent, computeAgentHash, PROMPTBOOK_ENGINE_VERSION } from '@promptbook-local/core';
7
7
  import { computeHash, serializeError } from '@promptbook-local/utils';
8
8
  import { assertsError } from '../../../../../../../../src/errors/assertsError';
9
+ import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
9
10
 
10
11
  export const maxDuration = 300;
11
12
 
12
13
  export async function OPTIONS(request: Request) {
14
+ keepUnused(request);
15
+
13
16
  return new Response(null, {
14
17
  status: 200,
15
18
  headers: {
@@ -38,7 +41,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ age
38
41
  const audioFile = formData.get('audio') as File | null;
39
42
  const threadString = formData.get('thread') as string | null;
40
43
  const thread = threadString ? JSON.parse(threadString) : undefined;
41
- const messageContext = formData.get('message') as string | null; // Optional text context or previous message?
44
+ // const messageContext = formData.get('message') as string | null; // Optional text context or previous message?
42
45
 
43
46
  if (!audioFile) {
44
47
  return new Response(JSON.stringify({ error: 'No audio file provided' }), {
@@ -1,14 +1,17 @@
1
1
  import { $provideAgentCollectionForServer } from '@/src/tools/$provideAgentCollectionForServer';
2
2
  import { $provideExecutionToolsForServer } from '@/src/tools/$provideExecutionToolsForServer';
3
- import { $bookTranspilersRegister } from '../../../../../../../../src/transpilers/_common/register/$bookTranspilersRegister';
4
3
  import { NextRequest, NextResponse } from 'next/server';
4
+ import { $bookTranspilersRegister } from '../../../../../../../../src/transpilers/_common/register/$bookTranspilersRegister';
5
+ import { keepUnused } from '../../../../../../../../src/utils/organization/keepUnused';
5
6
 
6
7
  export async function GET(request: NextRequest, { params }: { params: Promise<{ agentName: string }> }) {
7
- const agentName = (await params).agentName;
8
+ keepUnused(request);
9
+ keepUnused(params);
10
+ // const agentName = (await params).agentName;
8
11
 
9
12
  try {
10
13
  // Get available transpilers
11
- const transpilers = $bookTranspilersRegister.list().map(transpiler => ({
14
+ const transpilers = $bookTranspilersRegister.list().map((transpiler) => ({
12
15
  name: transpiler.name,
13
16
  title: transpiler.title,
14
17
  }));
@@ -32,7 +35,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
32
35
 
33
36
  // Get the transpiler
34
37
  const allTranspilers = $bookTranspilersRegister.list();
35
- const transpiler = allTranspilers.find(t => t.name === transpilerName);
38
+ const transpiler = allTranspilers.find((t) => t.name === transpilerName);
36
39
  if (!transpiler) {
37
40
  return NextResponse.json({ error: 'Transpiler not found' }, { status: 404 });
38
41
  }
@@ -56,9 +59,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
56
59
  transpiler: {
57
60
  name: transpiler.name,
58
61
  title: transpiler.title,
59
- }
62
+ },
60
63
  });
61
-
62
64
  } catch (error) {
63
65
  console.error('Error transpiling code:', error);
64
66
  return NextResponse.json({ error: 'Failed to transpile code' }, { status: 500 });