@agent-platform/ui 0.0.11 → 0.0.13

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 (111) hide show
  1. package/README.md +27 -10
  2. package/dist/index.d.ts +35 -3
  3. package/dist/index.js +2462 -2
  4. package/dist/styles/agent-ui.css +1226 -0
  5. package/dist/styles/globals.css +18 -902
  6. package/dist/styles/theme.css +34 -0
  7. package/package.json +14 -8
  8. package/dist/components/agent/agent-container-model.d.ts +0 -19
  9. package/dist/components/agent/agent-container-model.js +0 -17
  10. package/dist/components/agent/agent-container-state.d.ts +0 -2
  11. package/dist/components/agent/agent-container-state.js +0 -52
  12. package/dist/components/agent/agent-container-view.d.ts +0 -20
  13. package/dist/components/agent/agent-container-view.js +0 -19
  14. package/dist/components/agent/agent-container-view.test.d.ts +0 -1
  15. package/dist/components/agent/agent-container-view.test.js +0 -16
  16. package/dist/components/agent/agent-container.d.ts +0 -3
  17. package/dist/components/agent/agent-container.js +0 -24
  18. package/dist/components/agent/agent-greeting.d.ts +0 -3
  19. package/dist/components/agent/agent-greeting.js +0 -7
  20. package/dist/components/agent/agent-header.d.ts +0 -3
  21. package/dist/components/agent/agent-header.js +0 -9
  22. package/dist/components/agent/agent-home-card.d.ts +0 -3
  23. package/dist/components/agent/agent-home-card.js +0 -7
  24. package/dist/components/agent/agent-home-cards.d.ts +0 -9
  25. package/dist/components/agent/agent-home-cards.js +0 -13
  26. package/dist/components/agent/agent-input.d.ts +0 -3
  27. package/dist/components/agent/agent-input.js +0 -51
  28. package/dist/components/agent/agent-popup-widget.d.ts +0 -15
  29. package/dist/components/agent/agent-popup-widget.js +0 -49
  30. package/dist/components/agent/agent-screen.d.ts +0 -5
  31. package/dist/components/agent/agent-screen.js +0 -7
  32. package/dist/components/agent/approval-ui-model.d.ts +0 -18
  33. package/dist/components/agent/approval-ui-model.js +0 -27
  34. package/dist/components/agent/approval-ui-model.test.d.ts +0 -1
  35. package/dist/components/agent/approval-ui-model.test.js +0 -39
  36. package/dist/components/agent/defaults.d.ts +0 -5
  37. package/dist/components/agent/defaults.js +0 -12
  38. package/dist/components/agent/index.d.ts +0 -3
  39. package/dist/components/agent/index.js +0 -1
  40. package/dist/components/agent/input-mode.d.ts +0 -5
  41. package/dist/components/agent/input-mode.js +0 -9
  42. package/dist/components/agent/message/index.d.ts +0 -8
  43. package/dist/components/agent/message/index.js +0 -4
  44. package/dist/components/agent/message/markdown.d.ts +0 -6
  45. package/dist/components/agent/message/markdown.js +0 -66
  46. package/dist/components/agent/message/message-item.d.ts +0 -7
  47. package/dist/components/agent/message/message-item.js +0 -24
  48. package/dist/components/agent/message/message-list.d.ts +0 -8
  49. package/dist/components/agent/message/message-list.js +0 -20
  50. package/dist/components/agent/message/message-loading.d.ts +0 -4
  51. package/dist/components/agent/message/message-loading.js +0 -10
  52. package/dist/components/agent/message/tool-call-card.d.ts +0 -9
  53. package/dist/components/agent/message/tool-call-card.js +0 -26
  54. package/dist/components/agent/message/utils.d.ts +0 -8
  55. package/dist/components/agent/message/utils.js +0 -21
  56. package/dist/components/agent/provider/agent-context.d.ts +0 -4
  57. package/dist/components/agent/provider/agent-context.js +0 -13
  58. package/dist/components/agent/provider/agent-provider.d.ts +0 -10
  59. package/dist/components/agent/provider/agent-provider.js +0 -40
  60. package/dist/components/agent/provider/index.d.ts +0 -4
  61. package/dist/components/agent/provider/index.js +0 -2
  62. package/dist/components/agent/provider/parse-sse-buffer.d.ts +0 -9
  63. package/dist/components/agent/provider/parse-sse-buffer.js +0 -23
  64. package/dist/components/agent/provider/runtime-config.d.ts +0 -5
  65. package/dist/components/agent/provider/runtime-config.js +0 -24
  66. package/dist/components/agent/provider/types.d.ts +0 -66
  67. package/dist/components/agent/provider/types.js +0 -1
  68. package/dist/components/agent/provider/use-agent-chat.d.ts +0 -6
  69. package/dist/components/agent/provider/use-agent-chat.js +0 -493
  70. package/dist/components/agent/tool-approval-panel.d.ts +0 -9
  71. package/dist/components/agent/tool-approval-panel.js +0 -11
  72. package/dist/components/agent/types.d.ts +0 -44
  73. package/dist/components/agent/types.js +0 -1
  74. package/dist/components/index.d.ts +0 -7
  75. package/dist/components/index.js +0 -9
  76. package/dist/components/ui/badge.d.ts +0 -9
  77. package/dist/components/ui/badge.js +0 -24
  78. package/dist/components/ui/button.d.ts +0 -10
  79. package/dist/components/ui/button.js +0 -35
  80. package/dist/components/ui/card.d.ts +0 -9
  81. package/dist/components/ui/card.js +0 -24
  82. package/dist/components/ui/input.d.ts +0 -3
  83. package/dist/components/ui/input.js +0 -6
  84. package/dist/components/ui/label.d.ts +0 -4
  85. package/dist/components/ui/label.js +0 -7
  86. package/dist/components/ui/separator.d.ts +0 -4
  87. package/dist/components/ui/separator.js +0 -8
  88. package/dist/components/ui/textarea.d.ts +0 -3
  89. package/dist/components/ui/textarea.js +0 -6
  90. package/dist/lib/index.d.ts +0 -1
  91. package/dist/lib/index.js +0 -1
  92. package/dist/lib/utils.d.ts +0 -2
  93. package/dist/lib/utils.js +0 -5
  94. package/dist/modules/agent/agent.repository.d.ts +0 -58
  95. package/dist/modules/agent/agent.repository.js +0 -235
  96. package/dist/modules/agent/agent.repository.test.d.ts +0 -1
  97. package/dist/modules/agent/agent.repository.test.js +0 -64
  98. package/dist/modules/agent/domain/chat-state.d.ts +0 -64
  99. package/dist/modules/agent/domain/chat-state.js +0 -148
  100. package/dist/modules/agent/domain/chat-state.test.d.ts +0 -1
  101. package/dist/modules/agent/domain/chat-state.test.js +0 -72
  102. package/dist/modules/agent/use-agent-chat.d.ts +0 -6
  103. package/dist/modules/agent/use-agent-chat.js +0 -106
  104. package/dist/modules/agent/usecases/process-stream.d.ts +0 -26
  105. package/dist/modules/agent/usecases/process-stream.js +0 -112
  106. package/dist/modules/agent/usecases/process-stream.test.d.ts +0 -1
  107. package/dist/modules/agent/usecases/process-stream.test.js +0 -91
  108. package/dist/modules/agent/usecases/send-message.d.ts +0 -21
  109. package/dist/modules/agent/usecases/send-message.js +0 -298
  110. package/dist/modules/agent/usecases/send-message.test.d.ts +0 -1
  111. package/dist/modules/agent/usecases/send-message.test.js +0 -257
