@4djs/assistant 0.0.0 → 0.1.0
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/README.md +49 -68
- package/dist/core/chat-activity.d.ts +19 -0
- package/dist/core/chat-activity.d.ts.map +1 -0
- package/dist/core/chat-commands.d.ts +33 -0
- package/dist/core/chat-commands.d.ts.map +1 -0
- package/dist/core/chat-history.d.ts +14 -0
- package/dist/core/chat-history.d.ts.map +1 -0
- package/dist/core/chat-reply-suggestions-parse.d.ts +20 -0
- package/dist/core/chat-reply-suggestions-parse.d.ts.map +1 -0
- package/dist/core/code-highlight.d.ts +3 -0
- package/dist/core/code-highlight.d.ts.map +1 -0
- package/dist/core/create-assistant-store.d.ts +33 -0
- package/dist/core/create-assistant-store.d.ts.map +1 -0
- package/dist/core/fetch-suggested-prompts.d.ts +11 -0
- package/dist/core/fetch-suggested-prompts.d.ts.map +1 -0
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +2876 -0
- package/dist/core/interactive-tools/choices.d.ts +22 -0
- package/dist/core/interactive-tools/choices.d.ts.map +1 -0
- package/dist/core/interactive-tools/confirmation.d.ts +15 -0
- package/dist/core/interactive-tools/confirmation.d.ts.map +1 -0
- package/dist/core/interactive-tools/constants.d.ts +6 -0
- package/dist/core/interactive-tools/constants.d.ts.map +1 -0
- package/dist/core/interactive-tools/execute.d.ts +11 -0
- package/dist/core/interactive-tools/execute.d.ts.map +1 -0
- package/dist/core/interactive-tools/index.d.ts +7 -0
- package/dist/core/interactive-tools/index.d.ts.map +1 -0
- package/dist/core/interactive-tools/suggestions.d.ts +13 -0
- package/dist/core/interactive-tools/suggestions.d.ts.map +1 -0
- package/dist/core/interactive-tools/waiters.d.ts +4 -0
- package/dist/core/interactive-tools/waiters.d.ts.map +1 -0
- package/dist/core/llm-chat.d.ts +96 -0
- package/dist/core/llm-chat.d.ts.map +1 -0
- package/dist/core/llm-config.d.ts +24 -0
- package/dist/core/llm-config.d.ts.map +1 -0
- package/dist/core/llm-models.d.ts +14 -0
- package/dist/core/llm-models.d.ts.map +1 -0
- package/dist/core/llm-provider.d.ts +13 -0
- package/dist/core/llm-provider.d.ts.map +1 -0
- package/dist/core/llm-settings-storage.d.ts +47 -0
- package/dist/core/llm-settings-storage.d.ts.map +1 -0
- package/dist/core/llm-sse.d.ts +13 -0
- package/dist/core/llm-sse.d.ts.map +1 -0
- package/dist/core/llm-types.d.ts +49 -0
- package/dist/core/llm-types.d.ts.map +1 -0
- package/dist/core/markdown-utils.d.ts +3 -0
- package/dist/core/markdown-utils.d.ts.map +1 -0
- package/dist/core/prepare-markdown.d.ts +7 -0
- package/dist/core/prepare-markdown.d.ts.map +1 -0
- package/dist/core/types.d.ts +74 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/index.css +1195 -0
- package/dist/index.js +184948 -0
- package/dist/react/Assistant.d.ts +10 -0
- package/dist/react/Assistant.d.ts.map +1 -0
- package/dist/react/components/HighlightedJsonCode.d.ts +6 -0
- package/dist/react/components/HighlightedJsonCode.d.ts.map +1 -0
- package/dist/react/components/MarkdownContent.d.ts +10 -0
- package/dist/react/components/MarkdownContent.d.ts.map +1 -0
- package/dist/react/components/MarkdownEditor.d.ts +11 -0
- package/dist/react/components/MarkdownEditor.d.ts.map +1 -0
- package/dist/react/components/MermaidDiagram.d.ts +8 -0
- package/dist/react/components/MermaidDiagram.d.ts.map +1 -0
- package/dist/react/components/ModelSelector.d.ts +8 -0
- package/dist/react/components/ModelSelector.d.ts.map +1 -0
- package/dist/react/components/chat/AssistantErrorCallout.d.ts +11 -0
- package/dist/react/components/chat/AssistantErrorCallout.d.ts.map +1 -0
- package/dist/react/components/chat/ChatActivity.d.ts +8 -0
- package/dist/react/components/chat/ChatActivity.d.ts.map +1 -0
- package/dist/react/components/chat/ChatComposer.d.ts +36 -0
- package/dist/react/components/chat/ChatComposer.d.ts.map +1 -0
- package/dist/react/components/chat/ChatEmptyState.d.ts +10 -0
- package/dist/react/components/chat/ChatEmptyState.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/choices-prompt.d.ts +7 -0
- package/dist/react/components/chat/ChatInteractivePrompt/choices-prompt.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/confirmation-prompt.d.ts +7 -0
- package/dist/react/components/chat/ChatInteractivePrompt/confirmation-prompt.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/index.d.ts +7 -0
- package/dist/react/components/chat/ChatInteractivePrompt/index.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/shell.d.ts +13 -0
- package/dist/react/components/chat/ChatInteractivePrompt/shell.d.ts.map +1 -0
- package/dist/react/components/chat/ChatInteractivePrompt/utils.d.ts +4 -0
- package/dist/react/components/chat/ChatInteractivePrompt/utils.d.ts.map +1 -0
- package/dist/react/components/chat/ChatMessage.d.ts +11 -0
- package/dist/react/components/chat/ChatMessage.d.ts.map +1 -0
- package/dist/react/components/chat/ChatMessageScroll.d.ts +8 -0
- package/dist/react/components/chat/ChatMessageScroll.d.ts.map +1 -0
- package/dist/react/components/chat/ChatReplySuggestions.d.ts +9 -0
- package/dist/react/components/chat/ChatReplySuggestions.d.ts.map +1 -0
- package/dist/react/components/chat/ComposerCommandMenu.d.ts +10 -0
- package/dist/react/components/chat/ComposerCommandMenu.d.ts.map +1 -0
- package/dist/react/components/chat/LlmSettingsStrip.d.ts +7 -0
- package/dist/react/components/chat/LlmSettingsStrip.d.ts.map +1 -0
- package/dist/react/components/chat/LlmSetupPrompt.d.ts +7 -0
- package/dist/react/components/chat/LlmSetupPrompt.d.ts.map +1 -0
- package/dist/react/components/chat/LlmUnavailableBanner.d.ts +6 -0
- package/dist/react/components/chat/LlmUnavailableBanner.d.ts.map +1 -0
- package/dist/react/components/chat/SuggestedPromptsList.d.ts +14 -0
- package/dist/react/components/chat/SuggestedPromptsList.d.ts.map +1 -0
- package/dist/react/components/chat/SuggestedPromptsStrip.d.ts +11 -0
- package/dist/react/components/chat/SuggestedPromptsStrip.d.ts.map +1 -0
- package/dist/react/components/chat/SystemPromptField.d.ts +10 -0
- package/dist/react/components/chat/SystemPromptField.d.ts.map +1 -0
- package/dist/react/components/highlighted-code.d.ts +8 -0
- package/dist/react/components/highlighted-code.d.ts.map +1 -0
- package/dist/react/context.d.ts +11 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/hooks/use-composer-commands.d.ts +21 -0
- package/dist/react/hooks/use-composer-commands.d.ts.map +1 -0
- package/dist/react/hooks/use-suggested-prompts.d.ts +29 -0
- package/dist/react/hooks/use-suggested-prompts.d.ts.map +1 -0
- package/dist/react/index.d.ts +17 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/lib/parse-assistant-error.d.ts +9 -0
- package/dist/react/lib/parse-assistant-error.d.ts.map +1 -0
- package/dist/react/lib/prompt-icons.d.ts +5 -0
- package/dist/react/lib/prompt-icons.d.ts.map +1 -0
- package/dist/react/types.d.ts +69 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/utils/cn.d.ts +2 -0
- package/dist/react/utils/cn.d.ts.map +1 -0
- package/package.json +16 -5
- package/src/core/chat-activity.ts +0 -107
- package/src/core/chat-commands.ts +0 -173
- package/src/core/chat-history.ts +0 -113
- package/src/core/chat-reply-suggestions-parse.ts +0 -119
- package/src/core/code-highlight.ts +0 -20
- package/src/core/create-assistant-store.ts +0 -639
- package/src/core/fetch-suggested-prompts.ts +0 -53
- package/src/core/index.ts +0 -125
- package/src/core/interactive-tools/choices.ts +0 -155
- package/src/core/interactive-tools/confirmation.ts +0 -63
- package/src/core/interactive-tools/constants.ts +0 -22
- package/src/core/interactive-tools/execute.ts +0 -70
- package/src/core/interactive-tools/index.ts +0 -41
- package/src/core/interactive-tools/suggestions.ts +0 -87
- package/src/core/interactive-tools/waiters.ts +0 -55
- package/src/core/llm-chat.ts +0 -686
- package/src/core/llm-config.ts +0 -101
- package/src/core/llm-models.ts +0 -96
- package/src/core/llm-provider.ts +0 -99
- package/src/core/llm-settings-storage.ts +0 -331
- package/src/core/llm-sse.ts +0 -166
- package/src/core/llm-types.ts +0 -52
- package/src/core/markdown-utils.ts +0 -11
- package/src/core/prepare-markdown.ts +0 -38
- package/src/core/types.ts +0 -86
- package/src/css.d.ts +0 -1
- package/src/react/Assistant.tsx +0 -358
- package/src/react/components/HighlightedJsonCode.tsx +0 -24
- package/src/react/components/MarkdownContent.tsx +0 -98
- package/src/react/components/MarkdownEditor.tsx +0 -60
- package/src/react/components/MermaidDiagram.tsx +0 -139
- package/src/react/components/ModelSelector.tsx +0 -243
- package/src/react/components/chat/AssistantErrorCallout.tsx +0 -79
- package/src/react/components/chat/ChatActivity.tsx +0 -274
- package/src/react/components/chat/ChatComposer.tsx +0 -189
- package/src/react/components/chat/ChatEmptyState.tsx +0 -145
- package/src/react/components/chat/ChatInteractivePrompt/choices-prompt.tsx +0 -262
- package/src/react/components/chat/ChatInteractivePrompt/confirmation-prompt.tsx +0 -97
- package/src/react/components/chat/ChatInteractivePrompt/index.tsx +0 -60
- package/src/react/components/chat/ChatInteractivePrompt/shell.tsx +0 -60
- package/src/react/components/chat/ChatInteractivePrompt/utils.ts +0 -14
- package/src/react/components/chat/ChatMessage.tsx +0 -150
- package/src/react/components/chat/ChatMessageScroll.tsx +0 -116
- package/src/react/components/chat/ChatReplySuggestions.tsx +0 -231
- package/src/react/components/chat/ComposerCommandMenu.tsx +0 -69
- package/src/react/components/chat/LlmSettingsStrip.tsx +0 -348
- package/src/react/components/chat/LlmSetupPrompt.tsx +0 -58
- package/src/react/components/chat/LlmUnavailableBanner.tsx +0 -11
- package/src/react/components/chat/SuggestedPromptsList.tsx +0 -121
- package/src/react/components/chat/SuggestedPromptsStrip.tsx +0 -72
- package/src/react/components/chat/SystemPromptField.tsx +0 -107
- package/src/react/components/highlighted-code.tsx +0 -107
- package/src/react/context.tsx +0 -72
- package/src/react/hooks/use-composer-commands.ts +0 -129
- package/src/react/hooks/use-suggested-prompts.ts +0 -128
- package/src/react/index.ts +0 -39
- package/src/react/lib/parse-assistant-error.ts +0 -96
- package/src/react/lib/prompt-icons.ts +0 -40
- package/src/react/types.ts +0 -83
- package/src/react/utils/cn.ts +0 -5
- package/test/buildLlmHistory.test.ts +0 -95
- package/test/llm-config.test.ts +0 -72
- package/test/llmSettingsStorage.test.ts +0 -121
- package/test/parse-assistant-error.test.ts +0 -24
- package/tsconfig.json +0 -8
- /package/{src/styles/assistant.css → dist/styles.css} +0 -0
package/src/core/index.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
export type { ChatActivityStep } from "./chat-activity.ts";
|
|
2
|
-
export {
|
|
3
|
-
chatActivityStepLabel,
|
|
4
|
-
formatJsonIfLarge,
|
|
5
|
-
summarizeActivityResult,
|
|
6
|
-
} from "./chat-activity.ts";
|
|
7
|
-
export type {
|
|
8
|
-
AssistantCommandDeps,
|
|
9
|
-
ChatCommandRunResult,
|
|
10
|
-
ChatCommandSuggestion,
|
|
11
|
-
ChatCommandSurface,
|
|
12
|
-
} from "./chat-commands.ts";
|
|
13
|
-
export {
|
|
14
|
-
filterChatCommands,
|
|
15
|
-
getChatCommandSuggestions,
|
|
16
|
-
isChatCommandInput,
|
|
17
|
-
listChatCommands,
|
|
18
|
-
parseChatCommand,
|
|
19
|
-
runAssistantChatCommand,
|
|
20
|
-
shouldShowChatCommandMenu,
|
|
21
|
-
} from "./chat-commands.ts";
|
|
22
|
-
export { createChatHistoryHelpers } from "./chat-history.ts";
|
|
23
|
-
export {
|
|
24
|
-
type AssistantState,
|
|
25
|
-
createAssistantStore,
|
|
26
|
-
} from "./create-assistant-store.ts";
|
|
27
|
-
export {
|
|
28
|
-
parseSuggestedPromptsResponse,
|
|
29
|
-
type SuggestedPromptsResponse,
|
|
30
|
-
} from "./fetch-suggested-prompts.ts";
|
|
31
|
-
export {
|
|
32
|
-
CHOICES_TOOL,
|
|
33
|
-
type ChoiceOption,
|
|
34
|
-
type ChoicesToolArgs,
|
|
35
|
-
CONFIRMATION_TOOL,
|
|
36
|
-
type ConfirmationToolArgs,
|
|
37
|
-
type ReplySuggestions,
|
|
38
|
-
rejectAllInteractiveToolWaiters,
|
|
39
|
-
resolveInteractiveToolResult,
|
|
40
|
-
SUGGEST_REPLIES_TOOL,
|
|
41
|
-
} from "./interactive-tools/index.ts";
|
|
42
|
-
export type {
|
|
43
|
-
AgentStepResult,
|
|
44
|
-
LlmChatStatus,
|
|
45
|
-
StreamHandlers,
|
|
46
|
-
ToolHandlers,
|
|
47
|
-
} from "./llm-chat.ts";
|
|
48
|
-
export {
|
|
49
|
-
buildLlmHistory,
|
|
50
|
-
ChatAbortedError,
|
|
51
|
-
fetchLlmStatus,
|
|
52
|
-
LlmNotConfiguredError,
|
|
53
|
-
LlmUpstreamError,
|
|
54
|
-
requestLlmCompletion,
|
|
55
|
-
runLlmAgent,
|
|
56
|
-
sanitizeLlmMessages,
|
|
57
|
-
} from "./llm-chat.ts";
|
|
58
|
-
export {
|
|
59
|
-
buildCompletionsUrl,
|
|
60
|
-
buildLlmRequestHeaders,
|
|
61
|
-
buildModelsUrl,
|
|
62
|
-
DEFAULT_LLM_BASE_URL,
|
|
63
|
-
DEFAULT_LLM_MODEL,
|
|
64
|
-
getFallbackModels,
|
|
65
|
-
isLlmConfigured,
|
|
66
|
-
isLlmUnavailableMessage,
|
|
67
|
-
isLocalLlmBaseUrl,
|
|
68
|
-
LLM_UNAVAILABLE_MESSAGE,
|
|
69
|
-
} from "./llm-config.ts";
|
|
70
|
-
export {
|
|
71
|
-
clearProviderModelCache,
|
|
72
|
-
fetchProviderModels,
|
|
73
|
-
} from "./llm-models.ts";
|
|
74
|
-
export {
|
|
75
|
-
configureAssistantLlm,
|
|
76
|
-
resetAssistantLlm,
|
|
77
|
-
resolveAssistantLlmSettings,
|
|
78
|
-
testLlmConnection,
|
|
79
|
-
} from "./llm-provider.ts";
|
|
80
|
-
export type {
|
|
81
|
-
LlmSettingsFormState,
|
|
82
|
-
LlmSettingsFormValues,
|
|
83
|
-
StoredLlmUserSettings,
|
|
84
|
-
} from "./llm-settings-storage.ts";
|
|
85
|
-
export {
|
|
86
|
-
assistantToStored,
|
|
87
|
-
buildDefaultLlmSettings,
|
|
88
|
-
createDefaultStoredSettings,
|
|
89
|
-
createLlmSettingsFormState,
|
|
90
|
-
createLlmSettingsFormStateFromStored,
|
|
91
|
-
createLlmSettingsStorage,
|
|
92
|
-
DEFAULT_LLM_SETTINGS_STORAGE_KEY,
|
|
93
|
-
formatModelsText,
|
|
94
|
-
isLlmSettingsFormDirty,
|
|
95
|
-
mergeLlmSettings,
|
|
96
|
-
migrateLegacyModelStorage,
|
|
97
|
-
normalizeStoredSettings,
|
|
98
|
-
normalizeStoredSystemPrompt,
|
|
99
|
-
parseModelsText,
|
|
100
|
-
peekStoredModel,
|
|
101
|
-
persistStoredModelSelection,
|
|
102
|
-
resolveSelectedModel,
|
|
103
|
-
storedSettingsHaveOverrides,
|
|
104
|
-
storedToAssistant,
|
|
105
|
-
toStoredSettings,
|
|
106
|
-
} from "./llm-settings-storage.ts";
|
|
107
|
-
export type {
|
|
108
|
-
ClientToolDefinition,
|
|
109
|
-
LlmChatMessage,
|
|
110
|
-
OpenAiToolCall,
|
|
111
|
-
} from "./llm-types.ts";
|
|
112
|
-
export { childrenToText } from "./markdown-utils.ts";
|
|
113
|
-
export type {
|
|
114
|
-
AssistantLlmConfig,
|
|
115
|
-
AssistantLlmSettings,
|
|
116
|
-
AssistantMessage,
|
|
117
|
-
AssistantStorageKeys,
|
|
118
|
-
AssistantStoreDependencies,
|
|
119
|
-
AssistantSuggestedPrompt,
|
|
120
|
-
AssistantToolContent,
|
|
121
|
-
AssistantToolDefinition,
|
|
122
|
-
AssistantToolResult,
|
|
123
|
-
AssistantWelcomeContext,
|
|
124
|
-
JsonSchema,
|
|
125
|
-
} from "./types.ts";
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from "../llm-types.ts";
|
|
2
|
-
|
|
3
|
-
export const REQUEST_CHOICES_TOOL = "request_choices";
|
|
4
|
-
|
|
5
|
-
export type ChoiceOption = {
|
|
6
|
-
id: string;
|
|
7
|
-
label: string;
|
|
8
|
-
description?: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type ChoicesToolArgs = {
|
|
12
|
-
message: string;
|
|
13
|
-
options: ChoiceOption[];
|
|
14
|
-
allowMultiple: boolean;
|
|
15
|
-
minSelections: number;
|
|
16
|
-
maxSelections?: number;
|
|
17
|
-
submitLabel: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type ChoicesToolResult = {
|
|
21
|
-
selected: string[];
|
|
22
|
-
cancelled?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const CHOICES_TOOL: ClientToolDefinition = {
|
|
26
|
-
name: REQUEST_CHOICES_TOOL,
|
|
27
|
-
description:
|
|
28
|
-
"Present options when multiple valid paths exist and you need the user to choose before continuing. Supports single-select and multi-select.",
|
|
29
|
-
inputSchema: {
|
|
30
|
-
type: "object",
|
|
31
|
-
properties: {
|
|
32
|
-
message: {
|
|
33
|
-
type: "string",
|
|
34
|
-
description: "Prompt explaining what the user should choose.",
|
|
35
|
-
},
|
|
36
|
-
options: {
|
|
37
|
-
type: "array",
|
|
38
|
-
minItems: 2,
|
|
39
|
-
items: {
|
|
40
|
-
type: "object",
|
|
41
|
-
properties: {
|
|
42
|
-
id: {
|
|
43
|
-
type: "string",
|
|
44
|
-
description: "Stable option id returned in the tool result.",
|
|
45
|
-
},
|
|
46
|
-
label: {
|
|
47
|
-
type: "string",
|
|
48
|
-
description: "User-visible option label.",
|
|
49
|
-
},
|
|
50
|
-
description: {
|
|
51
|
-
type: "string",
|
|
52
|
-
description: "Optional longer description for the option.",
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
required: ["id", "label"],
|
|
56
|
-
additionalProperties: false,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
allowMultiple: {
|
|
60
|
-
type: "boolean",
|
|
61
|
-
description: "If true, the user may select multiple options.",
|
|
62
|
-
},
|
|
63
|
-
minSelections: {
|
|
64
|
-
type: "integer",
|
|
65
|
-
description:
|
|
66
|
-
"Minimum number of selections when allowMultiple is true. Default: 1.",
|
|
67
|
-
},
|
|
68
|
-
maxSelections: {
|
|
69
|
-
type: "integer",
|
|
70
|
-
description: "Maximum number of selections when allowMultiple is true.",
|
|
71
|
-
},
|
|
72
|
-
submitLabel: {
|
|
73
|
-
type: "string",
|
|
74
|
-
description: "Submit button label. Default: Continue.",
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
required: ["message", "options"],
|
|
78
|
-
additionalProperties: false,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export function parseChoicesArgs(
|
|
83
|
-
args: Record<string, unknown>,
|
|
84
|
-
): ChoicesToolArgs {
|
|
85
|
-
const message = String(args.message ?? "").trim();
|
|
86
|
-
if (!message) {
|
|
87
|
-
throw new Error("request_choices requires a non-empty message");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!Array.isArray(args.options) || args.options.length < 2) {
|
|
91
|
-
throw new Error("request_choices requires at least two options");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const options: ChoiceOption[] = [];
|
|
95
|
-
const seenIds = new Set<string>();
|
|
96
|
-
|
|
97
|
-
for (const entry of args.options) {
|
|
98
|
-
if (!entry || typeof entry !== "object") {
|
|
99
|
-
throw new Error("Each choice option must be an object with id and label");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const option = entry as Record<string, unknown>;
|
|
103
|
-
const id = String(option.id ?? "").trim();
|
|
104
|
-
const label = String(option.label ?? "").trim();
|
|
105
|
-
|
|
106
|
-
if (!id || !label) {
|
|
107
|
-
throw new Error("Each choice option requires a non-empty id and label");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (seenIds.has(id)) {
|
|
111
|
-
throw new Error(`Duplicate choice option id: ${id}`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
seenIds.add(id);
|
|
115
|
-
options.push({
|
|
116
|
-
id,
|
|
117
|
-
label,
|
|
118
|
-
description:
|
|
119
|
-
option.description !== undefined
|
|
120
|
-
? String(option.description).trim()
|
|
121
|
-
: undefined,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const allowMultiple = Boolean(args.allowMultiple);
|
|
126
|
-
const minSelections =
|
|
127
|
-
typeof args.minSelections === "number" && args.minSelections > 0
|
|
128
|
-
? Math.floor(args.minSelections)
|
|
129
|
-
: 1;
|
|
130
|
-
const maxSelections =
|
|
131
|
-
typeof args.maxSelections === "number" && args.maxSelections > 0
|
|
132
|
-
? Math.floor(args.maxSelections)
|
|
133
|
-
: undefined;
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
allowMultiple &&
|
|
137
|
-
maxSelections !== undefined &&
|
|
138
|
-
maxSelections < minSelections
|
|
139
|
-
) {
|
|
140
|
-
throw new Error(
|
|
141
|
-
"maxSelections must be greater than or equal to minSelections",
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
message,
|
|
147
|
-
options,
|
|
148
|
-
allowMultiple,
|
|
149
|
-
minSelections: allowMultiple ? minSelections : 1,
|
|
150
|
-
maxSelections: allowMultiple ? maxSelections : 1,
|
|
151
|
-
submitLabel: args.submitLabel
|
|
152
|
-
? String(args.submitLabel).trim()
|
|
153
|
-
: "Continue",
|
|
154
|
-
};
|
|
155
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from "../llm-types.ts";
|
|
2
|
-
|
|
3
|
-
export const REQUEST_CONFIRMATION_TOOL = "request_confirmation";
|
|
4
|
-
|
|
5
|
-
export type ConfirmationToolArgs = {
|
|
6
|
-
message: string;
|
|
7
|
-
action?: string;
|
|
8
|
-
confirmLabel: string;
|
|
9
|
-
cancelLabel: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type ConfirmationToolResult = {
|
|
13
|
-
confirmed: boolean;
|
|
14
|
-
cancelled?: boolean;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const CONFIRMATION_TOOL: ClientToolDefinition = {
|
|
18
|
-
name: REQUEST_CONFIRMATION_TOOL,
|
|
19
|
-
description:
|
|
20
|
-
"Ask the user to confirm before proceeding with an important or irreversible action. Execution pauses until the user confirms or cancels.",
|
|
21
|
-
inputSchema: {
|
|
22
|
-
type: "object",
|
|
23
|
-
properties: {
|
|
24
|
-
message: {
|
|
25
|
-
type: "string",
|
|
26
|
-
description: "Explanation or question shown to the user.",
|
|
27
|
-
},
|
|
28
|
-
action: {
|
|
29
|
-
type: "string",
|
|
30
|
-
description:
|
|
31
|
-
"Short summary of what happens if confirmed, e.g. 'Delete 3 User records'.",
|
|
32
|
-
},
|
|
33
|
-
confirmLabel: {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "Confirm button label. Default: Proceed.",
|
|
36
|
-
},
|
|
37
|
-
cancelLabel: {
|
|
38
|
-
type: "string",
|
|
39
|
-
description: "Cancel button label. Default: Cancel.",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
required: ["message"],
|
|
43
|
-
additionalProperties: false,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export function parseConfirmationArgs(
|
|
48
|
-
args: Record<string, unknown>,
|
|
49
|
-
): ConfirmationToolArgs {
|
|
50
|
-
const message = String(args.message ?? "").trim();
|
|
51
|
-
if (!message) {
|
|
52
|
-
throw new Error("request_confirmation requires a non-empty message");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
message,
|
|
57
|
-
action: args.action !== undefined ? String(args.action).trim() : undefined,
|
|
58
|
-
confirmLabel: args.confirmLabel
|
|
59
|
-
? String(args.confirmLabel).trim()
|
|
60
|
-
: "Proceed",
|
|
61
|
-
cancelLabel: args.cancelLabel ? String(args.cancelLabel).trim() : "Cancel",
|
|
62
|
-
};
|
|
63
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { REQUEST_CHOICES_TOOL } from "./choices.ts";
|
|
2
|
-
import { REQUEST_CONFIRMATION_TOOL } from "./confirmation.ts";
|
|
3
|
-
import { SUGGEST_REPLIES_TOOL } from "./suggestions.ts";
|
|
4
|
-
|
|
5
|
-
export const INTERACTIVE_CHAT_TOOL_NAMES = new Set([
|
|
6
|
-
REQUEST_CONFIRMATION_TOOL,
|
|
7
|
-
REQUEST_CHOICES_TOOL,
|
|
8
|
-
]);
|
|
9
|
-
|
|
10
|
-
export const POST_RESPONSE_CHAT_TOOL_NAMES = new Set([SUGGEST_REPLIES_TOOL]);
|
|
11
|
-
|
|
12
|
-
export function isInteractiveChatTool(name: string): boolean {
|
|
13
|
-
return INTERACTIVE_CHAT_TOOL_NAMES.has(name);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function isPostResponseChatTool(name: string): boolean {
|
|
17
|
-
return POST_RESPONSE_CHAT_TOOL_NAMES.has(name);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function isChatUiTool(name: string): boolean {
|
|
21
|
-
return isInteractiveChatTool(name) || isPostResponseChatTool(name);
|
|
22
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from "../llm-types.ts";
|
|
2
|
-
import {
|
|
3
|
-
CHOICES_TOOL,
|
|
4
|
-
type ChoicesToolResult,
|
|
5
|
-
parseChoicesArgs,
|
|
6
|
-
REQUEST_CHOICES_TOOL,
|
|
7
|
-
} from "./choices.ts";
|
|
8
|
-
import {
|
|
9
|
-
CONFIRMATION_TOOL,
|
|
10
|
-
type ConfirmationToolResult,
|
|
11
|
-
parseConfirmationArgs,
|
|
12
|
-
REQUEST_CONFIRMATION_TOOL,
|
|
13
|
-
} from "./confirmation.ts";
|
|
14
|
-
import { isPostResponseChatTool } from "./constants.ts";
|
|
15
|
-
import {
|
|
16
|
-
parseSuggestRepliesArgs,
|
|
17
|
-
type ReplySuggestions,
|
|
18
|
-
SUGGEST_REPLIES_TOOL,
|
|
19
|
-
SUGGEST_REPLIES_TOOL_DEFINITION,
|
|
20
|
-
} from "./suggestions.ts";
|
|
21
|
-
import { waitForInteractiveToolResult } from "./waiters.ts";
|
|
22
|
-
|
|
23
|
-
export type ChatInteractiveToolResult = {
|
|
24
|
-
content: string;
|
|
25
|
-
postResponse?: ReplySuggestions;
|
|
26
|
-
isError?: boolean;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export function getChatInteractiveTools(): ClientToolDefinition[] {
|
|
30
|
-
return [CONFIRMATION_TOOL, CHOICES_TOOL, SUGGEST_REPLIES_TOOL_DEFINITION];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function executeChatInteractiveTool(
|
|
34
|
-
name: string,
|
|
35
|
-
args: Record<string, unknown>,
|
|
36
|
-
callId: string,
|
|
37
|
-
signal?: AbortSignal,
|
|
38
|
-
): Promise<ChatInteractiveToolResult> {
|
|
39
|
-
if (name === REQUEST_CONFIRMATION_TOOL) {
|
|
40
|
-
parseConfirmationArgs(args);
|
|
41
|
-
const result = await waitForInteractiveToolResult<ConfirmationToolResult>(
|
|
42
|
-
callId,
|
|
43
|
-
signal,
|
|
44
|
-
);
|
|
45
|
-
return { content: JSON.stringify(result) };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (name === REQUEST_CHOICES_TOOL) {
|
|
49
|
-
parseChoicesArgs(args);
|
|
50
|
-
const result = await waitForInteractiveToolResult<ChoicesToolResult>(
|
|
51
|
-
callId,
|
|
52
|
-
signal,
|
|
53
|
-
);
|
|
54
|
-
return { content: JSON.stringify(result) };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (name === SUGGEST_REPLIES_TOOL) {
|
|
58
|
-
const suggestions = parseSuggestRepliesArgs(args);
|
|
59
|
-
return {
|
|
60
|
-
content: JSON.stringify({ displayed: true }),
|
|
61
|
-
postResponse: suggestions,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
throw new Error(`Unknown chat UI tool: ${name}`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function shouldTerminateTurnAfterTool(name: string): boolean {
|
|
69
|
-
return isPostResponseChatTool(name);
|
|
70
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
CHOICES_TOOL,
|
|
3
|
-
type ChoiceOption,
|
|
4
|
-
type ChoicesToolArgs,
|
|
5
|
-
type ChoicesToolResult,
|
|
6
|
-
parseChoicesArgs,
|
|
7
|
-
REQUEST_CHOICES_TOOL,
|
|
8
|
-
} from "./choices.ts";
|
|
9
|
-
export {
|
|
10
|
-
CONFIRMATION_TOOL,
|
|
11
|
-
type ConfirmationToolArgs,
|
|
12
|
-
type ConfirmationToolResult,
|
|
13
|
-
parseConfirmationArgs,
|
|
14
|
-
REQUEST_CONFIRMATION_TOOL,
|
|
15
|
-
} from "./confirmation.ts";
|
|
16
|
-
export {
|
|
17
|
-
INTERACTIVE_CHAT_TOOL_NAMES,
|
|
18
|
-
isChatUiTool,
|
|
19
|
-
isInteractiveChatTool,
|
|
20
|
-
isPostResponseChatTool,
|
|
21
|
-
POST_RESPONSE_CHAT_TOOL_NAMES,
|
|
22
|
-
} from "./constants.ts";
|
|
23
|
-
export {
|
|
24
|
-
type ChatInteractiveToolResult,
|
|
25
|
-
executeChatInteractiveTool,
|
|
26
|
-
getChatInteractiveTools,
|
|
27
|
-
shouldTerminateTurnAfterTool,
|
|
28
|
-
} from "./execute.ts";
|
|
29
|
-
export {
|
|
30
|
-
isValidReplySuggestions,
|
|
31
|
-
parseSuggestRepliesArgs,
|
|
32
|
-
type ReplySuggestions,
|
|
33
|
-
SUGGEST_REPLIES_TOOL,
|
|
34
|
-
SUGGEST_REPLIES_TOOL_DEFINITION,
|
|
35
|
-
type SuggestRepliesToolResult,
|
|
36
|
-
} from "./suggestions.ts";
|
|
37
|
-
export {
|
|
38
|
-
rejectAllInteractiveToolWaiters,
|
|
39
|
-
resolveInteractiveToolResult,
|
|
40
|
-
waitForInteractiveToolResult,
|
|
41
|
-
} from "./waiters.ts";
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { ClientToolDefinition } from "../llm-types.ts";
|
|
2
|
-
|
|
3
|
-
export const SUGGEST_REPLIES_TOOL = "suggest_replies";
|
|
4
|
-
|
|
5
|
-
export type ReplySuggestions = {
|
|
6
|
-
question: string;
|
|
7
|
-
suggestions: string[];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type SuggestRepliesToolResult = {
|
|
11
|
-
displayed: true;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const SUGGEST_REPLIES_TOOL_DEFINITION: ClientToolDefinition = {
|
|
15
|
-
name: SUGGEST_REPLIES_TOOL,
|
|
16
|
-
description:
|
|
17
|
-
"Required when your message asks the user a question and you can suggest 2–6 short example answers. Call as the ONLY tool in the turn, after writing the question in your message. Use for yes/no, dataclass picks, filter examples, or next-step options. The user can tap a suggestion or type their own reply.",
|
|
18
|
-
inputSchema: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
question: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description:
|
|
24
|
-
"The question from your message, e.g. Which dataclass should I query?",
|
|
25
|
-
},
|
|
26
|
-
suggestions: {
|
|
27
|
-
type: "array",
|
|
28
|
-
minItems: 2,
|
|
29
|
-
maxItems: 8,
|
|
30
|
-
items: {
|
|
31
|
-
type: "string",
|
|
32
|
-
description: "A short tap-to-send answer.",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
required: ["question", "suggestions"],
|
|
37
|
-
additionalProperties: false,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export function parseSuggestRepliesArgs(
|
|
42
|
-
args: Record<string, unknown>,
|
|
43
|
-
): ReplySuggestions {
|
|
44
|
-
const question = String(args.question ?? "").trim();
|
|
45
|
-
if (!question) {
|
|
46
|
-
throw new Error("suggest_replies requires a non-empty question");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!Array.isArray(args.suggestions) || args.suggestions.length < 2) {
|
|
50
|
-
throw new Error("suggest_replies requires at least two suggestions");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const suggestions = args.suggestions
|
|
54
|
-
.map((entry) => String(entry ?? "").trim())
|
|
55
|
-
.filter((entry) => entry.length > 0);
|
|
56
|
-
|
|
57
|
-
if (suggestions.length < 2) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
"suggest_replies requires at least two non-empty suggestions",
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (suggestions.length > 8) {
|
|
64
|
-
throw new Error("suggest_replies allows at most 8 suggestions");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return { question, suggestions };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function isValidReplySuggestions(
|
|
71
|
-
value: unknown,
|
|
72
|
-
): value is ReplySuggestions {
|
|
73
|
-
if (!value || typeof value !== "object") return false;
|
|
74
|
-
|
|
75
|
-
const entry = value as ReplySuggestions;
|
|
76
|
-
if (typeof entry.question !== "string" || !entry.question.trim()) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!Array.isArray(entry.suggestions) || entry.suggestions.length < 2) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return entry.suggestions.every(
|
|
85
|
-
(suggestion) => typeof suggestion === "string" && suggestion.trim(),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
type InteractiveWaiter = {
|
|
2
|
-
resolve: (value: unknown) => void;
|
|
3
|
-
reject: (error: Error) => void;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const waiters = new Map<string, InteractiveWaiter>();
|
|
7
|
-
|
|
8
|
-
export function waitForInteractiveToolResult<T>(
|
|
9
|
-
callId: string,
|
|
10
|
-
signal?: AbortSignal,
|
|
11
|
-
): Promise<T> {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
if (signal?.aborted) {
|
|
14
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const onAbort = () => {
|
|
19
|
-
waiters.delete(callId);
|
|
20
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
24
|
-
|
|
25
|
-
waiters.set(callId, {
|
|
26
|
-
resolve: (value) => {
|
|
27
|
-
signal?.removeEventListener("abort", onAbort);
|
|
28
|
-
resolve(value as T);
|
|
29
|
-
},
|
|
30
|
-
reject: (error) => {
|
|
31
|
-
signal?.removeEventListener("abort", onAbort);
|
|
32
|
-
reject(error);
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function resolveInteractiveToolResult(
|
|
39
|
-
callId: string,
|
|
40
|
-
value: unknown,
|
|
41
|
-
): boolean {
|
|
42
|
-
const waiter = waiters.get(callId);
|
|
43
|
-
if (!waiter) return false;
|
|
44
|
-
|
|
45
|
-
waiter.resolve(value);
|
|
46
|
-
waiters.delete(callId);
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function rejectAllInteractiveToolWaiters(error: Error): void {
|
|
51
|
-
for (const [callId, waiter] of waiters.entries()) {
|
|
52
|
-
waiter.reject(error);
|
|
53
|
-
waiters.delete(callId);
|
|
54
|
-
}
|
|
55
|
-
}
|