@xinghunm/ai-chat 0.3.0 → 1.0.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/dist/index.d.mts CHANGED
@@ -101,6 +101,7 @@ interface PlanBooleanQuestion extends PlanQuestionBase {
101
101
  * Supported question variants in a plan questionnaire.
102
102
  */
103
103
  type PlanQuestion = PlanSingleSelectQuestion | PlanMultiSelectQuestion | PlanTextQuestion | PlanNumberQuestion | PlanBooleanQuestion;
104
+ type PlanQuestionnaireStatus = 'expired' | 'failed';
104
105
  /**
105
106
  * Structured question form emitted for plan-mode clarification flows.
106
107
  */
@@ -111,6 +112,8 @@ interface PlanQuestionnaire {
111
112
  submitLabel?: string;
112
113
  questions: PlanQuestion[];
113
114
  answers?: Partial<Record<string, PlanQuestionnaireAnswerValue>>;
115
+ status?: PlanQuestionnaireStatus;
116
+ statusMessage?: string;
114
117
  }
115
118
  /**
116
119
  * Submission payload emitted by a questionnaire card.
@@ -129,6 +132,13 @@ interface ExecutionConfirmationSubmission {
129
132
  content: string;
130
133
  sourceMessageId?: string;
131
134
  }
135
+ /**
136
+ * Context metadata provided to custom structured submission handlers.
137
+ */
138
+ interface ChatSubmissionContext {
139
+ sessionId?: string;
140
+ mode: ChatAgentMode;
141
+ }
132
142
  /**
133
143
  * Summary item used by structured assistant cards to describe parameter changes.
134
144
  */
@@ -142,18 +152,18 @@ interface ChatParameterSummaryItem {
142
152
  */
143
153
  interface ExecutionProposal {
144
154
  proposalId: string;
145
- equationKey: string;
146
- equationName: string;
147
- solverName?: string;
155
+ resourceKey: string;
156
+ resourceName: string;
157
+ executorName?: string;
148
158
  parameterSummary: ChatParameterSummaryItem[];
149
159
  warnings?: string[];
150
160
  requiresConfirmation: true;
151
161
  }
152
162
  /**
153
- * Structured result summary emitted after a PDE task has started or completed.
163
+ * Structured result summary emitted after a task has started or completed.
154
164
  */
155
165
  interface ResultSummary {
156
- taskId: string;
166
+ summaryId: string;
157
167
  status: 'completed' | 'failed' | 'running' | 'pending';
158
168
  headline: string;
159
169
  details: string[];
@@ -279,6 +289,14 @@ interface ChatMessageBlockRendererProps {
279
289
  * Optional renderer used for custom block variants.
280
290
  */
281
291
  type ChatMessageBlockRenderer = (props: ChatMessageBlockRendererProps) => ReactNode;
292
+ /**
293
+ * Optional application-provided handler that intercepts questionnaire submissions.
294
+ */
295
+ type ChatQuestionnaireSubmitHandler = (submission: PlanQuestionnaireSubmission, context: ChatSubmissionContext) => Promise<boolean | void> | boolean | void;
296
+ /**
297
+ * Optional application-provided handler that intercepts confirmation submissions.
298
+ */
299
+ type ChatConfirmationSubmitHandler = (submission: ExecutionConfirmationSubmission, context: ChatSubmissionContext) => Promise<boolean | void> | boolean | void;
282
300
  interface ChatModel {
283
301
  id: string;
284
302
  object: string;
@@ -336,10 +354,18 @@ interface AiChatLabels {
336
354
  attachmentLimitNotice?: string;
337
355
  userRoleLabel?: string;
338
356
  assistantRoleLabel?: string;
357
+ expandMessageAriaLabel?: string;
358
+ collapseMessageAriaLabel?: string;
359
+ expandComposerAriaLabel?: string;
360
+ collapseComposerAriaLabel?: string;
339
361
  stoppedResponse?: string;
340
362
  assistantStreamingAriaLabel?: string;
341
363
  networkError?: string;
342
364
  genericError?: string;
365
+ questionnaireSubmitting?: string;
366
+ questionnaireSubmitted?: string;
367
+ questionnaireValidationPrefix?: string;
368
+ questionnaireSubmitFailed?: string;
343
369
  }
344
370
  /**
345
371
  * Default English label values used when no labels are provided.
@@ -353,6 +379,10 @@ interface AiChatProviderBaseProps {
353
379
  labels?: AiChatLabels;
354
380
  /** Optional renderer used to extend message blocks with app-specific UI. */
355
381
  renderMessageBlock?: ChatMessageBlockRenderer;
382
+ /** Optional handler used to intercept questionnaire submissions before the default send flow. */
383
+ handleQuestionnaireSubmit?: ChatQuestionnaireSubmitHandler;
384
+ /** Optional handler used to intercept confirmation submissions before the default send flow. */
385
+ handleConfirmationSubmit?: ChatConfirmationSubmitHandler;
356
386
  /** Optional render order used for mixed text and structured message blocks. */
357
387
  messageRenderOrder?: ChatMessageRenderOrder;
358
388
  /**
@@ -416,6 +446,17 @@ interface DefaultChatTransportEndpoints {
416
446
  /** Relative path used to request stream termination. */
417
447
  terminate?: string;
418
448
  }
449
+ /**
450
+ * Tool execution policy applied to outgoing stream requests.
451
+ */
452
+ interface ChatToolExecutionPolicy {
453
+ /** Enables tool execution headers for the stream request. */
454
+ enabled?: boolean;
455
+ /** Marks the request as requiring explicit approval before tool execution. */
456
+ approvalRequired?: boolean;
457
+ /** Approval timeout in seconds, forwarded when approval is enabled. */
458
+ approvalTimeoutSec?: number;
459
+ }
419
460
  /**
420
461
  * Options for the built-in HTTP transport adapter.
421
462
  */
@@ -424,6 +465,8 @@ interface CreateDefaultChatTransportOptions {
424
465
  apiBaseUrl: string;
425
466
  /** Authorization header value forwarded to the backend. */
426
467
  authToken: string;
468
+ /** Optional tool execution policy translated into stream request headers. */
469
+ toolExecutionPolicy?: ChatToolExecutionPolicy;
427
470
  /** Optional extra headers appended to each streaming chat completion request. */
428
471
  streamHeaders?: Record<string, string>;
429
472
  /** Optional transformer used to normalize custom stream packets. */
@@ -436,7 +479,7 @@ interface CreateDefaultChatTransportOptions {
436
479
  /**
437
480
  * Creates the built-in transport backed by the current HTTP chat API.
438
481
  */
439
- declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, streamHeaders, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
482
+ declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, toolExecutionPolicy, streamHeaders, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
440
483
 
441
484
  declare const ChatThread: () => _emotion_react_jsx_runtime.JSX.Element;
442
485
 
@@ -466,6 +509,8 @@ interface ChatComposerViewProps {
466
509
  plan: string;
467
510
  agent: string;
468
511
  };
512
+ expandComposerAriaLabel: string;
513
+ collapseComposerAriaLabel: string;
469
514
  onValueChange: (value: string) => void;
470
515
  onPickImages: (files: FileList | File[]) => void;
471
516
  onPasteImages: (files: File[]) => void;
@@ -529,6 +574,10 @@ interface ChatContextValue {
529
574
  retryRef: MutableRefObject<() => Promise<void>>;
530
575
  /** Optional block renderer used to extend message rendering with custom block types. */
531
576
  renderMessageBlock?: ChatMessageBlockRenderer;
577
+ /** Optional handler used to intercept questionnaire submissions before the default send flow. */
578
+ handleQuestionnaireSubmit?: ChatQuestionnaireSubmitHandler;
579
+ /** Optional handler used to intercept confirmation submissions before the default send flow. */
580
+ handleConfirmationSubmit?: ChatConfirmationSubmitHandler;
532
581
  /** Optional render order used for mixed text and structured message blocks. */
533
582
  messageRenderOrder?: ChatMessageRenderOrder;
534
583
  /** Optional packet transformer used by the legacy default adapter. */
@@ -551,4 +600,4 @@ declare const useChatContext: () => ChatContextValue;
551
600
  */
552
601
  declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
553
602
 
554
- export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, CHAT_MESSAGE_RENDER_ORDERS, type ChatAgentMode, ChatComposer, type ChatComposerViewProps, ChatConversationList, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatRole, type ChatSession, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, ChatThread, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type ExecutionConfirmationSubmission, type ExecutionProposal, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
603
+ export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, CHAT_MESSAGE_RENDER_ORDERS, type ChatAgentMode, ChatComposer, type ChatComposerViewProps, type ChatConfirmationSubmitHandler, ChatConversationList, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, type ChatSubmissionContext, ChatThread, type ChatToolExecutionPolicy, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type ExecutionConfirmationSubmission, type ExecutionProposal, type PlanQuestionOption, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
package/dist/index.d.ts CHANGED
@@ -101,6 +101,7 @@ interface PlanBooleanQuestion extends PlanQuestionBase {
101
101
  * Supported question variants in a plan questionnaire.
102
102
  */
103
103
  type PlanQuestion = PlanSingleSelectQuestion | PlanMultiSelectQuestion | PlanTextQuestion | PlanNumberQuestion | PlanBooleanQuestion;
104
+ type PlanQuestionnaireStatus = 'expired' | 'failed';
104
105
  /**
105
106
  * Structured question form emitted for plan-mode clarification flows.
106
107
  */
@@ -111,6 +112,8 @@ interface PlanQuestionnaire {
111
112
  submitLabel?: string;
112
113
  questions: PlanQuestion[];
113
114
  answers?: Partial<Record<string, PlanQuestionnaireAnswerValue>>;
115
+ status?: PlanQuestionnaireStatus;
116
+ statusMessage?: string;
114
117
  }
115
118
  /**
116
119
  * Submission payload emitted by a questionnaire card.
@@ -129,6 +132,13 @@ interface ExecutionConfirmationSubmission {
129
132
  content: string;
130
133
  sourceMessageId?: string;
131
134
  }
135
+ /**
136
+ * Context metadata provided to custom structured submission handlers.
137
+ */
138
+ interface ChatSubmissionContext {
139
+ sessionId?: string;
140
+ mode: ChatAgentMode;
141
+ }
132
142
  /**
133
143
  * Summary item used by structured assistant cards to describe parameter changes.
134
144
  */
@@ -142,18 +152,18 @@ interface ChatParameterSummaryItem {
142
152
  */
143
153
  interface ExecutionProposal {
144
154
  proposalId: string;
145
- equationKey: string;
146
- equationName: string;
147
- solverName?: string;
155
+ resourceKey: string;
156
+ resourceName: string;
157
+ executorName?: string;
148
158
  parameterSummary: ChatParameterSummaryItem[];
149
159
  warnings?: string[];
150
160
  requiresConfirmation: true;
151
161
  }
152
162
  /**
153
- * Structured result summary emitted after a PDE task has started or completed.
163
+ * Structured result summary emitted after a task has started or completed.
154
164
  */
155
165
  interface ResultSummary {
156
- taskId: string;
166
+ summaryId: string;
157
167
  status: 'completed' | 'failed' | 'running' | 'pending';
158
168
  headline: string;
159
169
  details: string[];
@@ -279,6 +289,14 @@ interface ChatMessageBlockRendererProps {
279
289
  * Optional renderer used for custom block variants.
280
290
  */
281
291
  type ChatMessageBlockRenderer = (props: ChatMessageBlockRendererProps) => ReactNode;
292
+ /**
293
+ * Optional application-provided handler that intercepts questionnaire submissions.
294
+ */
295
+ type ChatQuestionnaireSubmitHandler = (submission: PlanQuestionnaireSubmission, context: ChatSubmissionContext) => Promise<boolean | void> | boolean | void;
296
+ /**
297
+ * Optional application-provided handler that intercepts confirmation submissions.
298
+ */
299
+ type ChatConfirmationSubmitHandler = (submission: ExecutionConfirmationSubmission, context: ChatSubmissionContext) => Promise<boolean | void> | boolean | void;
282
300
  interface ChatModel {
283
301
  id: string;
284
302
  object: string;
@@ -336,10 +354,18 @@ interface AiChatLabels {
336
354
  attachmentLimitNotice?: string;
337
355
  userRoleLabel?: string;
338
356
  assistantRoleLabel?: string;
357
+ expandMessageAriaLabel?: string;
358
+ collapseMessageAriaLabel?: string;
359
+ expandComposerAriaLabel?: string;
360
+ collapseComposerAriaLabel?: string;
339
361
  stoppedResponse?: string;
340
362
  assistantStreamingAriaLabel?: string;
341
363
  networkError?: string;
342
364
  genericError?: string;
365
+ questionnaireSubmitting?: string;
366
+ questionnaireSubmitted?: string;
367
+ questionnaireValidationPrefix?: string;
368
+ questionnaireSubmitFailed?: string;
343
369
  }
344
370
  /**
345
371
  * Default English label values used when no labels are provided.
@@ -353,6 +379,10 @@ interface AiChatProviderBaseProps {
353
379
  labels?: AiChatLabels;
354
380
  /** Optional renderer used to extend message blocks with app-specific UI. */
355
381
  renderMessageBlock?: ChatMessageBlockRenderer;
382
+ /** Optional handler used to intercept questionnaire submissions before the default send flow. */
383
+ handleQuestionnaireSubmit?: ChatQuestionnaireSubmitHandler;
384
+ /** Optional handler used to intercept confirmation submissions before the default send flow. */
385
+ handleConfirmationSubmit?: ChatConfirmationSubmitHandler;
356
386
  /** Optional render order used for mixed text and structured message blocks. */
357
387
  messageRenderOrder?: ChatMessageRenderOrder;
358
388
  /**
@@ -416,6 +446,17 @@ interface DefaultChatTransportEndpoints {
416
446
  /** Relative path used to request stream termination. */
417
447
  terminate?: string;
418
448
  }
449
+ /**
450
+ * Tool execution policy applied to outgoing stream requests.
451
+ */
452
+ interface ChatToolExecutionPolicy {
453
+ /** Enables tool execution headers for the stream request. */
454
+ enabled?: boolean;
455
+ /** Marks the request as requiring explicit approval before tool execution. */
456
+ approvalRequired?: boolean;
457
+ /** Approval timeout in seconds, forwarded when approval is enabled. */
458
+ approvalTimeoutSec?: number;
459
+ }
419
460
  /**
420
461
  * Options for the built-in HTTP transport adapter.
421
462
  */
@@ -424,6 +465,8 @@ interface CreateDefaultChatTransportOptions {
424
465
  apiBaseUrl: string;
425
466
  /** Authorization header value forwarded to the backend. */
426
467
  authToken: string;
468
+ /** Optional tool execution policy translated into stream request headers. */
469
+ toolExecutionPolicy?: ChatToolExecutionPolicy;
427
470
  /** Optional extra headers appended to each streaming chat completion request. */
428
471
  streamHeaders?: Record<string, string>;
429
472
  /** Optional transformer used to normalize custom stream packets. */
@@ -436,7 +479,7 @@ interface CreateDefaultChatTransportOptions {
436
479
  /**
437
480
  * Creates the built-in transport backed by the current HTTP chat API.
438
481
  */
439
- declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, streamHeaders, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
482
+ declare const createDefaultChatTransport: ({ apiBaseUrl, authToken, toolExecutionPolicy, streamHeaders, transformStreamPacket, endpoints, axiosInstance, }: CreateDefaultChatTransportOptions) => ChatTransport;
440
483
 
441
484
  declare const ChatThread: () => _emotion_react_jsx_runtime.JSX.Element;
442
485
 
@@ -466,6 +509,8 @@ interface ChatComposerViewProps {
466
509
  plan: string;
467
510
  agent: string;
468
511
  };
512
+ expandComposerAriaLabel: string;
513
+ collapseComposerAriaLabel: string;
469
514
  onValueChange: (value: string) => void;
470
515
  onPickImages: (files: FileList | File[]) => void;
471
516
  onPasteImages: (files: File[]) => void;
@@ -529,6 +574,10 @@ interface ChatContextValue {
529
574
  retryRef: MutableRefObject<() => Promise<void>>;
530
575
  /** Optional block renderer used to extend message rendering with custom block types. */
531
576
  renderMessageBlock?: ChatMessageBlockRenderer;
577
+ /** Optional handler used to intercept questionnaire submissions before the default send flow. */
578
+ handleQuestionnaireSubmit?: ChatQuestionnaireSubmitHandler;
579
+ /** Optional handler used to intercept confirmation submissions before the default send flow. */
580
+ handleConfirmationSubmit?: ChatConfirmationSubmitHandler;
532
581
  /** Optional render order used for mixed text and structured message blocks. */
533
582
  messageRenderOrder?: ChatMessageRenderOrder;
534
583
  /** Optional packet transformer used by the legacy default adapter. */
@@ -551,4 +600,4 @@ declare const useChatContext: () => ChatContextValue;
551
600
  */
552
601
  declare const useChatStore: <T>(selector: (state: ChatStore) => T) => T;
553
602
 
554
- export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, CHAT_MESSAGE_RENDER_ORDERS, type ChatAgentMode, ChatComposer, type ChatComposerViewProps, ChatConversationList, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatRole, type ChatSession, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, ChatThread, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type ExecutionConfirmationSubmission, type ExecutionProposal, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };
603
+ export { AiChat, type AiChatLabels, type AiChatProps, AiChatProvider, type AiChatProviderProps, CHAT_AGENT_MODES, CHAT_MESSAGE_RENDER_ORDERS, type ChatAgentMode, ChatComposer, type ChatComposerViewProps, type ChatConfirmationSubmitHandler, ChatConversationList, type ChatImageAttachment, type ChatMessage, type ChatMessageBlock, type ChatMessageBlockRenderer, type ChatMessageBlockRendererProps, type ChatMessageRenderOrder, type ChatMessageStatus, type ChatModel, type ChatParameterSummaryItem, type ChatQuestionnaireSubmitHandler, type ChatRole, type ChatSession, type ChatStreamMessagePatch, type ChatStreamPacketTransformArgs, type ChatStreamPacketUpdate, type ChatSubmissionContext, ChatThread, type ChatToolExecutionPolicy, type ChatTransport, type ChatTransportStartStreamArgs, type CreateDefaultChatTransportOptions, DEFAULT_AI_CHAT_LABELS, DEFAULT_CHAT_AGENT_MODE, type DefaultChatTransportEndpoints, type ExecutionConfirmationSubmission, type ExecutionProposal, type PlanQuestionOption, type PlanQuestionnaire, type PlanQuestionnaireSubmission, type ResultSummary, type TransformChatStreamPacket, createDefaultChatTransport, useChatContext, useChatStore };