@dudousxd/nestjs-agent-react 0.11.0 → 0.13.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 +22 -2
- package/dist/index.cjs +125 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -2
- package/dist/index.d.ts +49 -2
- package/dist/index.js +119 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
2
|
import { ChatTransport, UIMessage, UIMessageChunk, ToolUIPart, DynamicToolUIPart, DataUIPart, UIDataTypes } from 'ai';
|
|
3
3
|
import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
|
|
4
|
-
import { StoredMessage, ThreadSummary, SkillCatalogEntry, ToolCatalogEntry, ThreadDetail, MessageAttachment, QuotaView, ToolPresentation, ToolResultField, ToolResultView, ToolPresentationTone } from '@dudousxd/nestjs-agent-core';
|
|
4
|
+
import { StoredMessage, ThreadSummary, SkillCatalogEntry, ToolCatalogEntry, ThreadDetail, MessageAttachment, QuotaView, ElicitationQuestion, ElicitationInputType, ToolPresentation, ToolResultField, ToolResultView, ToolPresentationTone, ElicitationInput } from '@dudousxd/nestjs-agent-core';
|
|
5
|
+
export { ElicitationInput, ElicitationInputType, validateElicitationAnswer as validateAnswer, validateElicitationValue as validateAnswerValue } from '@dudousxd/nestjs-agent-core';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
8
|
/** Identity surfaced by the backend's `meta` SSE frame / response headers. */
|
|
@@ -314,6 +315,26 @@ interface ChatInputProps {
|
|
|
314
315
|
*/
|
|
315
316
|
declare function ChatInput({ onSubmit, disabled, placeholder, rows, enableSpeech, speechLang, sendLabel, onStop, isStreaming, stopLabel, className, textareaClassName, sendButtonClassName, micButtonClassName, stopButtonClassName, renderMic, }: ChatInputProps): React.JSX.Element;
|
|
316
317
|
|
|
318
|
+
/** What a form control can hand over: a field's value, a checkbox's state, a picked date, a list. */
|
|
319
|
+
type RawAnswer = string | number | boolean | Date | null | undefined | readonly RawAnswer[];
|
|
320
|
+
/** The question fields {@link coerceAnswer} reads. A transcript question and a core one both fit. */
|
|
321
|
+
type CoercibleQuestion = Pick<ElicitationQuestion, 'multiple'> & {
|
|
322
|
+
input?: {
|
|
323
|
+
type: ElicitationInputType;
|
|
324
|
+
} | null;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Turn whatever a form control produced into the `string[]` the answer route takes, in the
|
|
328
|
+
* question's canonical form: numbers as decimals, booleans as `"true"`/`"false"`, dates as
|
|
329
|
+
* `YYYY-MM-DD` (a `Date` is read as the local calendar day), trimmed where whitespace means
|
|
330
|
+
* nothing. An empty value becomes `[]` — no answer, not an empty string. A single-choice question
|
|
331
|
+
* keeps the first value.
|
|
332
|
+
*
|
|
333
|
+
* Coercion never judges: pair it with {@link validateAnswer} (the same rules the server applies) to
|
|
334
|
+
* say what is wrong before sending.
|
|
335
|
+
*/
|
|
336
|
+
declare function coerceAnswer(question: CoercibleQuestion, raw: RawAnswer): string[];
|
|
337
|
+
|
|
317
338
|
/** Tool name → how the server said it is spoken about. */
|
|
318
339
|
type ToolCatalog = Record<string, ToolPresentation>;
|
|
319
340
|
/** Index `GET <base>/tools` by tool name, keeping only the tools that declared a presentation. */
|
|
@@ -652,6 +673,8 @@ interface TranscriptUiBlock {
|
|
|
652
673
|
props: Record<string, unknown>;
|
|
653
674
|
/** Schema version of `props`; `null` when the server did not stamp one. */
|
|
654
675
|
version: number | null;
|
|
676
|
+
/** The tool call that pushed it (`ctx.emitUi`); `null` for a component pushed outside a tool. */
|
|
677
|
+
toolCallId: string | null;
|
|
655
678
|
}
|
|
656
679
|
/** One choice a question offers, with its live selection state. */
|
|
657
680
|
interface TranscriptQuestionOption {
|
|
@@ -669,6 +692,14 @@ interface TranscriptQuestionOption {
|
|
|
669
692
|
interface TranscriptQuestion {
|
|
670
693
|
id: string;
|
|
671
694
|
prompt: string;
|
|
695
|
+
/** A line of help under the prompt; `null` when the request gave none. */
|
|
696
|
+
description: string | null;
|
|
697
|
+
/**
|
|
698
|
+
* How the answer is typed — `{ type, placeholder?, required?, min?, max?, pattern? }` — or `null`
|
|
699
|
+
* for a plain pick from `options`. Render the control from `input.type`; `select` still picks
|
|
700
|
+
* from `options`.
|
|
701
|
+
*/
|
|
702
|
+
input: ElicitationInput | null;
|
|
672
703
|
multiple: boolean;
|
|
673
704
|
/** 1-based. The request carries every question up front, so "Question 1 of N" is honest. */
|
|
674
705
|
position: number;
|
|
@@ -680,6 +711,20 @@ interface TranscriptQuestion {
|
|
|
680
711
|
* first is recorded as `defaulted` rather than as a choice the user made.
|
|
681
712
|
*/
|
|
682
713
|
isPristine: boolean;
|
|
714
|
+
/** The first selected value, or `''` — what a single text/number/date field shows. */
|
|
715
|
+
value: string;
|
|
716
|
+
/**
|
|
717
|
+
* Set a typed answer from whatever the control produced (a string, a number, a checkbox's
|
|
718
|
+
* boolean, a `Date`, a list); coerced to the question's canonical strings with `coerceAnswer`.
|
|
719
|
+
* `null`/`''` clears it. Does nothing once the set settled.
|
|
720
|
+
*/
|
|
721
|
+
setValue: (raw: RawAnswer) => void;
|
|
722
|
+
/**
|
|
723
|
+
* Why the current selection would be refused (the server's own rules — `validateAnswer`), or
|
|
724
|
+
* `null`. A pristine required question with no default reads `requires an answer`; show it once
|
|
725
|
+
* the user tried to submit, or right away — the model does not decide that for you.
|
|
726
|
+
*/
|
|
727
|
+
error: string | null;
|
|
683
728
|
}
|
|
684
729
|
/** How a question set settled, once it did. */
|
|
685
730
|
interface TranscriptElicitationOutcome {
|
|
@@ -706,6 +751,8 @@ interface TranscriptElicitationBlock {
|
|
|
706
751
|
questionCount: number;
|
|
707
752
|
/** Still waiting on a human. */
|
|
708
753
|
isPending: boolean;
|
|
754
|
+
/** Every question's current selection is acceptable (no question has an `error`). */
|
|
755
|
+
isValid: boolean;
|
|
709
756
|
outcome: TranscriptElicitationOutcome | null;
|
|
710
757
|
/** A failed submission — the run is still parked, so the form stays live. */
|
|
711
758
|
error: string | null;
|
|
@@ -1711,4 +1758,4 @@ declare function useAgentChat(options: UseAgentChatOptions): {
|
|
|
1711
1758
|
clearError: () => void;
|
|
1712
1759
|
};
|
|
1713
1760
|
|
|
1714
|
-
export { AgentChatTransport, type AgentChatTransportOptions, AgentClient, type AgentClientOptions, AgentHttpError, type AgentStreamMeta, type AggregatedTurnUsage, type AnyToolUIPart, type ApprovalBlockOptions, type ApprovalCountdown, type ApproveOptions, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type BuildBlocksOptions, type CancelResult, type ChatBackground, ChatInput, type ChatInputProps, type ChatStatus, type ChatTranscript, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DescribeToolCallOptions, type ElicitationBlockOptions, type GroupToolActivityOptions, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, type MessageUsageInfo, type QuotaToday, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, type ResolvedReading, type ResolvedResultView, type RetrievedPassage, SPEECH_LANGUAGES, type SettleAction, type SkillSuggestionData, type SkillsSourceOptions, type SpeechLanguage, type SpeechRecognitionHook, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type ThreadPatch, type TimestampInfo, type ToolActivityGroup, type ToolCallDescription, type ToolCallState, type ToolCallStatus, type ToolCatalog, type ToolCatalogState, type TranscriptActionState, type TranscriptApproval, type TranscriptApprovalStatus, type TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, type TranscriptElicitationBlock, type TranscriptElicitationOutcome, type TranscriptFile, type TranscriptFilesBlock, type TranscriptItem, type TranscriptItemOptions, type TranscriptQuestion, type TranscriptQuestionOption, type TranscriptReasoningBlock, type TranscriptSettleState, type TranscriptSource, type TranscriptSourcesBlock, type TranscriptStopState, type TranscriptTextBlock, type TranscriptToolBlock, type TranscriptToolCall, type TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, type UsageSummary, type UseAgentChatOptions, type UseApprovalCountdownOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseSpeechRecognitionOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, applyCompletion, approvalCountdown, backgroundRunsFromThread, buildTranscriptBlocks, correctedCallIds, createSkillsSource, describeTimestamp, describeToolCall, describeUsage, extractMessageText, fillTemplate, filterAutocompleteItems, findActiveTrigger, formatElapsed, formatRelativeTime, groupToolActivity, inferResultView, isActionCall, loadStoredSpeechLang, persistSpeechLang, phraseFor, readPath, readReasoningMs, resolveResultView, storedMessageToUiMessage, storedThreadToUiMessages, toolCallState, toolCatalogFrom, useAgentChat, useApprovalCountdown, useChatTranscript, useComposerAutocomplete, useElapsed, useSpeechRecognition, useStickToBottom, useToolCatalog, useTranscriptItem };
|
|
1761
|
+
export { AgentChatTransport, type AgentChatTransportOptions, AgentClient, type AgentClientOptions, AgentHttpError, type AgentStreamMeta, type AggregatedTurnUsage, type AnyToolUIPart, type ApprovalBlockOptions, type ApprovalCountdown, type ApproveOptions, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type BuildBlocksOptions, type CancelResult, type ChatBackground, ChatInput, type ChatInputProps, type ChatStatus, type ChatTranscript, type CoercibleQuestion, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DescribeToolCallOptions, type ElicitationBlockOptions, type GroupToolActivityOptions, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, type MessageUsageInfo, type QuotaToday, type RawAnswer, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, type ResolvedReading, type ResolvedResultView, type RetrievedPassage, SPEECH_LANGUAGES, type SettleAction, type SkillSuggestionData, type SkillsSourceOptions, type SpeechLanguage, type SpeechRecognitionHook, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type ThreadPatch, type TimestampInfo, type ToolActivityGroup, type ToolCallDescription, type ToolCallState, type ToolCallStatus, type ToolCatalog, type ToolCatalogState, type TranscriptActionState, type TranscriptApproval, type TranscriptApprovalStatus, type TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, type TranscriptElicitationBlock, type TranscriptElicitationOutcome, type TranscriptFile, type TranscriptFilesBlock, type TranscriptItem, type TranscriptItemOptions, type TranscriptQuestion, type TranscriptQuestionOption, type TranscriptReasoningBlock, type TranscriptSettleState, type TranscriptSource, type TranscriptSourcesBlock, type TranscriptStopState, type TranscriptTextBlock, type TranscriptToolBlock, type TranscriptToolCall, type TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, type UsageSummary, type UseAgentChatOptions, type UseApprovalCountdownOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseSpeechRecognitionOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, applyCompletion, approvalCountdown, backgroundRunsFromThread, buildTranscriptBlocks, coerceAnswer, correctedCallIds, createSkillsSource, describeTimestamp, describeToolCall, describeUsage, extractMessageText, fillTemplate, filterAutocompleteItems, findActiveTrigger, formatElapsed, formatRelativeTime, groupToolActivity, inferResultView, isActionCall, loadStoredSpeechLang, persistSpeechLang, phraseFor, readPath, readReasoningMs, resolveResultView, storedMessageToUiMessage, storedThreadToUiMessages, toolCallState, toolCatalogFrom, useAgentChat, useApprovalCountdown, useChatTranscript, useComposerAutocomplete, useElapsed, useSpeechRecognition, useStickToBottom, useToolCatalog, useTranscriptItem };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
2
|
import { ChatTransport, UIMessage, UIMessageChunk, ToolUIPart, DynamicToolUIPart, DataUIPart, UIDataTypes } from 'ai';
|
|
3
3
|
import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
|
|
4
|
-
import { StoredMessage, ThreadSummary, SkillCatalogEntry, ToolCatalogEntry, ThreadDetail, MessageAttachment, QuotaView, ToolPresentation, ToolResultField, ToolResultView, ToolPresentationTone } from '@dudousxd/nestjs-agent-core';
|
|
4
|
+
import { StoredMessage, ThreadSummary, SkillCatalogEntry, ToolCatalogEntry, ThreadDetail, MessageAttachment, QuotaView, ElicitationQuestion, ElicitationInputType, ToolPresentation, ToolResultField, ToolResultView, ToolPresentationTone, ElicitationInput } from '@dudousxd/nestjs-agent-core';
|
|
5
|
+
export { ElicitationInput, ElicitationInputType, validateElicitationAnswer as validateAnswer, validateElicitationValue as validateAnswerValue } from '@dudousxd/nestjs-agent-core';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
8
|
/** Identity surfaced by the backend's `meta` SSE frame / response headers. */
|
|
@@ -314,6 +315,26 @@ interface ChatInputProps {
|
|
|
314
315
|
*/
|
|
315
316
|
declare function ChatInput({ onSubmit, disabled, placeholder, rows, enableSpeech, speechLang, sendLabel, onStop, isStreaming, stopLabel, className, textareaClassName, sendButtonClassName, micButtonClassName, stopButtonClassName, renderMic, }: ChatInputProps): React.JSX.Element;
|
|
316
317
|
|
|
318
|
+
/** What a form control can hand over: a field's value, a checkbox's state, a picked date, a list. */
|
|
319
|
+
type RawAnswer = string | number | boolean | Date | null | undefined | readonly RawAnswer[];
|
|
320
|
+
/** The question fields {@link coerceAnswer} reads. A transcript question and a core one both fit. */
|
|
321
|
+
type CoercibleQuestion = Pick<ElicitationQuestion, 'multiple'> & {
|
|
322
|
+
input?: {
|
|
323
|
+
type: ElicitationInputType;
|
|
324
|
+
} | null;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Turn whatever a form control produced into the `string[]` the answer route takes, in the
|
|
328
|
+
* question's canonical form: numbers as decimals, booleans as `"true"`/`"false"`, dates as
|
|
329
|
+
* `YYYY-MM-DD` (a `Date` is read as the local calendar day), trimmed where whitespace means
|
|
330
|
+
* nothing. An empty value becomes `[]` — no answer, not an empty string. A single-choice question
|
|
331
|
+
* keeps the first value.
|
|
332
|
+
*
|
|
333
|
+
* Coercion never judges: pair it with {@link validateAnswer} (the same rules the server applies) to
|
|
334
|
+
* say what is wrong before sending.
|
|
335
|
+
*/
|
|
336
|
+
declare function coerceAnswer(question: CoercibleQuestion, raw: RawAnswer): string[];
|
|
337
|
+
|
|
317
338
|
/** Tool name → how the server said it is spoken about. */
|
|
318
339
|
type ToolCatalog = Record<string, ToolPresentation>;
|
|
319
340
|
/** Index `GET <base>/tools` by tool name, keeping only the tools that declared a presentation. */
|
|
@@ -652,6 +673,8 @@ interface TranscriptUiBlock {
|
|
|
652
673
|
props: Record<string, unknown>;
|
|
653
674
|
/** Schema version of `props`; `null` when the server did not stamp one. */
|
|
654
675
|
version: number | null;
|
|
676
|
+
/** The tool call that pushed it (`ctx.emitUi`); `null` for a component pushed outside a tool. */
|
|
677
|
+
toolCallId: string | null;
|
|
655
678
|
}
|
|
656
679
|
/** One choice a question offers, with its live selection state. */
|
|
657
680
|
interface TranscriptQuestionOption {
|
|
@@ -669,6 +692,14 @@ interface TranscriptQuestionOption {
|
|
|
669
692
|
interface TranscriptQuestion {
|
|
670
693
|
id: string;
|
|
671
694
|
prompt: string;
|
|
695
|
+
/** A line of help under the prompt; `null` when the request gave none. */
|
|
696
|
+
description: string | null;
|
|
697
|
+
/**
|
|
698
|
+
* How the answer is typed — `{ type, placeholder?, required?, min?, max?, pattern? }` — or `null`
|
|
699
|
+
* for a plain pick from `options`. Render the control from `input.type`; `select` still picks
|
|
700
|
+
* from `options`.
|
|
701
|
+
*/
|
|
702
|
+
input: ElicitationInput | null;
|
|
672
703
|
multiple: boolean;
|
|
673
704
|
/** 1-based. The request carries every question up front, so "Question 1 of N" is honest. */
|
|
674
705
|
position: number;
|
|
@@ -680,6 +711,20 @@ interface TranscriptQuestion {
|
|
|
680
711
|
* first is recorded as `defaulted` rather than as a choice the user made.
|
|
681
712
|
*/
|
|
682
713
|
isPristine: boolean;
|
|
714
|
+
/** The first selected value, or `''` — what a single text/number/date field shows. */
|
|
715
|
+
value: string;
|
|
716
|
+
/**
|
|
717
|
+
* Set a typed answer from whatever the control produced (a string, a number, a checkbox's
|
|
718
|
+
* boolean, a `Date`, a list); coerced to the question's canonical strings with `coerceAnswer`.
|
|
719
|
+
* `null`/`''` clears it. Does nothing once the set settled.
|
|
720
|
+
*/
|
|
721
|
+
setValue: (raw: RawAnswer) => void;
|
|
722
|
+
/**
|
|
723
|
+
* Why the current selection would be refused (the server's own rules — `validateAnswer`), or
|
|
724
|
+
* `null`. A pristine required question with no default reads `requires an answer`; show it once
|
|
725
|
+
* the user tried to submit, or right away — the model does not decide that for you.
|
|
726
|
+
*/
|
|
727
|
+
error: string | null;
|
|
683
728
|
}
|
|
684
729
|
/** How a question set settled, once it did. */
|
|
685
730
|
interface TranscriptElicitationOutcome {
|
|
@@ -706,6 +751,8 @@ interface TranscriptElicitationBlock {
|
|
|
706
751
|
questionCount: number;
|
|
707
752
|
/** Still waiting on a human. */
|
|
708
753
|
isPending: boolean;
|
|
754
|
+
/** Every question's current selection is acceptable (no question has an `error`). */
|
|
755
|
+
isValid: boolean;
|
|
709
756
|
outcome: TranscriptElicitationOutcome | null;
|
|
710
757
|
/** A failed submission — the run is still parked, so the form stays live. */
|
|
711
758
|
error: string | null;
|
|
@@ -1711,4 +1758,4 @@ declare function useAgentChat(options: UseAgentChatOptions): {
|
|
|
1711
1758
|
clearError: () => void;
|
|
1712
1759
|
};
|
|
1713
1760
|
|
|
1714
|
-
export { AgentChatTransport, type AgentChatTransportOptions, AgentClient, type AgentClientOptions, AgentHttpError, type AgentStreamMeta, type AggregatedTurnUsage, type AnyToolUIPart, type ApprovalBlockOptions, type ApprovalCountdown, type ApproveOptions, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type BuildBlocksOptions, type CancelResult, type ChatBackground, ChatInput, type ChatInputProps, type ChatStatus, type ChatTranscript, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DescribeToolCallOptions, type ElicitationBlockOptions, type GroupToolActivityOptions, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, type MessageUsageInfo, type QuotaToday, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, type ResolvedReading, type ResolvedResultView, type RetrievedPassage, SPEECH_LANGUAGES, type SettleAction, type SkillSuggestionData, type SkillsSourceOptions, type SpeechLanguage, type SpeechRecognitionHook, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type ThreadPatch, type TimestampInfo, type ToolActivityGroup, type ToolCallDescription, type ToolCallState, type ToolCallStatus, type ToolCatalog, type ToolCatalogState, type TranscriptActionState, type TranscriptApproval, type TranscriptApprovalStatus, type TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, type TranscriptElicitationBlock, type TranscriptElicitationOutcome, type TranscriptFile, type TranscriptFilesBlock, type TranscriptItem, type TranscriptItemOptions, type TranscriptQuestion, type TranscriptQuestionOption, type TranscriptReasoningBlock, type TranscriptSettleState, type TranscriptSource, type TranscriptSourcesBlock, type TranscriptStopState, type TranscriptTextBlock, type TranscriptToolBlock, type TranscriptToolCall, type TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, type UsageSummary, type UseAgentChatOptions, type UseApprovalCountdownOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseSpeechRecognitionOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, applyCompletion, approvalCountdown, backgroundRunsFromThread, buildTranscriptBlocks, correctedCallIds, createSkillsSource, describeTimestamp, describeToolCall, describeUsage, extractMessageText, fillTemplate, filterAutocompleteItems, findActiveTrigger, formatElapsed, formatRelativeTime, groupToolActivity, inferResultView, isActionCall, loadStoredSpeechLang, persistSpeechLang, phraseFor, readPath, readReasoningMs, resolveResultView, storedMessageToUiMessage, storedThreadToUiMessages, toolCallState, toolCatalogFrom, useAgentChat, useApprovalCountdown, useChatTranscript, useComposerAutocomplete, useElapsed, useSpeechRecognition, useStickToBottom, useToolCatalog, useTranscriptItem };
|
|
1761
|
+
export { AgentChatTransport, type AgentChatTransportOptions, AgentClient, type AgentClientOptions, AgentHttpError, type AgentStreamMeta, type AggregatedTurnUsage, type AnyToolUIPart, type ApprovalBlockOptions, type ApprovalCountdown, type ApproveOptions, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type BuildBlocksOptions, type CancelResult, type ChatBackground, ChatInput, type ChatInputProps, type ChatStatus, type ChatTranscript, type CoercibleQuestion, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DescribeToolCallOptions, type ElicitationBlockOptions, type GroupToolActivityOptions, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, type MessageUsageInfo, type QuotaToday, type RawAnswer, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, type ResolvedReading, type ResolvedResultView, type RetrievedPassage, SPEECH_LANGUAGES, type SettleAction, type SkillSuggestionData, type SkillsSourceOptions, type SpeechLanguage, type SpeechRecognitionHook, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type ThreadPatch, type TimestampInfo, type ToolActivityGroup, type ToolCallDescription, type ToolCallState, type ToolCallStatus, type ToolCatalog, type ToolCatalogState, type TranscriptActionState, type TranscriptApproval, type TranscriptApprovalStatus, type TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, type TranscriptElicitationBlock, type TranscriptElicitationOutcome, type TranscriptFile, type TranscriptFilesBlock, type TranscriptItem, type TranscriptItemOptions, type TranscriptQuestion, type TranscriptQuestionOption, type TranscriptReasoningBlock, type TranscriptSettleState, type TranscriptSource, type TranscriptSourcesBlock, type TranscriptStopState, type TranscriptTextBlock, type TranscriptToolBlock, type TranscriptToolCall, type TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, type UsageSummary, type UseAgentChatOptions, type UseApprovalCountdownOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseSpeechRecognitionOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, applyCompletion, approvalCountdown, backgroundRunsFromThread, buildTranscriptBlocks, coerceAnswer, correctedCallIds, createSkillsSource, describeTimestamp, describeToolCall, describeUsage, extractMessageText, fillTemplate, filterAutocompleteItems, findActiveTrigger, formatElapsed, formatRelativeTime, groupToolActivity, inferResultView, isActionCall, loadStoredSpeechLang, persistSpeechLang, phraseFor, readPath, readReasoningMs, resolveResultView, storedMessageToUiMessage, storedThreadToUiMessages, toolCallState, toolCatalogFrom, useAgentChat, useApprovalCountdown, useChatTranscript, useComposerAutocomplete, useElapsed, useSpeechRecognition, useStickToBottom, useToolCatalog, useTranscriptItem };
|
package/dist/index.js
CHANGED
|
@@ -460,6 +460,9 @@ var AgentChatTransport = class {
|
|
|
460
460
|
props: event.props,
|
|
461
461
|
...event.version !== void 0 ? {
|
|
462
462
|
version: event.version
|
|
463
|
+
} : {},
|
|
464
|
+
...event.toolCallId !== void 0 ? {
|
|
465
|
+
toolCallId: event.toolCallId
|
|
463
466
|
} : {}
|
|
464
467
|
}
|
|
465
468
|
});
|
|
@@ -978,8 +981,66 @@ import React3 from "react";
|
|
|
978
981
|
import { useCallback as useCallback3, useEffect as useEffect5, useRef as useRef4, useState as useState5 } from "react";
|
|
979
982
|
|
|
980
983
|
// src/transcript/model.ts
|
|
984
|
+
import { readElicitationInput, validateElicitationAnswer as validateElicitationAnswer2 } from "@dudousxd/nestjs-agent-core";
|
|
981
985
|
import { getToolName as getToolName2, isDataUIPart, isFileUIPart, isReasoningUIPart, isTextUIPart, isToolUIPart } from "ai";
|
|
982
986
|
|
|
987
|
+
// src/elicitation/answers.ts
|
|
988
|
+
import { validateElicitationAnswer, validateElicitationValue } from "@dudousxd/nestjs-agent-core";
|
|
989
|
+
function pad(value) {
|
|
990
|
+
return String(value).padStart(2, "0");
|
|
991
|
+
}
|
|
992
|
+
__name(pad, "pad");
|
|
993
|
+
function toDay(date) {
|
|
994
|
+
if (Number.isNaN(date.getTime())) {
|
|
995
|
+
return null;
|
|
996
|
+
}
|
|
997
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
998
|
+
}
|
|
999
|
+
__name(toDay, "toDay");
|
|
1000
|
+
function coerceOne(type, raw) {
|
|
1001
|
+
if (raw === null || raw === void 0) {
|
|
1002
|
+
return null;
|
|
1003
|
+
}
|
|
1004
|
+
if (Array.isArray(raw)) {
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
1007
|
+
if (raw instanceof Date) {
|
|
1008
|
+
return type === "date" || type === void 0 ? toDay(raw) : raw.toISOString();
|
|
1009
|
+
}
|
|
1010
|
+
if (typeof raw === "boolean") {
|
|
1011
|
+
return raw ? "true" : "false";
|
|
1012
|
+
}
|
|
1013
|
+
if (typeof raw === "number") {
|
|
1014
|
+
return Number.isFinite(raw) ? String(raw) : null;
|
|
1015
|
+
}
|
|
1016
|
+
const text = raw;
|
|
1017
|
+
switch (type) {
|
|
1018
|
+
case "number":
|
|
1019
|
+
case "email":
|
|
1020
|
+
case "url":
|
|
1021
|
+
case "date":
|
|
1022
|
+
return text.trim() === "" ? null : text.trim();
|
|
1023
|
+
case "boolean": {
|
|
1024
|
+
const lowered = text.trim().toLowerCase();
|
|
1025
|
+
if (lowered === "true" || lowered === "on" || lowered === "yes") return "true";
|
|
1026
|
+
if (lowered === "false" || lowered === "off" || lowered === "no") return "false";
|
|
1027
|
+
return lowered === "" ? null : text;
|
|
1028
|
+
}
|
|
1029
|
+
default:
|
|
1030
|
+
return text === "" ? null : text;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
__name(coerceOne, "coerceOne");
|
|
1034
|
+
function coerceAnswer(question, raw) {
|
|
1035
|
+
const type = question.input?.type;
|
|
1036
|
+
const items = Array.isArray(raw) ? raw : [
|
|
1037
|
+
raw
|
|
1038
|
+
];
|
|
1039
|
+
const values = items.map((item) => coerceOne(type, item)).filter((value) => value !== null);
|
|
1040
|
+
return question.multiple === true ? values : values.slice(0, 1);
|
|
1041
|
+
}
|
|
1042
|
+
__name(coerceAnswer, "coerceAnswer");
|
|
1043
|
+
|
|
983
1044
|
// src/presentation/tool-activity.ts
|
|
984
1045
|
import { getToolName } from "ai";
|
|
985
1046
|
|
|
@@ -1516,11 +1577,16 @@ function readElicitationRequest(part) {
|
|
|
1516
1577
|
}
|
|
1517
1578
|
const questions = [];
|
|
1518
1579
|
for (const candidate of input.questions) {
|
|
1519
|
-
if (!isRecord2(candidate) || typeof candidate.id !== "string" || typeof candidate.prompt !== "string"
|
|
1580
|
+
if (!isRecord2(candidate) || typeof candidate.id !== "string" || typeof candidate.prompt !== "string") {
|
|
1581
|
+
return null;
|
|
1582
|
+
}
|
|
1583
|
+
const input2 = readElicitationInput(candidate.input) ?? null;
|
|
1584
|
+
const rawOptions = Array.isArray(candidate.options) ? candidate.options : [];
|
|
1585
|
+
if (rawOptions.length === 0 && (input2 === null || input2.type === "select")) {
|
|
1520
1586
|
return null;
|
|
1521
1587
|
}
|
|
1522
1588
|
const options = [];
|
|
1523
|
-
for (const option of
|
|
1589
|
+
for (const option of rawOptions) {
|
|
1524
1590
|
if (!isRecord2(option) || typeof option.value !== "string" || typeof option.label !== "string") {
|
|
1525
1591
|
return null;
|
|
1526
1592
|
}
|
|
@@ -1533,7 +1599,10 @@ function readElicitationRequest(part) {
|
|
|
1533
1599
|
questions.push({
|
|
1534
1600
|
id: candidate.id,
|
|
1535
1601
|
prompt: candidate.prompt,
|
|
1602
|
+
description: typeof candidate.description === "string" ? candidate.description : null,
|
|
1603
|
+
input: input2,
|
|
1536
1604
|
multiple: candidate.multiple === true,
|
|
1605
|
+
allowFreeText: candidate.allowFreeText === true,
|
|
1537
1606
|
defaults: Array.isArray(candidate.defaults) ? candidate.defaults.filter((value) => typeof value === "string") : [],
|
|
1538
1607
|
options
|
|
1539
1608
|
});
|
|
@@ -1569,12 +1638,38 @@ function buildElicitationBlock(key, part, request, options) {
|
|
|
1569
1638
|
const picked = isPending ? options.picked(toolCallId, question.id) : void 0;
|
|
1570
1639
|
const selected = picked ?? outcome?.answers[question.id] ?? question.defaults;
|
|
1571
1640
|
const pick = /* @__PURE__ */ __name((values) => options.pick(toolCallId, question.id, values), "pick");
|
|
1641
|
+
const error = isPending ? validateElicitationAnswer2({
|
|
1642
|
+
id: question.id,
|
|
1643
|
+
prompt: question.prompt,
|
|
1644
|
+
options: question.options.map(({ value, label }) => ({
|
|
1645
|
+
value,
|
|
1646
|
+
label
|
|
1647
|
+
})),
|
|
1648
|
+
...question.input !== null ? {
|
|
1649
|
+
input: question.input
|
|
1650
|
+
} : {},
|
|
1651
|
+
...question.multiple ? {
|
|
1652
|
+
multiple: true
|
|
1653
|
+
} : {},
|
|
1654
|
+
...question.allowFreeText ? {
|
|
1655
|
+
allowFreeText: true
|
|
1656
|
+
} : {}
|
|
1657
|
+
}, selected) : null;
|
|
1572
1658
|
return {
|
|
1573
1659
|
id: question.id,
|
|
1574
1660
|
prompt: question.prompt,
|
|
1661
|
+
description: question.description,
|
|
1662
|
+
input: question.input,
|
|
1575
1663
|
multiple: question.multiple,
|
|
1576
1664
|
position: index + 1,
|
|
1577
1665
|
selected,
|
|
1666
|
+
value: selected[0] ?? "",
|
|
1667
|
+
error,
|
|
1668
|
+
setValue: /* @__PURE__ */ __name((raw) => {
|
|
1669
|
+
if (isPending) {
|
|
1670
|
+
pick(coerceAnswer(question, raw));
|
|
1671
|
+
}
|
|
1672
|
+
}, "setValue"),
|
|
1578
1673
|
isPristine: isPending ? picked === void 0 : outcome?.defaulted.includes(question.id) ?? true,
|
|
1579
1674
|
options: question.options.map((option) => ({
|
|
1580
1675
|
value: option.value,
|
|
@@ -1609,6 +1704,7 @@ function buildElicitationBlock(key, part, request, options) {
|
|
|
1609
1704
|
questions,
|
|
1610
1705
|
questionCount: questions.length,
|
|
1611
1706
|
isPending,
|
|
1707
|
+
isValid: questions.every((question) => question.error === null),
|
|
1612
1708
|
outcome,
|
|
1613
1709
|
error: options.errorOf(toolCallId),
|
|
1614
1710
|
answer: {
|
|
@@ -1723,7 +1819,8 @@ function readUiComponent(part) {
|
|
|
1723
1819
|
id,
|
|
1724
1820
|
component: data.component,
|
|
1725
1821
|
props: isRecord2(data.props) ? data.props : {},
|
|
1726
|
-
version: typeof data.version === "number" ? data.version : null
|
|
1822
|
+
version: typeof data.version === "number" ? data.version : null,
|
|
1823
|
+
toolCallId: typeof data.toolCallId === "string" ? data.toolCallId : null
|
|
1727
1824
|
};
|
|
1728
1825
|
}
|
|
1729
1826
|
__name(readUiComponent, "readUiComponent");
|
|
@@ -3161,8 +3258,10 @@ function storedMessageToUiMessage(message) {
|
|
|
3161
3258
|
url: attachment.url
|
|
3162
3259
|
});
|
|
3163
3260
|
}
|
|
3261
|
+
const toolCallIds = new Set((message.toolCalls ?? []).map((call) => call.id));
|
|
3262
|
+
const pushedByCall = /* @__PURE__ */ new Map();
|
|
3164
3263
|
for (const component of message.ui ?? []) {
|
|
3165
|
-
|
|
3264
|
+
const part = {
|
|
3166
3265
|
type: "data-ui",
|
|
3167
3266
|
id: component.id,
|
|
3168
3267
|
data: {
|
|
@@ -3171,9 +3270,19 @@ function storedMessageToUiMessage(message) {
|
|
|
3171
3270
|
props: component.props,
|
|
3172
3271
|
...component.version !== void 0 ? {
|
|
3173
3272
|
version: component.version
|
|
3273
|
+
} : {},
|
|
3274
|
+
...component.toolCallId !== void 0 ? {
|
|
3275
|
+
toolCallId: component.toolCallId
|
|
3174
3276
|
} : {}
|
|
3175
3277
|
}
|
|
3176
|
-
}
|
|
3278
|
+
};
|
|
3279
|
+
if (component.toolCallId !== void 0 && toolCallIds.has(component.toolCallId)) {
|
|
3280
|
+
const list = pushedByCall.get(component.toolCallId) ?? [];
|
|
3281
|
+
list.push(part);
|
|
3282
|
+
pushedByCall.set(component.toolCallId, list);
|
|
3283
|
+
} else {
|
|
3284
|
+
parts.push(part);
|
|
3285
|
+
}
|
|
3177
3286
|
}
|
|
3178
3287
|
for (const approval of message.approvals ?? []) {
|
|
3179
3288
|
parts.push({
|
|
@@ -3244,6 +3353,7 @@ function storedMessageToUiMessage(message) {
|
|
|
3244
3353
|
input: call.input
|
|
3245
3354
|
}
|
|
3246
3355
|
});
|
|
3356
|
+
parts.push(...pushedByCall.get(call.id) ?? []);
|
|
3247
3357
|
}
|
|
3248
3358
|
return {
|
|
3249
3359
|
id: message.id,
|
|
@@ -3677,6 +3787,7 @@ export {
|
|
|
3677
3787
|
approvalCountdown,
|
|
3678
3788
|
backgroundRunsFromThread,
|
|
3679
3789
|
buildTranscriptBlocks,
|
|
3790
|
+
coerceAnswer,
|
|
3680
3791
|
correctedCallIds,
|
|
3681
3792
|
createSkillsSource,
|
|
3682
3793
|
describeTimestamp,
|
|
@@ -3709,6 +3820,8 @@ export {
|
|
|
3709
3820
|
useSpeechRecognition,
|
|
3710
3821
|
useStickToBottom,
|
|
3711
3822
|
useToolCatalog,
|
|
3712
|
-
useTranscriptItem
|
|
3823
|
+
useTranscriptItem,
|
|
3824
|
+
validateElicitationAnswer as validateAnswer,
|
|
3825
|
+
validateElicitationValue as validateAnswerValue
|
|
3713
3826
|
};
|
|
3714
3827
|
//# sourceMappingURL=index.js.map
|