@@ -1,9 +0,0 @@
1
- export function resolveInputMode(input) {
2
- if (input.hasActiveApprovalRequest) {
3
- return 'approval';
4
- }
5
- if (!input.showInput) {
6
- return 'none';
7
- }
8
- return 'input';
9
- }
@@ -1,8 +0,0 @@
1
- export { MessageList } from './message-list';
2
- export type { MessageListProps } from './message-list';
3
- export { MessageItem } from './message-item';
4
- export type { MessageItemProps } from './message-item';
5
- export { ToolCallCard } from './tool-call-card';
6
- export type { ToolCallCardProps } from './tool-call-card';
7
- export { MessageLoading } from './message-loading';
8
- export type { MessageLoadingProps } from './message-loading';
@@ -1,4 +0,0 @@
1
- export { MessageList } from './message-list';
2
- export { MessageItem } from './message-item';
3
- export { ToolCallCard } from './tool-call-card';
4
- export { MessageLoading } from './message-loading';
@@ -1,6 +0,0 @@
1
- interface MarkdownProps {
2
- content: string;
3
- className?: string;
4
- }
5
- export declare function Markdown({ content, className }: MarkdownProps): import("react/jsx-runtime").JSX.Element;
6
- export {};
@@ -1,66 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import ReactMarkdown from 'react-markdown';
4
- import remarkGfm from 'remark-gfm';
5
- import { cn } from '../../../lib/utils';
6
- const listItemPattern = /^\s*(?:[-*+]\s+|\d+[.)]\s+)/;
7
- const codeFenceStartPattern = /^\s*```/;
8
- const blockquotePattern = /^\s*>/;
9
- function isListItemLine(line) {
10
- return listItemPattern.test(line);
11
- }
12
- function isPotentialParagraphLine(line) {
13
- if (!line.trim())
14
- return false;
15
- if (/^(?: {4,}|\t)/.test(line))
16
- return false;
17
- const normalizedLine = line.replace(/^[ \u3000]+/, '');
18
- if (!normalizedLine)
19
- return false;
20
- if (isListItemLine(normalizedLine))
21
- return false;
22
- if (blockquotePattern.test(normalizedLine))
23
- return false;
24
- if (codeFenceStartPattern.test(normalizedLine))
25
- return false;
26
- return true;
27
- }
28
- function normalizeAgentMarkdown(content) {
29
- const lines = content.replace(/\r\n?/g, '\n').split('\n');
30
- const normalized = [];
31
- for (const line of lines) {
32
- const prevLine = normalized[normalized.length - 1] ?? '';
33
- if (isListItemLine(prevLine) && isPotentialParagraphLine(line)) {
34
- normalized.push('');
35
- }
36
- normalized.push(line);
37
- }
38
- return normalized.join('\n');
39
- }
40
- const components = {
41
- pre: ({ children }) => (_jsx("pre", { className: "bg-background/50 rounded p-2 overflow-x-auto my-1.5 text-xs", children: children })),
42
- code: ({ children, className }) => {
43
- if (className) {
44
- return _jsx("code", { className: cn('text-xs', className), children: children });
45
- }
46
- return _jsx("code", { className: "bg-background/50 px-1 py-0.5 rounded text-xs", children: children });
47
- },
48
- a: ({ href, children }) => (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", className: "text-primary underline hover:text-primary/80", children: children })),
49
- ul: ({ children }) => _jsx("ul", { className: "list-disc list-inside pl-3 my-1", children: children }),
50
- ol: ({ children }) => _jsx("ol", { className: "list-decimal list-inside pl-3 my-1", children: children }),
51
- li: ({ children }) => _jsx("li", { className: "leading-relaxed", children: children }),
52
- p: ({ children }) => _jsx("p", { className: "first:mt-0 last:mb-0", children: children }),
53
- h1: ({ children }) => _jsx("h1", { className: "text-base font-bold mt-3 mb-1 first:mt-0", children: children }),
54
- h2: ({ children }) => _jsx("h2", { className: "text-sm font-bold mt-2.5 mb-1 first:mt-0", children: children }),
55
- h3: ({ children }) => _jsx("h3", { className: "text-sm font-semibold mt-2 mb-1 first:mt-0", children: children }),
56
- blockquote: ({ children }) => (_jsx("blockquote", { className: "border-l-2 border-border pl-3 my-1.5 text-muted-foreground italic", children: children })),
57
- table: ({ children }) => (_jsx("div", { className: "overflow-x-auto my-1.5", children: _jsx("table", { className: "min-w-full border-collapse border border-border text-xs", children: children }) })),
58
- thead: ({ children }) => _jsx("thead", { className: "bg-muted/50", children: children }),
59
- th: ({ children }) => (_jsx("th", { className: "border border-border px-2 py-1.5 text-left font-semibold", children: children })),
60
- td: ({ children }) => _jsx("td", { className: "border border-border px-2 py-1.5", children: children }),
61
- hr: () => _jsx("hr", { className: "my-3 border-border" }),
62
- };
63
- export function Markdown({ content, className }) {
64
- const normalizedContent = normalizeAgentMarkdown(content);
65
- return (_jsx("div", { className: cn('text-sm leading-relaxed', className), children: _jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], components: components, children: normalizedContent }) }));
66
- }
@@ -1,7 +0,0 @@
1
- import type { AgentMessage, ToolCallState } from '../provider/types';
2
- export interface MessageItemProps {
3
- message: AgentMessage;
4
- pendingToolCalls: ToolCallState[];
5
- toolNameLabels?: Record<string, string>;
6
- }
7
- export declare function MessageItem({ message, pendingToolCalls, toolNameLabels }: MessageItemProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,24 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { cn } from '../../../lib/utils';
4
- import { Markdown } from './markdown';
5
- import { ToolCallCard } from './tool-call-card';
6
- import { extractTextContent, extractToolCalls } from './utils';
7
- export function MessageItem({ message, pendingToolCalls, toolNameLabels }) {
8
- const isUser = message.role === 'user';
9
- const textContent = extractTextContent(message.content);
10
- const toolCalls = extractToolCalls(message.content);
11
- // 空のストリーミング中の assistant メッセージは非表示(MessageLoading が表示されるため)
12
- if (!isUser && message.isStreaming && !textContent && toolCalls.length === 0) {
13
- return null;
14
- }
15
- return (_jsx("div", { className: cn('flex', isUser ? 'justify-end' : 'justify-start'), children: _jsxs("div", { className: "max-w-3/4 space-y-1.5", children: [textContent && (_jsx("div", { className: cn('rounded-lg px-3 py-2', isUser
16
- ? 'bg-muted text-foreground'
17
- : 'border border-border bg-card text-card-foreground'), children: isUser ? (_jsx("div", { className: "whitespace-pre-wrap text-sm leading-relaxed", children: textContent })) : (_jsx(Markdown, { content: textContent })) })), !isUser && toolCalls.length > 0 && (_jsx("div", { className: "ml-2 space-y-1.5 border-l-2 border-border pl-2", children: toolCalls.map((tc) => {
18
- const toolCallState = pendingToolCalls.find((p) => p.toolCall.toolCallId === tc.toolCallId);
19
- if (toolCallState) {
20
- return (_jsx(ToolCallCard, { toolCallState: toolCallState, toolNameLabels: toolNameLabels }, tc.toolCallId));
21
- }
22
- return null;
23
- }) }))] }) }));
24
- }
@@ -1,8 +0,0 @@
1
- import type { AgentMessage, ToolCallState } from '../provider/types';
2
- export interface MessageListProps {
3
- messages: AgentMessage[];
4
- pendingToolCalls: ToolCallState[];
5
- toolNameLabels?: Record<string, string>;
6
- isLoading?: boolean;
7
- }
8
- export declare function MessageList({ messages, pendingToolCalls, toolNameLabels, isLoading, }: MessageListProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,20 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useRef } from 'react';
4
- import { MessageItem } from './message-item';
5
- import { MessageLoading } from './message-loading';
6
- import { shouldShowLoadingIndicator } from './utils';
7
- export function MessageList({ messages, pendingToolCalls, toolNameLabels, isLoading = false, }) {
8
- const bottomRef = useRef(null);
9
- useEffect(() => {
10
- bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
11
- }, [messages, isLoading]);
12
- if (messages.length === 0 && !isLoading) {
13
- return null;
14
- }
15
- const showLoadingIndicator = shouldShowLoadingIndicator({
16
- messages,
17
- isLoading,
18
- });
19
- return (_jsxs("div", { className: "flex flex-col gap-3 p-3", children: [messages.map((message) => (_jsx(MessageItem, { message: message, pendingToolCalls: pendingToolCalls, toolNameLabels: toolNameLabels }, message.id))), showLoadingIndicator && _jsx(MessageLoading, {}), _jsx("div", { ref: bottomRef })] }));
20
- }
@@ -1,4 +0,0 @@
1
- export interface MessageLoadingProps {
2
- className?: string;
3
- }
4
- export declare function MessageLoading({ className }: MessageLoadingProps): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { cn } from '../../../lib/utils';
4
- /** Reusable loading dots animation */
5
- function LoadingDots() {
6
- return (_jsxs("span", { className: "flex gap-0.5", "aria-hidden": "true", children: [_jsx("span", { className: "h-0.5 w-0.5 animate-dot-fade rounded-full bg-muted-foreground/50 [animation-delay:0ms]" }), _jsx("span", { className: "h-0.5 w-0.5 animate-dot-fade rounded-full bg-muted-foreground/50 [animation-delay:150ms]" }), _jsx("span", { className: "h-0.5 w-0.5 animate-dot-fade rounded-full bg-muted-foreground/50 [animation-delay:300ms]" })] }));
7
- }
8
- export function MessageLoading({ className }) {
9
- return (_jsx("output", { className: cn('flex justify-start', className), "aria-label": "AI\u5FDC\u7B54\u3092\u5F85\u6A5F\u4E2D", children: _jsx("div", { className: "max-w-xl", children: _jsx("div", { className: "rounded-lg border border-border bg-card px-3 py-2", children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-sm text-muted-foreground", children: "\u8003\u3048\u4E2D" }), _jsx(LoadingDots, {})] }) }) }) }));
10
- }
@@ -1,9 +0,0 @@
1
- import type { ToolCallState } from '../provider/types';
2
- export interface ToolCallCardProps {
3
- toolCallState: ToolCallState;
4
- toolNameLabels?: Record<string, string>;
5
- statusLabels?: Record<string, string>;
6
- parametersLabel?: string;
7
- resultLabel?: string;
8
- }
9
- export declare function ToolCallCard({ toolCallState, toolNameLabels, statusLabels, parametersLabel, resultLabel, }: ToolCallCardProps): import("react/jsx-runtime").JSX.Element;
@@ -1,26 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { cn } from '../../../lib/utils';
4
- const defaultStatusLabels = {
5
- pending: '待機中',
6
- 'awaiting-approval': '承認待ち',
7
- executing: '実行中',
8
- completed: '完了',
9
- error: 'エラー',
10
- };
11
- const statusColors = {
12
- pending: 'bg-muted text-muted-foreground',
13
- 'awaiting-approval': 'bg-amber-50 text-amber-700 dark:bg-amber-950 dark:text-amber-300',
14
- executing: 'bg-primary/10 text-primary',
15
- completed: 'bg-green-50 text-green-600 dark:bg-green-950 dark:text-green-400',
16
- error: 'bg-destructive/10 text-destructive',
17
- };
18
- export function ToolCallCard({ toolCallState, toolNameLabels = {}, statusLabels, parametersLabel = 'パラメータ', resultLabel = '結果を表示', }) {
19
- const { toolCall, status, result, error } = toolCallState;
20
- const toolLabel = toolNameLabels[toolCall.toolName] || toolCall.toolName;
21
- const mergedStatusLabels = statusLabels
22
- ? { ...defaultStatusLabels, ...statusLabels }
23
- : defaultStatusLabels;
24
- const statusLabel = mergedStatusLabels[status];
25
- return (_jsxs("div", { className: "rounded-md p-1 mt-3 bg-card", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-xs font-medium text-foreground", children: toolLabel }), status === 'executing' ? (_jsx("div", { className: "h-3 w-3 animate-spin rounded-full border border-primary border-t-transparent" })) : (_jsx("span", { className: cn('rounded-full px-2 py-0.5 text-[11px]', statusColors[status]), children: statusLabel }))] }), _jsxs("details", { className: "mt-2", children: [_jsx("summary", { className: "cursor-pointer text-xs text-muted-foreground", children: parametersLabel }), _jsx("pre", { className: "mt-1 ml-4 overflow-x-auto rounded bg-muted p-2 text-xs text-muted-foreground", children: JSON.stringify(toolCall.input, null, 2) })] }), status === 'completed' && result !== undefined && (_jsxs("details", { className: "mt-2", children: [_jsx("summary", { className: "cursor-pointer text-xs text-muted-foreground", children: resultLabel }), _jsx("pre", { className: "mt-1 ml-4 max-h-40 overflow-auto rounded bg-muted p-2 text-xs text-muted-foreground", children: typeof result === 'string' ? result : JSON.stringify(result, null, 2) })] })), status === 'error' && error && (_jsx("div", { className: "mt-2 rounded bg-destructive/10 p-2 text-xs text-destructive", children: error }))] }));
26
- }
@@ -1,8 +0,0 @@
1
- import type { AgentMessage, ToolCallData } from '../provider/types';
2
- export interface LoadingIndicatorInput {
3
- messages: AgentMessage[];
4
- isLoading: boolean;
5
- }
6
- export declare function extractTextContent(content: AgentMessage['content']): string;
7
- export declare function extractToolCalls(content: AgentMessage['content']): ToolCallData[];
8
- export declare function shouldShowLoadingIndicator({ messages, isLoading, }: LoadingIndicatorInput): boolean;
@@ -1,21 +0,0 @@
1
- export function extractTextContent(content) {
2
- return content
3
- .filter((part) => part.type === 'text')
4
- .map((part) => part.text)
5
- .join('');
6
- }
7
- export function extractToolCalls(content) {
8
- return content
9
- .filter((part) => part.type === 'tool-call')
10
- .map((part) => part.toolCall);
11
- }
12
- export function shouldShowLoadingIndicator({ messages, isLoading, }) {
13
- if (!isLoading)
14
- return false;
15
- const lastMessage = messages[messages.length - 1];
16
- const hasNoMessages = messages.length === 0;
17
- if (hasNoMessages)
18
- return true;
19
- const lastAssistantHasContent = lastMessage?.role === 'assistant' && extractTextContent(lastMessage.content).trim().length > 0;
20
- return lastMessage?.role === 'user' || !lastAssistantHasContent;
21
- }
@@ -1,4 +0,0 @@
1
- import type { AgentContextValue } from './types';
2
- export declare const AgentContext: import("react").Context<AgentContextValue | null>;
3
- export declare function useAgentContext(): AgentContextValue;
4
- export declare function useOptionalAgentContext(): AgentContextValue | null;
@@ -1,13 +0,0 @@
1
- 'use client';
2
- import { createContext, useContext } from 'react';
3
- export const AgentContext = createContext(null);
4
- export function useAgentContext() {
5
- const context = useContext(AgentContext);
6
- if (!context) {
7
- throw new Error('useAgentContext must be used within an AgentProvider');
8
- }
9
- return context;
10
- }
11
- export function useOptionalAgentContext() {
12
- return useContext(AgentContext);
13
- }
@@ -1,10 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { AgentProviderConfig } from './types';
3
- export interface AgentProviderProps extends AgentProviderConfig {
4
- children: ReactNode;
5
- }
6
- /**
7
- * エージェントチャット機能を提供する内部Provider
8
- * 公開APIは AgentScreen / AgentPopupWidget を使用する。
9
- */
10
- export declare function AgentProvider({ children, agentId, onError, authToken, getAuthToken, getAgentHeaders, disableToolApiAuthHeader, toolApprovalLabels, }: AgentProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -1,40 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useMemo } from 'react';
4
- import { useAgentChat } from '../../../modules/agent/use-agent-chat';
5
- import { AgentContext } from './agent-context';
6
- import { resolveAgentRuntimeConfig } from './runtime-config';
7
- /**
8
- * エージェントチャット機能を提供する内部Provider
9
- * 公開APIは AgentScreen / AgentPopupWidget を使用する。
10
- */
11
- export function AgentProvider({ children, agentId, onError, authToken, getAuthToken, getAgentHeaders, disableToolApiAuthHeader, toolApprovalLabels, }) {
12
- const runtimeConfig = resolveAgentRuntimeConfig();
13
- const value = useAgentChat({
14
- config: {
15
- endpoint: runtimeConfig.endpoint,
16
- agentId,
17
- apiBaseUrl: runtimeConfig.apiBaseUrl,
18
- onError,
19
- authToken,
20
- getAuthToken,
21
- getAgentHeaders,
22
- disableToolApiAuthHeader,
23
- toolApprovalLabels,
24
- },
25
- });
26
- const contextValue = useMemo(() => value, [
27
- value.config,
28
- value.clearChat,
29
- value.error,
30
- value.isLoading,
31
- value.messages,
32
- value.pendingToolCalls,
33
- value.activeApprovalRequest,
34
- value.approveToolCall,
35
- value.rejectToolCall,
36
- value.sendMessage,
37
- value.threadId,
38
- ]);
39
- return _jsx(AgentContext.Provider, { value: contextValue, children: children });
40
- }
@@ -1,4 +0,0 @@
1
- export { useAgentContext } from './agent-context';
2
- export type { AgentProviderProps } from './agent-provider';
3
- export { AgentProvider } from './agent-provider';
4
- export type { ActiveToolApprovalRequest, AgentContextValue, AgentMessage, AgentProviderConfig, ToolApprovalLabels, AgentStreamEvent, FinishPayload, MessageContentPart, ToolCallData, ToolCallState, ToolCallStatus, ToolResultData, } from './types';
@@ -1,2 +0,0 @@
1
- export { useAgentContext } from './agent-context';
2
- export { AgentProvider } from './agent-provider';
@@ -1,9 +0,0 @@
1
- import type { AgentStreamEvent } from './types';
2
- export interface ParseResult {
3
- events: AgentStreamEvent[];
4
- remaining: string;
5
- }
6
- /**
7
- * SSEバッファからイベントをパースする
8
- */
9
- export declare function parseSSEBuffer(buffer: string): ParseResult;
@@ -1,23 +0,0 @@
1
- /**
2
- * SSEバッファからイベントをパースする
3
- */
4
- export function parseSSEBuffer(buffer) {
5
- const events = [];
6
- const lines = buffer.split('\n');
7
- const remaining = lines.pop() || '';
8
- for (const line of lines) {
9
- if (!line.startsWith('data: '))
10
- continue;
11
- const jsonStr = line.slice(6);
12
- if (!jsonStr)
13
- continue;
14
- try {
15
- const event = JSON.parse(jsonStr);
16
- events.push(event);
17
- }
18
- catch (e) {
19
- console.warn('Failed to parse SSE event:', e);
20
- }
21
- }
22
- return { events, remaining };
23
- }
@@ -1,5 +0,0 @@
1
- export interface AgentRuntimeConfig {
2
- endpoint: string;
3
- apiBaseUrl: string;
4
- }
5
- export declare function resolveAgentRuntimeConfig(): AgentRuntimeConfig;
@@ -1,24 +0,0 @@
1
- const isDevelopment = process.env.NODE_ENV === 'development';
2
- const PRODUCTION_AGENT_ENDPOINT = 'https://agent-server-prod--agent-platform-dev-8e3ae.asia-east1.hosted.app/api/agent';
3
- const DEVELOPMENT_AGENT_ENDPOINT = 'http://localhost:3002/api/agent';
4
- const PRODUCTION_API_BASE_URL = 'https://demo-scout-api-prod--agent-platform-dev-8e3ae.asia-east1.hosted.app/api';
5
- const DEVELOPMENT_API_BASE_URL = 'http://localhost:3001/api';
6
- function normalizeUrl(url) {
7
- return url.replace(/\/$/, '');
8
- }
9
- export function resolveAgentRuntimeConfig() {
10
- const endpoint = process.env.NEXT_PUBLIC_AGENT_ENDPOINT
11
- ? process.env.NEXT_PUBLIC_AGENT_ENDPOINT
12
- : isDevelopment
13
- ? DEVELOPMENT_AGENT_ENDPOINT
14
- : PRODUCTION_AGENT_ENDPOINT;
15
- const apiBaseUrl = process.env.NEXT_PUBLIC_API_URL
16
- ? process.env.NEXT_PUBLIC_API_URL
17
- : isDevelopment
18
- ? DEVELOPMENT_API_BASE_URL
19
- : PRODUCTION_API_BASE_URL;
20
- return {
21
- endpoint: normalizeUrl(endpoint),
22
- apiBaseUrl: normalizeUrl(apiBaseUrl),
23
- };
24
- }
@@ -1,66 +0,0 @@
1
- export type { AgentStreamEvent, ToolCallData, ToolResultData, FinishPayload, MessageContentPart, AgentMessage, } from '@agent-platform/server';
2
- /**
3
- * ツール実行状態
4
- */
5
- export type ToolCallStatus = 'pending' | 'awaiting-approval' | 'executing' | 'completed' | 'error';
6
- /**
7
- * ツールコール状態(UI表示用)
8
- */
9
- export interface ToolCallState {
10
- toolCall: import('@agent-platform/server').ToolCallData;
11
- status: ToolCallStatus;
12
- result?: unknown;
13
- error?: string;
14
- }
15
- export interface ActiveToolApprovalRequest {
16
- toolCall: import('@agent-platform/server').ToolCallData;
17
- actionLabel: string;
18
- riskLevel: 'read' | 'write' | 'destructive';
19
- }
20
- export interface ToolApprovalLabels {
21
- title?: string;
22
- description?: string;
23
- approveButton?: string;
24
- rejectButton?: string;
25
- }
26
- export type AgentHeadersProvider = () => Record<string, string> | Promise<Record<string, string>>;
27
- /**
28
- * AgentProvider設定
29
- */
30
- export interface AgentProviderConfig {
31
- agentId?: string;
32
- onError?: (error: string) => void;
33
- /** 静的なJWTトークン */
34
- authToken?: string;
35
- /** 動的にトークンを取得する関数(authTokenより優先) */
36
- getAuthToken?: () => string | Promise<string>;
37
- /** Agent Server リクエストにのみ追加するヘッダー */
38
- getAgentHeaders?: AgentHeadersProvider;
39
- /** trueの場合、Tool APIへのAuthorizationヘッダー付与を無効化する */
40
- disableToolApiAuthHeader?: boolean;
41
- /** 承認UI文言の上書き */
42
- toolApprovalLabels?: ToolApprovalLabels;
43
- }
44
- /**
45
- * Agent通信先を解決済みの内部設定
46
- */
47
- export interface ResolvedAgentRuntimeConfig extends AgentProviderConfig {
48
- endpoint: string;
49
- apiBaseUrl: string;
50
- }
51
- /**
52
- * AgentContext値
53
- */
54
- export interface AgentContextValue {
55
- messages: import('@agent-platform/server').AgentMessage[];
56
- threadId: string | null;
57
- isLoading: boolean;
58
- error: string | null;
59
- pendingToolCalls: ToolCallState[];
60
- activeApprovalRequest: ActiveToolApprovalRequest | null;
61
- approveToolCall: () => void;
62
- rejectToolCall: () => void;
63
- sendMessage: (message: string) => Promise<void>;
64
- clearChat: () => void;
65
- config: ResolvedAgentRuntimeConfig;
66
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import type { AgentContextValue, ResolvedAgentRuntimeConfig } from './types';
2
- interface UseAgentChatOptions {
3
- config: ResolvedAgentRuntimeConfig;
4
- }
5
- export declare function useAgentChatInternal(options: UseAgentChatOptions): AgentContextValue;
6
- export {};