glirastes 0.3.0 → 0.3.2
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/CHANGELOG.md +86 -0
- package/README.md +154 -9
- package/codegen/package.json +5 -0
- package/dist/cjs/codegen/asset-sync.d.ts +20 -0
- package/dist/cjs/codegen/asset-sync.js +28 -0
- package/dist/cjs/codegen/coverage.d.ts +66 -0
- package/dist/cjs/codegen/coverage.js +408 -0
- package/dist/cjs/codegen/endpoint-scanner.d.ts +16 -0
- package/dist/cjs/codegen/endpoint-scanner.js +197 -0
- package/dist/cjs/codegen/format.d.ts +17 -0
- package/dist/cjs/codegen/format.js +34 -0
- package/dist/cjs/codegen/fs-utils.d.ts +45 -0
- package/dist/cjs/codegen/fs-utils.js +165 -0
- package/dist/cjs/codegen/index.d.ts +13 -0
- package/dist/cjs/codegen/index.js +33 -0
- package/dist/cjs/codegen/mcp-generator.d.ts +50 -0
- package/dist/cjs/codegen/mcp-generator.js +803 -0
- package/dist/cjs/codegen/module-generator.d.ts +11 -0
- package/dist/cjs/codegen/module-generator.js +353 -0
- package/dist/cjs/codegen/nestjs-scanner.d.ts +43 -0
- package/dist/cjs/codegen/nestjs-scanner.js +241 -0
- package/dist/cjs/codegen/output-recommender.d.ts +23 -0
- package/dist/cjs/codegen/output-recommender.js +33 -0
- package/dist/cjs/codegen/scaffolder.d.ts +36 -0
- package/dist/cjs/codegen/scaffolder.js +262 -0
- package/dist/cjs/codegen/skill-generator.d.ts +49 -0
- package/dist/cjs/codegen/skill-generator.js +967 -0
- package/dist/cjs/codegen/types.d.ts +52 -0
- package/dist/cjs/codegen/types.js +16 -0
- package/dist/cjs/codegen/ui-scanner.d.ts +24 -0
- package/dist/cjs/codegen/ui-scanner.js +202 -0
- package/dist/cjs/codegen/validator.d.ts +35 -0
- package/dist/cjs/codegen/validator.js +292 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/openapi/index.d.ts +78 -0
- package/dist/cjs/openapi/index.js +347 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/react/audio-worklet-processor.d.ts +16 -0
- package/dist/cjs/react/audio-worklet-processor.js +27 -0
- package/dist/cjs/react/bridges/rest-session-bridge.d.ts +113 -0
- package/dist/cjs/react/bridges/rest-session-bridge.js +209 -0
- package/dist/cjs/react/components/ai-chat-panel.d.ts +12 -0
- package/dist/cjs/react/components/ai-chat-panel.js +67 -0
- package/dist/cjs/react/components/ai-trigger-button.d.ts +2 -0
- package/dist/cjs/react/components/ai-trigger-button.js +239 -0
- package/dist/cjs/react/components/approval-card.d.ts +9 -0
- package/dist/cjs/react/components/approval-card.js +24 -0
- package/dist/cjs/react/components/bulk-approval-card.d.ts +9 -0
- package/dist/cjs/react/components/bulk-approval-card.js +36 -0
- package/dist/cjs/react/components/chat-input.d.ts +10 -0
- package/dist/cjs/react/components/chat-input.js +60 -0
- package/dist/cjs/react/components/chat-window.d.ts +2 -0
- package/dist/cjs/react/components/chat-window.js +134 -0
- package/dist/cjs/react/components/confirm-dialog.d.ts +32 -0
- package/dist/cjs/react/components/confirm-dialog.js +48 -0
- package/dist/cjs/react/components/floating-chat-ui.d.ts +90 -0
- package/dist/cjs/react/components/floating-chat-ui.js +163 -0
- package/dist/cjs/react/components/mention-chip.d.ts +16 -0
- package/dist/cjs/react/components/mention-chip.js +42 -0
- package/dist/cjs/react/components/mention-input.d.ts +8 -0
- package/dist/cjs/react/components/mention-input.js +117 -0
- package/dist/cjs/react/components/message-bubble.d.ts +11 -0
- package/dist/cjs/react/components/message-bubble.js +171 -0
- package/dist/cjs/react/components/message-list.d.ts +8 -0
- package/dist/cjs/react/components/message-list.js +52 -0
- package/dist/cjs/react/components/pipeline-timeline.d.ts +7 -0
- package/dist/cjs/react/components/pipeline-timeline.js +72 -0
- package/dist/cjs/react/components/recording-bar.d.ts +2 -0
- package/dist/cjs/react/components/recording-bar.js +81 -0
- package/dist/cjs/react/components/recording-controls.d.ts +18 -0
- package/dist/cjs/react/components/recording-controls.js +38 -0
- package/dist/cjs/react/components/rich-mention-input.d.ts +2 -0
- package/dist/cjs/react/components/rich-mention-input.js +571 -0
- package/dist/cjs/react/components/session-switcher.d.ts +14 -0
- package/dist/cjs/react/components/session-switcher.js +133 -0
- package/dist/cjs/react/components/suggestion-bar.d.ts +9 -0
- package/dist/cjs/react/components/suggestion-bar.js +47 -0
- package/dist/cjs/react/components/suggestion-chip.d.ts +9 -0
- package/dist/cjs/react/components/suggestion-chip.js +14 -0
- package/dist/cjs/react/components/voice-input-addon.d.ts +13 -0
- package/dist/cjs/react/components/voice-input-addon.js +31 -0
- package/dist/cjs/react/components/voice-input-button.d.ts +2 -0
- package/dist/cjs/react/components/voice-input-button.js +55 -0
- package/dist/cjs/react/components/wavesurfer-loader.d.ts +5 -0
- package/dist/cjs/react/components/wavesurfer-loader.js +36 -0
- package/dist/cjs/react/hooks/use-ai-chat.d.ts +22 -0
- package/dist/cjs/react/hooks/use-ai-chat.js +51 -0
- package/dist/cjs/react/hooks/use-approvals.d.ts +23 -0
- package/dist/cjs/react/hooks/use-approvals.js +63 -0
- package/dist/cjs/react/hooks/use-deepgram-transcription.d.ts +2 -0
- package/dist/cjs/react/hooks/use-deepgram-transcription.js +329 -0
- package/dist/cjs/react/hooks/use-drag-resize-panel.d.ts +48 -0
- package/dist/cjs/react/hooks/use-drag-resize-panel.js +308 -0
- package/dist/cjs/react/hooks/use-draggable-position.d.ts +25 -0
- package/dist/cjs/react/hooks/use-draggable-position.js +134 -0
- package/dist/cjs/react/hooks/use-keyboard-shortcut.d.ts +20 -0
- package/dist/cjs/react/hooks/use-keyboard-shortcut.js +93 -0
- package/dist/cjs/react/hooks/use-mentions.d.ts +23 -0
- package/dist/cjs/react/hooks/use-mentions.js +42 -0
- package/dist/cjs/react/hooks/use-suggestions.d.ts +22 -0
- package/dist/cjs/react/hooks/use-suggestions.js +39 -0
- package/dist/cjs/react/index.d.ts +43 -0
- package/dist/cjs/react/index.js +111 -0
- package/dist/cjs/react/provider/ai-chat-provider.d.ts +45 -0
- package/dist/cjs/react/provider/ai-chat-provider.js +1024 -0
- package/dist/cjs/react/provider/chat-context.d.ts +84 -0
- package/dist/cjs/react/provider/chat-context.js +13 -0
- package/dist/cjs/react/template.d.ts +84 -0
- package/dist/cjs/react/template.js +90 -0
- package/dist/cjs/react/themes.d.ts +24 -0
- package/dist/cjs/react/themes.js +273 -0
- package/dist/cjs/react/transports/langgraph/index.d.ts +2 -0
- package/dist/cjs/react/transports/langgraph/index.js +8 -0
- package/dist/cjs/react/transports/langgraph/langgraph-ai-chat.d.ts +62 -0
- package/dist/cjs/react/transports/langgraph/langgraph-ai-chat.js +94 -0
- package/dist/cjs/react/transports/langgraph.d.ts +71 -0
- package/dist/cjs/react/transports/langgraph.js +369 -0
- package/dist/cjs/react/transports/vercel/index.d.ts +2 -0
- package/dist/cjs/react/transports/vercel/index.js +8 -0
- package/dist/cjs/react/transports/vercel/vercel-ai-chat.d.ts +49 -0
- package/dist/cjs/react/transports/vercel/vercel-ai-chat.js +81 -0
- package/dist/cjs/react/transports/vercel.d.ts +30 -0
- package/dist/cjs/react/transports/vercel.js +69 -0
- package/dist/cjs/react/types.d.ts +760 -0
- package/dist/cjs/react/types.js +2 -0
- package/dist/cjs/react/ui.d.ts +73 -0
- package/dist/cjs/react/ui.js +183 -0
- package/dist/cjs/react/utils/create-approval-description.d.ts +53 -0
- package/dist/cjs/react/utils/create-approval-description.js +122 -0
- package/dist/cjs/react/utils/create-tool-result-handler.d.ts +90 -0
- package/dist/cjs/react/utils/create-tool-result-handler.js +168 -0
- package/dist/cjs/react/utils/mention-markup.d.ts +13 -0
- package/dist/cjs/react/utils/mention-markup.js +117 -0
- package/dist/cjs/react/utils/merge-pipeline-steps.d.ts +19 -0
- package/dist/cjs/react/utils/merge-pipeline-steps.js +81 -0
- package/dist/cjs/react/utils/sanitize-stored-messages.d.ts +23 -0
- package/dist/cjs/react/utils/sanitize-stored-messages.js +52 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat-auth.guard.d.ts +10 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat-auth.guard.js +42 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat-module-options.interface.d.ts +32 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat-module-options.interface.js +4 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.controller.d.ts +11 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.controller.js +80 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.module.d.ts +9 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.module.js +119 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.service.d.ts +13 -0
- package/dist/cjs/server/adapters/nestjs/chat/ai-chat.service.js +131 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/ai-chat-request.dto.d.ts +7 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/ai-chat-request.dto.js +52 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/chat-message-part.dto.d.ts +19 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/chat-message-part.dto.js +108 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/chat-message.dto.d.ts +8 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/chat-message.dto.js +59 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/index.d.ts +3 -0
- package/dist/cjs/server/adapters/nestjs/chat/dto/index.js +9 -0
- package/dist/cjs/server/adapters/nestjs/chat/index.d.ts +3 -0
- package/dist/cjs/server/adapters/nestjs/chat/index.js +9 -0
- package/dist/cjs/server/adapters/nestjs/chat/speech-stream.gateway.d.ts +4 -0
- package/dist/cjs/server/adapters/nestjs/chat/speech-stream.gateway.js +73 -0
- package/dist/cjs/server/adapters/nestjs/chat/ws-loader.d.ts +5 -0
- package/dist/cjs/server/adapters/nestjs/chat/ws-loader.js +72 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-module.decorator.d.ts +6 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-module.decorator.js +13 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-param.decorator.d.ts +5 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-param.decorator.js +15 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-tool.decorator.d.ts +6 -0
- package/dist/cjs/server/adapters/nestjs/decorators/ai-tool.decorator.js +22 -0
- package/dist/cjs/server/adapters/nestjs/decorators/constants.d.ts +4 -0
- package/dist/cjs/server/adapters/nestjs/decorators/constants.js +7 -0
- package/dist/cjs/server/adapters/nestjs/index.d.ts +14 -0
- package/dist/cjs/server/adapters/nestjs/index.js +42 -0
- package/dist/cjs/server/adapters/nestjs/metadata.d.ts +39 -0
- package/dist/cjs/server/adapters/nestjs/metadata.js +36 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools-explorer.service.d.ts +36 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools-explorer.service.js +159 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools.module.d.ts +37 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools.module.js +44 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools.service.d.ts +28 -0
- package/dist/cjs/server/adapters/nestjs/module/ai-tools.service.js +41 -0
- package/dist/cjs/server/adapters/nestjs/scanner/nestjs-scanner.d.ts +16 -0
- package/dist/cjs/server/adapters/nestjs/scanner/nestjs-scanner.js +117 -0
- package/dist/cjs/server/adapters/nestjs/scanner/schema-builder.d.ts +26 -0
- package/dist/cjs/server/adapters/nestjs/scanner/schema-builder.js +259 -0
- package/dist/cjs/server/adapters/nestjs/swagger.d.ts +7 -0
- package/dist/cjs/server/adapters/nestjs/swagger.js +39 -0
- package/dist/cjs/server/adapters/nextjs/context-helpers.d.ts +22 -0
- package/dist/cjs/server/adapters/nextjs/context-helpers.js +60 -0
- package/dist/cjs/server/adapters/nextjs/create-ai-chat-handler.d.ts +94 -0
- package/dist/cjs/server/adapters/nextjs/create-ai-chat-handler.js +965 -0
- package/dist/cjs/server/adapters/nextjs/filter-fallback-error.d.ts +11 -0
- package/dist/cjs/server/adapters/nextjs/filter-fallback-error.js +41 -0
- package/dist/cjs/server/adapters/nextjs/index.d.ts +8 -0
- package/dist/cjs/server/adapters/nextjs/index.js +22 -0
- package/dist/cjs/server/adapters/nextjs/prepare-model-messages.d.ts +58 -0
- package/dist/cjs/server/adapters/nextjs/prepare-model-messages.js +114 -0
- package/dist/cjs/server/adapters/nextjs/sanitize-model-messages.d.ts +64 -0
- package/dist/cjs/server/adapters/nextjs/sanitize-model-messages.js +489 -0
- package/dist/cjs/server/adapters/nextjs/server-action-helper.d.ts +7 -0
- package/dist/cjs/server/adapters/nextjs/server-action-helper.js +40 -0
- package/dist/cjs/server/adapters/nextjs/types.d.ts +246 -0
- package/dist/cjs/server/adapters/nextjs/types.js +2 -0
- package/dist/cjs/server/adapters/nextjs/with-ai-tool.d.ts +9 -0
- package/dist/cjs/server/adapters/nextjs/with-ai-tool.js +12 -0
- package/dist/cjs/server/core/followup-tool.d.ts +9 -0
- package/dist/cjs/server/core/followup-tool.js +82 -0
- package/dist/cjs/server/core/index.d.ts +139 -0
- package/dist/cjs/server/core/index.js +818 -0
- package/dist/cjs/server/core/intent-classifier.d.ts +94 -0
- package/dist/cjs/server/core/intent-classifier.js +324 -0
- package/dist/cjs/server/core/model-selector.d.ts +12 -0
- package/dist/cjs/server/core/model-selector.js +48 -0
- package/dist/cjs/server/core/module-router.d.ts +14 -0
- package/dist/cjs/server/core/module-router.js +110 -0
- package/dist/cjs/server/core/zod-compact.d.ts +18 -0
- package/dist/cjs/server/core/zod-compact.js +129 -0
- package/dist/cjs/server/index.d.ts +6 -0
- package/dist/cjs/server/index.js +28 -0
- package/dist/cjs/server/lancer/cache.d.ts +9 -0
- package/dist/cjs/server/lancer/cache.js +33 -0
- package/dist/cjs/server/lancer/client.d.ts +2 -0
- package/dist/cjs/server/lancer/client.js +279 -0
- package/dist/cjs/server/lancer/errors.d.ts +13 -0
- package/dist/cjs/server/lancer/errors.js +21 -0
- package/dist/cjs/server/lancer/index.d.ts +3 -0
- package/dist/cjs/server/lancer/index.js +7 -0
- package/dist/cjs/server/lancer/telemetry-buffer.d.ts +15 -0
- package/dist/cjs/server/lancer/telemetry-buffer.js +64 -0
- package/dist/cjs/server/lancer/types.d.ts +201 -0
- package/dist/cjs/server/lancer/types.js +5 -0
- package/dist/cjs/server/pii-shield/aegis-detector.d.ts +26 -0
- package/dist/cjs/server/pii-shield/aegis-detector.js +26 -0
- package/dist/cjs/server/pii-shield/create-pii-shield.d.ts +2 -0
- package/dist/cjs/server/pii-shield/create-pii-shield.js +191 -0
- package/dist/cjs/server/pii-shield/deep-walk.d.ts +1 -0
- package/dist/cjs/server/pii-shield/deep-walk.js +19 -0
- package/dist/cjs/server/pii-shield/fake-data.d.ts +5 -0
- package/dist/cjs/server/pii-shield/fake-data.js +170 -0
- package/dist/cjs/server/pii-shield/index.d.ts +4 -0
- package/dist/cjs/server/pii-shield/index.js +9 -0
- package/dist/cjs/server/pii-shield/leakage.d.ts +1 -0
- package/dist/cjs/server/pii-shield/leakage.js +15 -0
- package/dist/cjs/server/pii-shield/session-mapping.d.ts +12 -0
- package/dist/cjs/server/pii-shield/session-mapping.js +70 -0
- package/dist/cjs/server/pipeline.d.ts +26 -0
- package/dist/cjs/server/pipeline.js +127 -0
- package/dist/cjs/server/testing/approvals.d.ts +11 -0
- package/dist/cjs/server/testing/approvals.js +41 -0
- package/dist/cjs/server/testing/combination.d.ts +3 -0
- package/dist/cjs/server/testing/combination.js +83 -0
- package/dist/cjs/server/testing/create-test-suite.d.ts +29 -0
- package/dist/cjs/server/testing/create-test-suite.js +81 -0
- package/dist/cjs/server/testing/edge-cases.d.ts +8 -0
- package/dist/cjs/server/testing/edge-cases.js +277 -0
- package/dist/cjs/server/testing/guardrails.d.ts +14 -0
- package/dist/cjs/server/testing/guardrails.js +152 -0
- package/dist/cjs/server/testing/helpers.d.ts +14 -0
- package/dist/cjs/server/testing/helpers.js +119 -0
- package/dist/cjs/server/testing/index.d.ts +12 -0
- package/dist/cjs/server/testing/index.js +37 -0
- package/dist/cjs/server/testing/mock-executor.d.ts +8 -0
- package/dist/cjs/server/testing/mock-executor.js +40 -0
- package/dist/cjs/server/testing/regression.d.ts +7 -0
- package/dist/cjs/server/testing/regression.js +27 -0
- package/dist/cjs/server/testing/routing.d.ts +12 -0
- package/dist/cjs/server/testing/routing.js +63 -0
- package/dist/cjs/server/testing/schema-consistency.d.ts +6 -0
- package/dist/cjs/server/testing/schema-consistency.js +56 -0
- package/dist/cjs/server/testing/smoke.d.ts +11 -0
- package/dist/cjs/server/testing/smoke.js +64 -0
- package/dist/cjs/server/testing/types.d.ts +156 -0
- package/dist/cjs/server/testing/types.js +2 -0
- package/dist/cjs/types.d.ts +696 -0
- package/dist/cjs/types.js +91 -0
- package/dist/cli/commands/install-skills.d.ts +17 -0
- package/dist/cli/commands/install-skills.js +185 -0
- package/dist/cli/commands/install-skills.js.map +1 -0
- package/dist/cli/index.js +25 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/react/components/ai-trigger-button.js +4 -6
- package/dist/react/components/ai-trigger-button.js.map +1 -1
- package/dist/react/components/recording-bar.js +4 -6
- package/dist/react/components/recording-bar.js.map +1 -1
- package/dist/react/components/wavesurfer-loader.d.ts +5 -0
- package/dist/react/components/wavesurfer-loader.js +34 -0
- package/dist/react/components/wavesurfer-loader.js.map +1 -0
- package/dist/server/adapters/nestjs/chat/ai-chat.module.d.ts +1 -1
- package/dist/server/adapters/nestjs/chat/ai-chat.module.js +3 -2
- package/dist/server/adapters/nestjs/chat/ai-chat.module.js.map +1 -1
- package/dist/server/adapters/nestjs/chat/speech-stream.gateway.d.ts +1 -1
- package/dist/server/adapters/nestjs/chat/speech-stream.gateway.js +10 -8
- package/dist/server/adapters/nestjs/chat/speech-stream.gateway.js.map +1 -1
- package/dist/server/adapters/nestjs/chat/ws-loader.d.ts +5 -0
- package/dist/server/adapters/nestjs/chat/ws-loader.js +37 -0
- package/dist/server/adapters/nestjs/chat/ws-loader.js.map +1 -0
- package/openapi/package.json +5 -0
- package/package.json +59 -16
- package/react/langgraph/package.json +5 -0
- package/react/package.json +5 -0
- package/react/vercel/package.json +5 -0
- package/server/nestjs/package.json +5 -0
- package/server/nextjs/package.json +5 -0
- package/server/package.json +5 -0
- package/server/testing/package.json +5 -0
- package/skills/README.md +107 -0
- package/skills/building-glirastes-chat-ui/SKILL.md +378 -0
- package/skills/integrating-glirastes-nestjs/SKILL.md +346 -0
- package/skills/integrating-glirastes-nextjs/SKILL.md +312 -0
- package/skills/integrating-glirastes-nextjs-with-nestjs-backend/SKILL.md +359 -0
- package/skills/maintaining-glirastes-tools/SKILL.md +467 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ActionIdRegistry } from '../types.js';
|
|
2
|
+
export interface UiAction {
|
|
3
|
+
type: string;
|
|
4
|
+
actionId?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export type UiActionHandler = (action: UiAction) => void | Promise<void>;
|
|
8
|
+
export interface AiClientActionEventDetail {
|
|
9
|
+
actionId: string;
|
|
10
|
+
payload?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export declare class UiActionBus {
|
|
13
|
+
private handlersByType;
|
|
14
|
+
private handlersById;
|
|
15
|
+
subscribeByType(type: string, handler: UiActionHandler): () => void;
|
|
16
|
+
subscribeById(actionId: string, handler: UiActionHandler): () => void;
|
|
17
|
+
dispatch(action: UiAction): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export declare function useAiClientActionByType(bus: UiActionBus, actionType: string, handler: UiActionHandler): void;
|
|
20
|
+
export declare function useAiClientActionById(bus: UiActionBus, actionId: string, handler: UiActionHandler): void;
|
|
21
|
+
/**
|
|
22
|
+
* Set the action ID registry for validation (call once at app startup).
|
|
23
|
+
* The registry is typically auto-generated by the codegen package.
|
|
24
|
+
*/
|
|
25
|
+
export declare function setActionIdRegistry(registry: ActionIdRegistry): void;
|
|
26
|
+
/**
|
|
27
|
+
* Dispatch an AI client action via window events.
|
|
28
|
+
* Used by the chat panel / AI layer to trigger UI updates.
|
|
29
|
+
*/
|
|
30
|
+
export declare function dispatchAiClientAction(detail: AiClientActionEventDetail): void;
|
|
31
|
+
/**
|
|
32
|
+
* Dispatch one or more AI client actions via window events.
|
|
33
|
+
* Convenience wrapper for compound actions — accepts a single action or an array.
|
|
34
|
+
*/
|
|
35
|
+
export declare function dispatchAiClientActions(details: AiClientActionEventDetail | AiClientActionEventDetail[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* Hook to register a handler for a specific AI client action ID.
|
|
38
|
+
* The handler is tracked in a global registry for dev-mode validation.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* useAiClientAction('task-details.open', (payload) => {
|
|
43
|
+
* openTaskDetails(payload?.taskId as string);
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function useAiClientAction(actionId: string, handler: (payload?: Record<string, unknown>) => void): void;
|
|
48
|
+
/**
|
|
49
|
+
* Returns all currently registered handler actionIds.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getRegisteredHandlers(): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Returns actionIds defined in the registry but missing a registered handler.
|
|
54
|
+
* Useful for dev-mode validation to ensure all AI actions have handlers.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getMissingHandlers(): string[];
|
|
57
|
+
/**
|
|
58
|
+
* Returns info about a specific actionId from the registry.
|
|
59
|
+
*/
|
|
60
|
+
export declare function getActionIdInfo(actionId: string): import("../types.js").ActionIdEntry | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Hook that warns about missing AI action handlers in development mode.
|
|
63
|
+
* Checks after a 2-second delay to allow all components to mount and register.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* // In your AppShell or root layout component:
|
|
68
|
+
* useAiMissingHandlerWarning();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function useAiMissingHandlerWarning(options?: {
|
|
72
|
+
delay?: number;
|
|
73
|
+
}): void;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UiActionBus = void 0;
|
|
4
|
+
exports.useAiClientActionByType = useAiClientActionByType;
|
|
5
|
+
exports.useAiClientActionById = useAiClientActionById;
|
|
6
|
+
exports.setActionIdRegistry = setActionIdRegistry;
|
|
7
|
+
exports.dispatchAiClientAction = dispatchAiClientAction;
|
|
8
|
+
exports.dispatchAiClientActions = dispatchAiClientActions;
|
|
9
|
+
exports.useAiClientAction = useAiClientAction;
|
|
10
|
+
exports.getRegisteredHandlers = getRegisteredHandlers;
|
|
11
|
+
exports.getMissingHandlers = getMissingHandlers;
|
|
12
|
+
exports.getActionIdInfo = getActionIdInfo;
|
|
13
|
+
exports.useAiMissingHandlerWarning = useAiMissingHandlerWarning;
|
|
14
|
+
const react_1 = require("react");
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// UiActionBus (class-based, framework-agnostic)
|
|
17
|
+
// ============================================================================
|
|
18
|
+
function addHandler(map, key, handler) {
|
|
19
|
+
const handlers = map.get(key) ?? new Set();
|
|
20
|
+
handlers.add(handler);
|
|
21
|
+
map.set(key, handlers);
|
|
22
|
+
return () => {
|
|
23
|
+
const current = map.get(key);
|
|
24
|
+
if (!current)
|
|
25
|
+
return;
|
|
26
|
+
current.delete(handler);
|
|
27
|
+
if (current.size === 0)
|
|
28
|
+
map.delete(key);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
class UiActionBus {
|
|
32
|
+
handlersByType = new Map();
|
|
33
|
+
handlersById = new Map();
|
|
34
|
+
subscribeByType(type, handler) {
|
|
35
|
+
return addHandler(this.handlersByType, type, handler);
|
|
36
|
+
}
|
|
37
|
+
subscribeById(actionId, handler) {
|
|
38
|
+
return addHandler(this.handlersById, actionId, handler);
|
|
39
|
+
}
|
|
40
|
+
async dispatch(action) {
|
|
41
|
+
const typeHandlers = this.handlersByType.get(action.type);
|
|
42
|
+
const idHandlers = action.actionId
|
|
43
|
+
? this.handlersById.get(action.actionId)
|
|
44
|
+
: undefined;
|
|
45
|
+
const allHandlers = new Set([
|
|
46
|
+
...(typeHandlers ? Array.from(typeHandlers) : []),
|
|
47
|
+
...(idHandlers ? Array.from(idHandlers) : []),
|
|
48
|
+
]);
|
|
49
|
+
for (const handler of allHandlers) {
|
|
50
|
+
await handler(action);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.UiActionBus = UiActionBus;
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// UiActionBus Hooks
|
|
57
|
+
// ============================================================================
|
|
58
|
+
function useAiClientActionByType(bus, actionType, handler) {
|
|
59
|
+
(0, react_1.useEffect)(() => bus.subscribeByType(actionType, handler), [bus, actionType, handler]);
|
|
60
|
+
}
|
|
61
|
+
function useAiClientActionById(bus, actionId, handler) {
|
|
62
|
+
(0, react_1.useEffect)(() => bus.subscribeById(actionId, handler), [bus, actionId, handler]);
|
|
63
|
+
}
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// Window Event-based Action Dispatch (to-do-manager pattern)
|
|
66
|
+
// ============================================================================
|
|
67
|
+
const AI_CLIENT_ACTION_EVENT = 'ai-client-action';
|
|
68
|
+
/** Global registry of currently registered handler actionIds */
|
|
69
|
+
const registeredHandlers = new Set();
|
|
70
|
+
/** Optional reference to an ActionIdRegistry for validation */
|
|
71
|
+
let actionIdRegistryRef;
|
|
72
|
+
/**
|
|
73
|
+
* Set the action ID registry for validation (call once at app startup).
|
|
74
|
+
* The registry is typically auto-generated by the codegen package.
|
|
75
|
+
*/
|
|
76
|
+
function setActionIdRegistry(registry) {
|
|
77
|
+
actionIdRegistryRef = registry;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Dispatch an AI client action via window events.
|
|
81
|
+
* Used by the chat panel / AI layer to trigger UI updates.
|
|
82
|
+
*/
|
|
83
|
+
function dispatchAiClientAction(detail) {
|
|
84
|
+
if (typeof window === 'undefined')
|
|
85
|
+
return;
|
|
86
|
+
window.dispatchEvent(new CustomEvent(AI_CLIENT_ACTION_EVENT, { detail }));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Dispatch one or more AI client actions via window events.
|
|
90
|
+
* Convenience wrapper for compound actions — accepts a single action or an array.
|
|
91
|
+
*/
|
|
92
|
+
function dispatchAiClientActions(details) {
|
|
93
|
+
const actions = Array.isArray(details) ? details : [details];
|
|
94
|
+
for (const detail of actions) {
|
|
95
|
+
dispatchAiClientAction(detail);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Hook to register a handler for a specific AI client action ID.
|
|
100
|
+
* The handler is tracked in a global registry for dev-mode validation.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
104
|
+
* useAiClientAction('task-details.open', (payload) => {
|
|
105
|
+
* openTaskDetails(payload?.taskId as string);
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
function useAiClientAction(actionId, handler) {
|
|
110
|
+
const handlerRef = (0, react_1.useRef)(handler);
|
|
111
|
+
handlerRef.current = handler;
|
|
112
|
+
const stableHandler = (0, react_1.useCallback)((payload) => handlerRef.current(payload), []);
|
|
113
|
+
(0, react_1.useEffect)(() => {
|
|
114
|
+
registeredHandlers.add(actionId);
|
|
115
|
+
const handleEvent = (event) => {
|
|
116
|
+
const detail = event
|
|
117
|
+
.detail;
|
|
118
|
+
if (!detail || detail.actionId !== actionId)
|
|
119
|
+
return;
|
|
120
|
+
stableHandler(detail.payload);
|
|
121
|
+
};
|
|
122
|
+
window.addEventListener(AI_CLIENT_ACTION_EVENT, handleEvent);
|
|
123
|
+
return () => {
|
|
124
|
+
window.removeEventListener(AI_CLIENT_ACTION_EVENT, handleEvent);
|
|
125
|
+
registeredHandlers.delete(actionId);
|
|
126
|
+
};
|
|
127
|
+
}, [actionId, stableHandler]);
|
|
128
|
+
}
|
|
129
|
+
// ============================================================================
|
|
130
|
+
// Handler Registry Inspection (for dev-mode validation)
|
|
131
|
+
// ============================================================================
|
|
132
|
+
/**
|
|
133
|
+
* Returns all currently registered handler actionIds.
|
|
134
|
+
*/
|
|
135
|
+
function getRegisteredHandlers() {
|
|
136
|
+
return Array.from(registeredHandlers);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns actionIds defined in the registry but missing a registered handler.
|
|
140
|
+
* Useful for dev-mode validation to ensure all AI actions have handlers.
|
|
141
|
+
*/
|
|
142
|
+
function getMissingHandlers() {
|
|
143
|
+
if (!actionIdRegistryRef)
|
|
144
|
+
return [];
|
|
145
|
+
const required = Object.keys(actionIdRegistryRef);
|
|
146
|
+
return required.filter((id) => !registeredHandlers.has(id));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Returns info about a specific actionId from the registry.
|
|
150
|
+
*/
|
|
151
|
+
function getActionIdInfo(actionId) {
|
|
152
|
+
return actionIdRegistryRef?.[actionId];
|
|
153
|
+
}
|
|
154
|
+
// ============================================================================
|
|
155
|
+
// Dev-Mode Missing Handler Warning
|
|
156
|
+
// ============================================================================
|
|
157
|
+
/**
|
|
158
|
+
* Hook that warns about missing AI action handlers in development mode.
|
|
159
|
+
* Checks after a 2-second delay to allow all components to mount and register.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```tsx
|
|
163
|
+
* // In your AppShell or root layout component:
|
|
164
|
+
* useAiMissingHandlerWarning();
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
function useAiMissingHandlerWarning(options = {}) {
|
|
168
|
+
const { delay = 2000 } = options;
|
|
169
|
+
(0, react_1.useEffect)(() => {
|
|
170
|
+
if (process.env.NODE_ENV !== 'development')
|
|
171
|
+
return;
|
|
172
|
+
if (!actionIdRegistryRef)
|
|
173
|
+
return;
|
|
174
|
+
const timer = setTimeout(() => {
|
|
175
|
+
const missing = getMissingHandlers();
|
|
176
|
+
if (missing.length === 0)
|
|
177
|
+
return;
|
|
178
|
+
console.warn(`[glirastes] ${missing.length} AI action handler(s) missing:`, missing);
|
|
179
|
+
console.warn('[glirastes] Register handlers with useAiClientAction() or mark as @ai-ignore');
|
|
180
|
+
}, delay);
|
|
181
|
+
return () => clearTimeout(timer);
|
|
182
|
+
}, [delay]);
|
|
183
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ApprovalDescriptionFn } from '../types.js';
|
|
2
|
+
export interface ApprovalDescriptionConfig {
|
|
3
|
+
/** Map field names to human-readable labels. Example: `{ dueDate: 'Due date' }` */
|
|
4
|
+
fieldLabels?: Record<string, string>;
|
|
5
|
+
/**
|
|
6
|
+
* Map of field+value to translated display value.
|
|
7
|
+
* Outer key = field name, inner key = raw value.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* { priority: { high: 'High', low: 'Low' }, status: { done: 'Done' } }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
valueTranslations?: Record<string, Record<string, string>>;
|
|
15
|
+
/** Field names to always hide (e.g. internal IDs). UUIDs are hidden automatically. */
|
|
16
|
+
hiddenFields?: string[] | Set<string>;
|
|
17
|
+
/** Map tool names to human-readable action labels */
|
|
18
|
+
toolLabels?: Record<string, string>;
|
|
19
|
+
/** Locale for date formatting (default: `'en-US'`) */
|
|
20
|
+
dateLocale?: string;
|
|
21
|
+
/** Default confirm button text */
|
|
22
|
+
defaultConfirmText?: string;
|
|
23
|
+
/** Default description for unknown tools */
|
|
24
|
+
defaultDescription?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create an approval description generator that formats tool arguments
|
|
28
|
+
* into human-readable detail lines for approval cards.
|
|
29
|
+
*
|
|
30
|
+
* Features:
|
|
31
|
+
* - Auto-hides UUID values and configurable field names
|
|
32
|
+
* - Auto-formats ISO dates using the configured locale
|
|
33
|
+
* - Translates field values via configurable mappings
|
|
34
|
+
* - Flattens nested objects into detail lines
|
|
35
|
+
* - Filters empty arrays and null/undefined values
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { createApprovalDescriptionGenerator } from '../index.js';
|
|
40
|
+
*
|
|
41
|
+
* const getApprovalDescription = createApprovalDescriptionGenerator({
|
|
42
|
+
* fieldLabels: { title: 'Title', dueDate: 'Due date', priority: 'Priority' },
|
|
43
|
+
* valueTranslations: { priority: { high: 'High', medium: 'Medium', low: 'Low' } },
|
|
44
|
+
* hiddenFields: ['taskId', 'assigneeId', 'groupId'],
|
|
45
|
+
* toolLabels: { create_task: 'Create task', update_task: 'Update task' },
|
|
46
|
+
* dateLocale: 'de-DE',
|
|
47
|
+
* defaultConfirmText: 'Execute',
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* <AiChatProvider approvalDescription={getApprovalDescription} ... />
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function createApprovalDescriptionGenerator(config?: ApprovalDescriptionConfig): ApprovalDescriptionFn;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createApprovalDescriptionGenerator = createApprovalDescriptionGenerator;
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Helpers
|
|
6
|
+
// ============================================================================
|
|
7
|
+
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
|
+
const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
9
|
+
function capitalize(str) {
|
|
10
|
+
return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
|
|
11
|
+
}
|
|
12
|
+
function formatDateValue(strValue, locale) {
|
|
13
|
+
try {
|
|
14
|
+
const date = new Date(strValue);
|
|
15
|
+
if (isNaN(date.getTime()))
|
|
16
|
+
return strValue;
|
|
17
|
+
// Date-only (YYYY-MM-DD)
|
|
18
|
+
if (strValue.length === 10) {
|
|
19
|
+
return date.toLocaleDateString(locale, { day: '2-digit', month: '2-digit', year: 'numeric' });
|
|
20
|
+
}
|
|
21
|
+
return date.toLocaleString(locale, {
|
|
22
|
+
day: '2-digit', month: '2-digit', year: 'numeric',
|
|
23
|
+
hour: '2-digit', minute: '2-digit',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return strValue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// Factory
|
|
32
|
+
// ============================================================================
|
|
33
|
+
/**
|
|
34
|
+
* Create an approval description generator that formats tool arguments
|
|
35
|
+
* into human-readable detail lines for approval cards.
|
|
36
|
+
*
|
|
37
|
+
* Features:
|
|
38
|
+
* - Auto-hides UUID values and configurable field names
|
|
39
|
+
* - Auto-formats ISO dates using the configured locale
|
|
40
|
+
* - Translates field values via configurable mappings
|
|
41
|
+
* - Flattens nested objects into detail lines
|
|
42
|
+
* - Filters empty arrays and null/undefined values
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { createApprovalDescriptionGenerator } from '../index.js';
|
|
47
|
+
*
|
|
48
|
+
* const getApprovalDescription = createApprovalDescriptionGenerator({
|
|
49
|
+
* fieldLabels: { title: 'Title', dueDate: 'Due date', priority: 'Priority' },
|
|
50
|
+
* valueTranslations: { priority: { high: 'High', medium: 'Medium', low: 'Low' } },
|
|
51
|
+
* hiddenFields: ['taskId', 'assigneeId', 'groupId'],
|
|
52
|
+
* toolLabels: { create_task: 'Create task', update_task: 'Update task' },
|
|
53
|
+
* dateLocale: 'de-DE',
|
|
54
|
+
* defaultConfirmText: 'Execute',
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* <AiChatProvider approvalDescription={getApprovalDescription} ... />
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function createApprovalDescriptionGenerator(config = {}) {
|
|
61
|
+
const { fieldLabels = {}, valueTranslations = {}, hiddenFields: rawHiddenFields, toolLabels = {}, dateLocale = 'en-US', defaultConfirmText, defaultDescription = 'Confirm action?', } = config;
|
|
62
|
+
const hiddenFields = rawHiddenFields instanceof Set
|
|
63
|
+
? rawHiddenFields
|
|
64
|
+
: new Set(rawHiddenFields ?? []);
|
|
65
|
+
function formatValue(key, value) {
|
|
66
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
67
|
+
return Object.entries(value)
|
|
68
|
+
.filter(([, v]) => v !== undefined && v !== null && v !== '')
|
|
69
|
+
.map(([k, v]) => `${fieldLabels[k] || k}: ${formatValue(k, v)}`)
|
|
70
|
+
.join(', ');
|
|
71
|
+
}
|
|
72
|
+
const strValue = String(value);
|
|
73
|
+
if (valueTranslations[key]?.[strValue])
|
|
74
|
+
return valueTranslations[key][strValue];
|
|
75
|
+
if (ISO_DATE_REGEX.test(strValue))
|
|
76
|
+
return formatDateValue(strValue, dateLocale);
|
|
77
|
+
return capitalize(strValue);
|
|
78
|
+
}
|
|
79
|
+
function collectDetails(obj) {
|
|
80
|
+
const result = [];
|
|
81
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
82
|
+
if (value === undefined || value === null || value === '')
|
|
83
|
+
continue;
|
|
84
|
+
if (hiddenFields.has(key))
|
|
85
|
+
continue;
|
|
86
|
+
if (UUID_REGEX.test(String(value)))
|
|
87
|
+
continue;
|
|
88
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
89
|
+
result.push(...collectDetails(value));
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const label = fieldLabels[key] || key;
|
|
93
|
+
let displayValue;
|
|
94
|
+
if (Array.isArray(value)) {
|
|
95
|
+
const filtered = value.filter((v) => !UUID_REGEX.test(String(v)));
|
|
96
|
+
if (filtered.length === 0)
|
|
97
|
+
continue;
|
|
98
|
+
displayValue = filtered.map((v) => formatValue(key, v)).join(', ');
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
displayValue = formatValue(key, value);
|
|
102
|
+
}
|
|
103
|
+
result.push(`${label}: ${displayValue}`);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
return (toolName, approvalId, args) => {
|
|
108
|
+
const details = [];
|
|
109
|
+
if (args && typeof args === 'object') {
|
|
110
|
+
details.push(...collectDetails(args));
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
id: approvalId,
|
|
114
|
+
toolName,
|
|
115
|
+
args: (args && typeof args === 'object' ? args : {}),
|
|
116
|
+
messageId: '',
|
|
117
|
+
description: toolLabels[toolName] || defaultDescription,
|
|
118
|
+
details,
|
|
119
|
+
...(defaultConfirmText ? { confirmText: defaultConfirmText } : {}),
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** Schema-like object that can validate values (compatible with Zod, Valibot, etc.) */
|
|
2
|
+
interface SafeParseable {
|
|
3
|
+
safeParse(value: unknown): {
|
|
4
|
+
success: true;
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
} | {
|
|
7
|
+
success: false;
|
|
8
|
+
error: {
|
|
9
|
+
issues: unknown[];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface ToolResultHandlerConfig {
|
|
14
|
+
/** Schema to validate uiActions (compatible with Zod `.safeParse()`). When omitted, uiActions are not validated. */
|
|
15
|
+
uiActionSchema?: SafeParseable;
|
|
16
|
+
/**
|
|
17
|
+
* Custom action handlers by uiAction type.
|
|
18
|
+
* Called with the full validated uiAction object.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* actionHandlers: {
|
|
23
|
+
* 'set-filters': (action) => {
|
|
24
|
+
* window.dispatchEvent(new CustomEvent('ai-set-filters', { detail: action.filters }));
|
|
25
|
+
* },
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
actionHandlers?: Record<string, (action: Record<string, unknown>) => void>;
|
|
30
|
+
/**
|
|
31
|
+
* Map of entity names to list page destinations.
|
|
32
|
+
* Used by convention-based `{entity}-created` actions.
|
|
33
|
+
*
|
|
34
|
+
* @example `{ task: '/tasks', group: '/groups' }`
|
|
35
|
+
*/
|
|
36
|
+
entityListDestinations?: Record<string, string>;
|
|
37
|
+
/** Called when an entity-created or entity-deleted action requires navigation */
|
|
38
|
+
onNavigate?: (destination: string, entity: string) => void;
|
|
39
|
+
/** Called when an entity-updated action requires opening a detail view */
|
|
40
|
+
onOpenDetail?: (entity: string, entityId: string) => void;
|
|
41
|
+
/** Called for `run-client-action` uiAction types */
|
|
42
|
+
onClientAction?: (actionId: string, payload?: Record<string, unknown>) => void;
|
|
43
|
+
/** Called for any successful tool result */
|
|
44
|
+
onSuccess?: (toolName: string, result: Record<string, unknown>) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Fallback handlers for specific tool names.
|
|
47
|
+
* Called when a tool succeeds but has no uiAction to process.
|
|
48
|
+
*/
|
|
49
|
+
toolFallbacks?: Record<string, (result: Record<string, unknown>) => void>;
|
|
50
|
+
/** Optional dedupe guard for duplicate `run-client-action` dispatches. */
|
|
51
|
+
clientActionDedupe?: {
|
|
52
|
+
enabled?: boolean;
|
|
53
|
+
windowMs?: number;
|
|
54
|
+
actionIds?: string[];
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a tool result handler that processes tool outputs for UI-side actions.
|
|
59
|
+
*
|
|
60
|
+
* Extracts `uiAction` from tool results, validates against an optional schema,
|
|
61
|
+
* and routes to the appropriate handler based on action type.
|
|
62
|
+
*
|
|
63
|
+
* Supports convention-based entity actions (`{entity}-created`, `{entity}-updated`,
|
|
64
|
+
* `{entity}-deleted`), `run-client-action`, and custom action handlers.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { createToolResultHandler } from '../index.js';
|
|
69
|
+
* import { dispatchAiClientAction } from '../ui/index.js';
|
|
70
|
+
*
|
|
71
|
+
* const handleToolResult = createToolResultHandler({
|
|
72
|
+
* uiActionSchema: mySchema,
|
|
73
|
+
* entityListDestinations: { task: '/tasks', group: '/groups' },
|
|
74
|
+
* onNavigate: (dest) => router.push(dest),
|
|
75
|
+
* onOpenDetail: (entity, id) => openPanel(entity, id),
|
|
76
|
+
* onClientAction: (actionId, payload) => dispatchAiClientAction({ actionId, payload }),
|
|
77
|
+
* onSuccess: () => window.dispatchEvent(new CustomEvent('data-refresh')),
|
|
78
|
+
* actionHandlers: {
|
|
79
|
+
* 'set-filters': (action) => {
|
|
80
|
+
* window.dispatchEvent(new CustomEvent('ai-set-filters', { detail: action.filters }));
|
|
81
|
+
* },
|
|
82
|
+
* },
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // Wire into AiChatProvider or use in useEffect:
|
|
86
|
+
* <AiChatProvider onToolResult={handleToolResult} ... />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function createToolResultHandler(config: ToolResultHandlerConfig): (toolName: string, result: unknown) => void;
|
|
90
|
+
export {};
|