Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/frameworks/vue/src/chat/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as GenuiChat } from './GenuiChat.vue';
export { cardIdSymbol } from './useChat.js';
export * from './CustomModelProvider.js';
export * from './response-handler.js';
export * from './chat.types.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
import { defineAsyncComponent, h } from 'vue';
import type { GenuiChat } from '@opentiny/genui-sdk-vue';
import { cardIdSymbol, type GenuiChat } from '@opentiny/genui-sdk-vue';

const GenuiRendererNg = defineAsyncComponent(() =>
import('schema-renderer-ng-adpater').then((m) => m.SchemaRendererNgAdapter),
);

/** Angular context 用的是另一份 CARD_ID Symbol,注入 Vue Chat 的 cardIdSymbol 才能让 saveState 定位到消息 */
function bindCardIdToAction<T extends { execute: (params: any, context: Record<string | symbol, any>) => any }>(
action: T,
cardId: string,
): T {
return {
...action,
execute: (params: any, context: Record<string | symbol, any> = {}) =>
action.execute(params, {
...context,
[cardIdSymbol]: cardId,
}),
};
}

export function getMessageRendererAngular(instance: InstanceType<typeof GenuiChat>) {
return (schemaCardProps) => {
const props = instance.getProps();
const { continueChatAction, saveStateAction } = instance;
const cardId = schemaCardProps.id;
const customActions = {
continueChat: bindCardIdToAction(continueChatAction, cardId),
saveState: bindCardIdToAction(saveStateAction, cardId),
};
return h(
'div',
h(GenuiRendererNg, {
...schemaCardProps,
requiredCompleteFieldSelectors: props.requiredCompleteFieldSelectors || [],
generating: instance.lastSchemaCardId === schemaCardProps.id ? instance.generating : false,
customActions: {
continueChat: continueChatAction,
saveState: saveStateAction,
},
customActions,
key: schemaCardProps.id,
}),
);
Expand Down
Loading