@chat-lab/ui 0.1.0-beta.52 → 0.1.0-beta.53

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.
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('../../packages/core/dist/index.cjs');
4
+ var deepAssign = require('../../utils/deepAssign.cjs');
4
5
 
5
6
  const pluginName = 'SkillAgentPlugin';
6
7
  class SkillAgentPlugin extends index.ChatkitPlugin {
@@ -12,17 +13,18 @@ class SkillAgentPlugin extends index.ChatkitPlugin {
12
13
  apply(compiler) {
13
14
  compiler.hooks.message.received.tap(pluginName, (ctx) => {
14
15
  const metadata = ctx.metadata;
16
+ const threadId = ctx.threadId;
15
17
  if (metadata.hasStateDelta) {
16
- this.onStateChange?.(metadata.stateDelta);
18
+ const thread = this.chatController?.getThread(threadId);
19
+ const pendingState = deepAssign.deepAssign(thread?.metadata?.state || {}, metadata.stateDelta);
20
+ this.onStateChange?.(pendingState);
21
+ this.chatController?.updateThread(threadId, {
22
+ metadata: {
23
+ ...thread?.metadata,
24
+ state: pendingState,
25
+ },
26
+ });
17
27
  }
18
- const threadId = ctx.threadId;
19
- const thread = this.chatController?.getThread(threadId);
20
- this.chatController?.updateThread(threadId, {
21
- metadata: {
22
- ...thread?.metadata,
23
- stateDelta: metadata.stateDelta,
24
- },
25
- });
26
28
  return ctx;
27
29
  });
28
30
  compiler.hooks.message.beforeSend.tap(pluginName, async (ctx) => {
@@ -1 +1 @@
1
- {"version":3,"file":"SkillAgentPlugin.cjs","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"sourcesContent":["import { ChatkitPlugin, Compiler } from '@chat-lab/core';\nimport { SkillAgentOptions } from '.';\nconst pluginName = 'SkillAgentPlugin';\nclass SkillAgentPlugin extends ChatkitPlugin {\n onStateChange?: (state: string) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n constructor(options: {\n onStateChange?: (state: string) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n }) {\n super({ pluginName });\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n apply(compiler: Compiler) {\n compiler.hooks.message.received.tap(pluginName, (ctx: any) => {\n const metadata = ctx.metadata;\n if (metadata.hasStateDelta) {\n this.onStateChange?.(metadata.stateDelta);\n }\n const threadId = ctx.threadId;\n const thread = this.chatController?.getThread(threadId);\n this.chatController?.updateThread(threadId, {\n metadata: {\n ...thread?.metadata,\n stateDelta: metadata.stateDelta,\n },\n });\n\n return ctx;\n });\n\n compiler.hooks.message.beforeSend.tap(pluginName, async (ctx: any) => {\n const filePaths = await this.onUploadFiles?.(\n ctx.userMessage.attaches.map(({ file }) => file),\n );\n\n return {\n ...ctx,\n attachments: [],\n userMessage: {\n ...ctx.userMessage,\n content: ctx.userMessage.content.concat({\n type: 'text',\n text: `附件 :${filePaths?.join(',') || ''}`,\n }),\n },\n };\n });\n }\n\n updateOptions(options: SkillAgentOptions) {\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n}\n\nexport default SkillAgentPlugin;\n"],"names":["ChatkitPlugin"],"mappings":";;;;AAEA,MAAM,UAAU,GAAG,kBAAkB,CAAC;AACtC,MAAM,gBAAiB,SAAQA,mBAAa,CAAA;AAG1C,IAAA,WAAA,CAAY,OAGX,EAAA;AACC,QAAA,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;AACtB,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAC3C,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;KAC5C;AACD,IAAA,KAAK,CAAC,QAAkB,EAAA;AACtB,QAAA,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,GAAQ,KAAI;AAC3D,YAAA,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAC9B,Y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;AAC3C,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;KAC5C;AACF;;;;"}
1
+ {"version":3,"file":"SkillAgentPlugin.cjs","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"sourcesContent":["import { ChatkitPlugin, Compiler } from '@chat-lab/core';\nimport { SkillAgentOptions } from '.';\nimport { deepAssign } from '@/utils/deepAssign';\nconst pluginName = 'SkillAgentPlugin';\nclass SkillAgentPlugin extends ChatkitPlugin {\n onStateChange?: (state: Record<string, unknown>) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n constructor(options: {\n onStateChange?: (state: Record<string, unknown>) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n }) {\n super({ pluginName });\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n apply(compiler: Compiler) {\n compiler.hooks.message.received.tap(pluginName, (ctx: any) => {\n const metadata = ctx.metadata;\n const threadId = ctx.threadId;\n if (metadata.hasStateDelta) {\n const thread = this.chatController?.getThread(threadId);\n const pendingState = deepAssign(\n thread?.metadata?.state || {},\n metadata.stateDelta,\n ) as Record<string, unknown>;\n this.onStateChange?.(pendingState);\n this.chatController?.updateThread(threadId, {\n metadata: {\n ...thread?.metadata,\n state: pendingState,\n },\n });\n }\n\n return ctx;\n });\n\n compiler.hooks.message.beforeSend.tap(pluginName, async (ctx: any) => {\n const filePaths = await this.onUploadFiles?.(\n ctx.userMessage.attaches.map(({ file }) => file),\n );\n\n return {\n ...ctx,\n attachments: [],\n userMessage: {\n ...ctx.userMessage,\n content: ctx.userMessage.content.concat({\n type: 'text',\n text: `附件 :${filePaths?.join(',') || ''}`,\n }),\n },\n };\n });\n }\n\n updateOptions(options: SkillAgentOptions) {\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n}\n\nexport default SkillAgentPlugin;\n"],"names":["ChatkitPlugin","deepAssign"],"mappings":";;;;;AAGA,MAAM,UAAU,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AAI,CAAC,aAAa,GACxC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC,CACjD,CAAC;YAEF,OAAO;AACL,gBAAA,GAAG,GAAG;AACN,gBAAA,WAAW,EAAE,EAAE;AACf,gBAAA,WAAW,EAAE;oBACX,GAAG,GAAG,CAAC,WAAW;oBAClB,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;AACtC,wBAAA,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,CAAO,IAAA,EAAA,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAE,CAAA;qBAC1C,CAAC;AACH,iBAAA;aACF,CAAC;AACJ,SAAC,CAAC,CAAC;KACJ;AAED,IAAA,aAAa,CAAC,OAA0B,EAAA;AACtC,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAC3C,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;KAC5C;AACF;;;;"}
@@ -1,10 +1,10 @@
1
1
  import { ChatkitPlugin, Compiler } from '@chat-lab/core';
2
2
  import { SkillAgentOptions } from '.';
3
3
  declare class SkillAgentPlugin extends ChatkitPlugin {
4
- onStateChange?: (state: string) => void;
4
+ onStateChange?: (state: Record<string, unknown>) => void;
5
5
  onUploadFiles?: (files: File[]) => Promise<string[]>;
6
6
  constructor(options: {
7
- onStateChange?: (state: string) => void;
7
+ onStateChange?: (state: Record<string, unknown>) => void;
8
8
  onUploadFiles?: (files: File[]) => Promise<string[]>;
9
9
  });
10
10
  apply(compiler: Compiler): void;
@@ -1 +1 @@
1
- {"version":3,"file":"SkillAgentPlugin.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC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AAQ,EAAE,QAAQ;IAyCxB,aAAa,CAAC,OAAO,EAAE,iBAAiB;CAIzC;AAED,eAAe,gBAAgB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { ChatkitPlugin } from '../../packages/core/dist/index.js';
2
+ import { deepAssign } from '../../utils/deepAssign.js';
2
3
 
3
4
  const pluginName = 'SkillAgentPlugin';
4
5
  class SkillAgentPlugin extends ChatkitPlugin {
@@ -10,17 +11,18 @@ class SkillAgentPlugin extends ChatkitPlugin {
10
11
  apply(compiler) {
11
12
  compiler.hooks.message.received.tap(pluginName, (ctx) => {
12
13
  const metadata = ctx.metadata;
14
+ const threadId = ctx.threadId;
13
15
  if (metadata.hasStateDelta) {
14
- this.onStateChange?.(metadata.stateDelta);
16
+ const thread = this.chatController?.getThread(threadId);
17
+ const pendingState = deepAssign(thread?.metadata?.state || {}, metadata.stateDelta);
18
+ this.onStateChange?.(pendingState);
19
+ this.chatController?.updateThread(threadId, {
20
+ metadata: {
21
+ ...thread?.metadata,
22
+ state: pendingState,
23
+ },
24
+ });
15
25
  }
16
- const threadId = ctx.threadId;
17
- const thread = this.chatController?.getThread(threadId);
18
- this.chatController?.updateThread(threadId, {
19
- metadata: {
20
- ...thread?.metadata,
21
- stateDelta: metadata.stateDelta,
22
- },
23
- });
24
26
  return ctx;
25
27
  });
26
28
  compiler.hooks.message.beforeSend.tap(pluginName, async (ctx) => {
@@ -1 +1 @@
1
- {"version":3,"file":"SkillAgentPlugin.js","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"sourcesContent":["import { ChatkitPlugin, Compiler } from '@chat-lab/core';\nimport { SkillAgentOptions } from '.';\nconst pluginName = 'SkillAgentPlugin';\nclass SkillAgentPlugin extends ChatkitPlugin {\n onStateChange?: (state: string) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n constructor(options: {\n onStateChange?: (state: string) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n }) {\n super({ pluginName });\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n apply(compiler: Compiler) {\n compiler.hooks.message.received.tap(pluginName, (ctx: any) => {\n const metadata = ctx.metadata;\n if (metadata.hasStateDelta) {\n this.onStateChange?.(metadata.stateDelta);\n }\n const threadId = ctx.threadId;\n const thread = this.chatController?.getThread(threadId);\n this.chatController?.updateThread(threadId, {\n metadata: {\n ...thread?.metadata,\n stateDelta: metadata.stateDelta,\n },\n });\n\n return ctx;\n });\n\n compiler.hooks.message.beforeSend.tap(pluginName, async (ctx: any) => {\n const filePaths = await this.onUploadFiles?.(\n ctx.userMessage.attaches.map(({ file }) => file),\n );\n\n return {\n ...ctx,\n attachments: [],\n userMessage: {\n ...ctx.userMessage,\n content: ctx.userMessage.content.concat({\n type: 'text',\n text: `附件 :${filePaths?.join(',') || ''}`,\n }),\n },\n };\n });\n }\n\n updateOptions(options: SkillAgentOptions) {\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n}\n\nexport default SkillAgentPlugin;\n"],"names":[],"mappings":";;AAEA,MAAM,UAAU,GAAG,kBAAkB,CAAC;AACtC,MAAM,gBAAiB,SAAQ,aAAa,CAAA;AAG1C,IAAA,WAAA,CAAY,OAGX,EAAA;AACC,QAAA,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;AACtB,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAC3C,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;KAC5C;AACD,IAAA,KAAK,CAAC,QAAkB,EAAA;AACtB,QAAA,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,GAAQ,KAAI;AAC3D,YAAA,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAC9B,YAAA,IAAI,QAAQ,CAAC,aAAa,EAAE;gBAC1B,IAAI,CAAC,aAAa,GAAG,QAA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F;;;;"}
1
+ {"version":3,"file":"SkillAgentPlugin.js","sources":["../../../src/hooks/useSkillAgent/SkillAgentPlugin.ts"],"sourcesContent":["import { ChatkitPlugin, Compiler } from '@chat-lab/core';\nimport { SkillAgentOptions } from '.';\nimport { deepAssign } from '@/utils/deepAssign';\nconst pluginName = 'SkillAgentPlugin';\nclass SkillAgentPlugin extends ChatkitPlugin {\n onStateChange?: (state: Record<string, unknown>) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n constructor(options: {\n onStateChange?: (state: Record<string, unknown>) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n }) {\n super({ pluginName });\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n apply(compiler: Compiler) {\n compiler.hooks.message.received.tap(pluginName, (ctx: any) => {\n const metadata = ctx.metadata;\n const threadId = ctx.threadId;\n if (metadata.hasStateDelta) {\n const thread = this.chatController?.getThread(threadId);\n const pendingState = deepAssign(\n thread?.metadata?.state || {},\n metadata.stateDelta,\n ) as Record<string, unknown>;\n this.onStateChange?.(pendingState);\n this.chatController?.updateThread(threadId, {\n metadata: {\n ...thread?.metadata,\n state: pendingState,\n },\n });\n }\n\n return ctx;\n });\n\n compiler.hooks.message.beforeSend.tap(pluginName, async (ctx: any) => {\n const filePaths = await this.onUploadFiles?.(\n ctx.userMessage.attaches.map(({ file }) => file),\n );\n\n return {\n ...ctx,\n attachments: [],\n userMessage: {\n ...ctx.userMessage,\n content: ctx.userMessage.content.concat({\n type: 'text',\n text: `附件 :${filePaths?.join(',') || ''}`,\n }),\n },\n };\n });\n }\n\n updateOptions(options: SkillAgentOptions) {\n this.onStateChange = options.onStateChange;\n this.onUploadFiles = options.onUploadFiles;\n }\n}\n\nexport default SkillAgentPlugin;\n"],"names":[],"mappings":";;;AAGA,MAAM,UAAU,GAAG,kBAAkB,CAAC;AACtC,MAAM,gBAAiB,SAAQ,aAAa,CAAA;AAG1C,IAAA,WAAA,CAAY,OAGX,EAAA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K,IAAI,CAAC,CACjD,CAAC;YAEF,OAAO;AACL,gBAAA,GAAG,GAAG;AACN,gBAAA,WAAW,EAAE,EAAE;AACf,gBAAA,WAAW,EAAE;oBACX,GAAG,GAAG,CAAC,WAAW;oBAClB,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;AACtC,wBAAA,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,CAAO,IAAA,EAAA,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAE,CAAA;qBAC1C,CAAC;AACH,iBAAA;aACF,CAAC;AACJ,SAAC,CAAC,CAAC;KACJ;AAED,IAAA,aAAa,CAAC,OAA0B,EAAA;AACtC,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAC3C,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;KAC5C;AACF;;;;"}
@@ -14,7 +14,19 @@ const useSkillAgent = (options) => {
14
14
  onUploadFiles: options.onUploadFiles,
15
15
  });
16
16
  }
17
+ const adkPlugin = React.useRef();
18
+ if (!adkPlugin.current) {
19
+ adkPlugin.current = new index.AdkPlugin({
20
+ appName: options.adkOptions.appName,
21
+ userId: options.adkOptions.userID,
22
+ });
23
+ }
17
24
  pluginRef.current.updateOptions(options);
25
+ adkPlugin.current.updateOptions({
26
+ appName: options.adkOptions.appName,
27
+ userId: options.adkOptions.userID,
28
+ onStateChange: options.onStateChange,
29
+ });
18
30
  if (!chatControllerRef.current) {
19
31
  const store = new index.ThreadMessageManager(index.createThreadManagerState());
20
32
  const plugin = pluginRef.current;
@@ -63,14 +75,14 @@ const useSkillAgent = (options) => {
63
75
  chatControllerRef.current?.setCurrentThread(sessionId);
64
76
  });
65
77
  });
66
- const getDeltaState = index$1(() => {
67
- return chatControllerRef.current?.getCurrentThread();
78
+ const getState = index$1(() => {
79
+ return chatControllerRef.current?.getCurrentThread()?.metadata?.state;
68
80
  });
69
81
  return {
70
82
  controllerRef: chatControllerRef,
71
83
  sendMessage,
72
84
  ready,
73
- getDeltaState,
85
+ getState,
74
86
  };
75
87
  };
76
88
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/hooks/useSkillAgent/index.tsx"],"sourcesContent":["import {\n ChatController,\n createThreadManagerState,\n ThreadMessageManager,\n AdkPlugin,\n} from '@chat-lab/core';\nimport { useRef } from 'react';\nimport { v4 as uuid } from 'uuid';\nimport SkillAgentPlugin from './SkillAgentPlugin';\nimport { useMemoizedFn } from 'ahooks';\n\nexport interface SkillAgentOptions {\n api: string;\n sessionId?: string;\n adkOptions: {\n appName: string;\n userID: string;\n };\n query?: Record<string, string>;\n onError?: (error: Error) => void;\n onStateChange?: (state: {}) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n}\n\nconst useSkillAgent = (options: SkillAgentOptions) => {\n const chatControllerRef = useRef<ChatController>();\n const pluginRef = useRef<SkillAgentPlugin>();\n if (!pluginRef.current) {\n pluginRef.current = new SkillAgentPlugin({\n onStateChange: options.onStateChange,\n onUploadFiles: options.onUploadFiles,\n });\n }\n pluginRef.current.updateOptions(options);\n if (!chatControllerRef.current) {\n const store = new ThreadMessageManager(createThreadManagerState());\n const plugin = pluginRef.current;\n const adlPlugin = new AdkPlugin({\n appName: options.adkOptions.appName,\n userId: options.adkOptions.userID,\n });\n chatControllerRef.current = new ChatController({\n requestOptions: {\n api: options.api,\n meta: options.query,\n headers: {\n Authorization: 'Bearer',\n },\n defaultParams: {\n streaming: true,\n },\n },\n protocolOptions: {\n protocol: 'ADK',\n },\n storeManager: store,\n plugins: [plugin, adlPlugin],\n });\n }\n\n const sendMessage = useMemoizedFn(({ message }: { message: string }) => {\n chatControllerRef.current?.sendMessage({\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n });\n });\n const ready = useMemoizedFn(({ sessionId }: { sessionId: string }) => {\n chatControllerRef.current\n ?.addThread({\n id: sessionId,\n name: sessionId,\n metadata: {},\n sending: false,\n messages: [],\n })\n .then(() => {\n chatControllerRef.current?.setCurrentThread(sessionId);\n });\n });\n\n const getDeltaState = useMemoizedFn(() => {\n return chatControllerRef.current?.getCurrentThread();\n });\n return {\n controllerRef: chatControllerRef,\n sendMessage,\n ready,\n getDeltaState,\n };\n};\n\nexport { useSkillAgent };\n"],"names":["useRef","ThreadMessageManager","createThreadManagerState","AdkPlugin","ChatController","useMemoizedFn"],"mappings":";;;;;;;AAwBA,MAAM,aAAa,GAAG,CAAC,OAA0B,KAAI;AACnD,IAAA,MAAM,iBAAiB,GAAGA,YAAM,EAAkB,CAAC;AACnD,IAAA,MAAM,SAAS,GAAGA,YAAM,EAAoB,CAAC;AAC7C,IAAA,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;AACtB,QAAA,SAAS,CAAC,OAAO,GAAG,IAAI,gBAAgB,CAAC;YACvC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,aAAa,EAAE,OAAO,CAAC,aAAa;AACrC,SAAA,CAAC,CAAC;KACJ;AACD,IAAA,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACzC,IAAA,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE;QAC9B,MAAM,KAAK,GAAG,IAAIC,0BAAoB,CAACC,8BAAwB,EAAE,CAAC,CAAC;AACnE,QAAA,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;AACjC,QAAA,MAAM,SAAS,GAAG,IAAIC,eAAS,CAAC;AAC9B,YAAA,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;AACnC,YAAA,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM;AAClC,SAAA,CAAC,CAAC;AACH,QAAA,iBAAiB,CAAC,OAAO,GAAG,IAAIC,oBAAc,CAAC;AAC7C,YAAA,cAAc,EAAE;gBACd,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,IAAI,EAAE,OAAO,CAAC,KAAK;AACnB,gBA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,aAAa;KACd,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/hooks/useSkillAgent/index.tsx"],"sourcesContent":["import {\n ChatController,\n createThreadManagerState,\n ThreadMessageManager,\n AdkPlugin,\n} from '@chat-lab/core';\nimport { useRef } from 'react';\nimport { v4 as uuid } from 'uuid';\nimport SkillAgentPlugin from './SkillAgentPlugin';\nimport { useMemoizedFn } from 'ahooks';\n\nexport interface SkillAgentOptions {\n api: string;\n sessionId?: string;\n adkOptions: {\n appName: string;\n userID: string;\n };\n query?: Record<string, string>;\n onError?: (error: Error) => void;\n onStateChange?: (state: {}) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n}\n\nconst useSkillAgent = (options: SkillAgentOptions) => {\n const chatControllerRef = useRef<ChatController>();\n const pluginRef = useRef<SkillAgentPlugin>();\n if (!pluginRef.current) {\n pluginRef.current = new SkillAgentPlugin({\n onStateChange: options.onStateChange,\n onUploadFiles: options.onUploadFiles,\n });\n }\n const adkPlugin = useRef<AdkPlugin>();\n if (!adkPlugin.current) {\n adkPlugin.current = new AdkPlugin({\n appName: options.adkOptions.appName,\n userId: options.adkOptions.userID,\n });\n }\n pluginRef.current.updateOptions(options);\n adkPlugin.current.updateOptions({\n appName: options.adkOptions.appName,\n userId: options.adkOptions.userID,\n onStateChange: options.onStateChange,\n });\n\n if (!chatControllerRef.current) {\n const store = new ThreadMessageManager(createThreadManagerState());\n const plugin = pluginRef.current;\n const adlPlugin = new AdkPlugin({\n appName: options.adkOptions.appName,\n userId: options.adkOptions.userID,\n });\n chatControllerRef.current = new ChatController({\n requestOptions: {\n api: options.api,\n meta: options.query,\n headers: {\n Authorization: 'Bearer',\n },\n defaultParams: {\n streaming: true,\n },\n },\n protocolOptions: {\n protocol: 'ADK',\n },\n storeManager: store,\n plugins: [plugin, adlPlugin],\n });\n }\n\n const sendMessage = useMemoizedFn(({ message }: { message: string }) => {\n chatControllerRef.current?.sendMessage({\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n });\n });\n const ready = useMemoizedFn(({ sessionId }: { sessionId: string }) => {\n chatControllerRef.current\n ?.addThread({\n id: sessionId,\n name: sessionId,\n metadata: {},\n sending: false,\n messages: [],\n })\n .then(() => {\n chatControllerRef.current?.setCurrentThread(sessionId);\n });\n });\n\n const getState = useMemoizedFn(() => {\n return chatControllerRef.current?.getCurrentThread()?.metadata?.state;\n });\n return {\n controllerRef: chatControllerRef,\n sendMessage,\n ready,\n getState,\n };\n};\n\nexport { useSkillAgent };\n"],"names":["useRef","AdkPlugin","ThreadMessageManager","createThreadManagerState","ChatController","useMemoizedFn"],"mappings":";;;;;;;AAwBA,MAAM,aAAa,GAAG,CAAC,OAA0B,KAAI;AACnD,IAAA,MAAM,iBAAiB,GAAGA,YAAM,EAAkB,CAAC;AACnD,IAAA,MAAM,SAAS,GAAGA,YAAM,EAAoB,CAAC;AAC7C,IAAA,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;AACtB,QAAA,SAAS,CAAC,OAAO,GAAG,IAAI,gBAAgB,CAAC;YACvC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,aAAa,EAAE,OAAO,CAAC,aAAa;AACrC,SAAA,CAAC,CAAC;KACJ;AACD,IAAA,MAAM,SAAS,GAAGA,YAAM,EAAa,CAAC;AACtC,IAAA,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;AACtB,QAAA,SAAS,CAAC,OAAO,GAAG,IAAIC,eAAS,CAAC;AAChC,YAAA,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;AACnC,YAAA,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM;AAClC,SAAA,CAAC,CAAC;KACJ;AACD,IAAA,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACzC,IAAA,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC;AAC9B,QAAA,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;AACnC,QAAA,MAAM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MAAM,KAAK,GAAGA,OAAa,CAAC,CAAC,EAAE,SAAS,EAAyB,KAAI;AACnE,QAAA,iBAAiB,CAAC,OAAO;AACvB,cAAE,SAAS,CAAC;AACV,YAAA,EAAE,EAAE,SAAS;AACb,YAAA,IAAI,EAAE,SAAS;AACf,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,KAAK;AACd,YAAA,QAAQ,EAAE,EAAE;SACb,CAAC;aACD,IAAI,CAAC,MAAK;AACT,YAAA,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACzD,SAAC,CAAC,CAAC;AACP,KAAC,CAAC,CAAC;AAEH,IAAA,MAAM,QAAQ,GAAGA,OAAa,CAAC,MAAK;QAClC,OAAO,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC;AACxE,KAAC,CAAC,CAAC;IACH,OAAO;AACL,QAAA,aAAa,EAAE,iBAAiB;QAChC,WAAW;QACX,KAAK;QACL,QAAQ;KACT,CAAC;AACJ;;;;"}
@@ -19,7 +19,7 @@ declare const useSkillAgent: (options: SkillAgentOptions) => {
19
19
  ready: (this: unknown, args_0: {
20
20
  sessionId: string;
21
21
  }) => void;
22
- getDeltaState: (this: unknown) => import("@chat-lab/core").Thread<import("@chat-lab/core").ChatMessage<import("@chat-lab/core").BaseMessage>> | null | undefined;
22
+ getState: (this: unknown) => any;
23
23
  };
24
24
  export { useSkillAgent };
25
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSkillAgent/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAIf,MAAM,gBAAgB,CAAC;AAMxB,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE;QACV,OAAO,EAAE,M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@@ -1,4 +1,4 @@
1
- import { ThreadMessageManager, createThreadManagerState, AdkPlugin, ChatController } from '../../packages/core/dist/index.js';
1
+ import { AdkPlugin, ThreadMessageManager, createThreadManagerState, ChatController } from '../../packages/core/dist/index.js';
2
2
  import { useRef } from 'react';
3
3
  import SkillAgentPlugin from './SkillAgentPlugin.js';
4
4
  import useMemoizedFn from '../../node_modules/.pnpm/ahooks@3.9.6_react-dom@17.0.2_react@17.0.2__react@17.0.2/node_modules/ahooks/es/useMemoizedFn/index.js';
@@ -12,7 +12,19 @@ const useSkillAgent = (options) => {
12
12
  onUploadFiles: options.onUploadFiles,
13
13
  });
14
14
  }
15
+ const adkPlugin = useRef();
16
+ if (!adkPlugin.current) {
17
+ adkPlugin.current = new AdkPlugin({
18
+ appName: options.adkOptions.appName,
19
+ userId: options.adkOptions.userID,
20
+ });
21
+ }
15
22
  pluginRef.current.updateOptions(options);
23
+ adkPlugin.current.updateOptions({
24
+ appName: options.adkOptions.appName,
25
+ userId: options.adkOptions.userID,
26
+ onStateChange: options.onStateChange,
27
+ });
16
28
  if (!chatControllerRef.current) {
17
29
  const store = new ThreadMessageManager(createThreadManagerState());
18
30
  const plugin = pluginRef.current;
@@ -61,14 +73,14 @@ const useSkillAgent = (options) => {
61
73
  chatControllerRef.current?.setCurrentThread(sessionId);
62
74
  });
63
75
  });
64
- const getDeltaState = useMemoizedFn(() => {
65
- return chatControllerRef.current?.getCurrentThread();
76
+ const getState = useMemoizedFn(() => {
77
+ return chatControllerRef.current?.getCurrentThread()?.metadata?.state;
66
78
  });
67
79
  return {
68
80
  controllerRef: chatControllerRef,
69
81
  sendMessage,
70
82
  ready,
71
- getDeltaState,
83
+ getState,
72
84
  };
73
85
  };
74
86
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/hooks/useSkillAgent/index.tsx"],"sourcesContent":["import {\n ChatController,\n createThreadManagerState,\n ThreadMessageManager,\n AdkPlugin,\n} from '@chat-lab/core';\nimport { useRef } from 'react';\nimport { v4 as uuid } from 'uuid';\nimport SkillAgentPlugin from './SkillAgentPlugin';\nimport { useMemoizedFn } from 'ahooks';\n\nexport interface SkillAgentOptions {\n api: string;\n sessionId?: string;\n adkOptions: {\n appName: string;\n userID: string;\n };\n query?: Record<string, string>;\n onError?: (error: Error) => void;\n onStateChange?: (state: {}) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n}\n\nconst useSkillAgent = (options: SkillAgentOptions) => {\n const chatControllerRef = useRef<ChatController>();\n const pluginRef = useRef<SkillAgentPlugin>();\n if (!pluginRef.current) {\n pluginRef.current = new SkillAgentPlugin({\n onStateChange: options.onStateChange,\n onUploadFiles: options.onUploadFiles,\n });\n }\n pluginRef.current.updateOptions(options);\n if (!chatControllerRef.current) {\n const store = new ThreadMessageManager(createThreadManagerState());\n const plugin = pluginRef.current;\n const adlPlugin = new AdkPlugin({\n appName: options.adkOptions.appName,\n userId: options.adkOptions.userID,\n });\n chatControllerRef.current = new ChatController({\n requestOptions: {\n api: options.api,\n meta: options.query,\n headers: {\n Authorization: 'Bearer',\n },\n defaultParams: {\n streaming: true,\n },\n },\n protocolOptions: {\n protocol: 'ADK',\n },\n storeManager: store,\n plugins: [plugin, adlPlugin],\n });\n }\n\n const sendMessage = useMemoizedFn(({ message }: { message: string }) => {\n chatControllerRef.current?.sendMessage({\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n });\n });\n const ready = useMemoizedFn(({ sessionId }: { sessionId: string }) => {\n chatControllerRef.current\n ?.addThread({\n id: sessionId,\n name: sessionId,\n metadata: {},\n sending: false,\n messages: [],\n })\n .then(() => {\n chatControllerRef.current?.setCurrentThread(sessionId);\n });\n });\n\n const getDeltaState = useMemoizedFn(() => {\n return chatControllerRef.current?.getCurrentThread();\n });\n return {\n controllerRef: chatControllerRef,\n sendMessage,\n ready,\n getDeltaState,\n };\n};\n\nexport { useSkillAgent };\n"],"names":[],"mappings":";;;;;AAwBA,MAAM,aAAa,GAAG,CAAC,OAA0B,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WAAW,GAAG,aAAa,CAAC,CAAC,EAAE,OAAO,EAAuB,KAAI;AACrE,QAAA,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC;AACrC,YAAA,OAAO,EAAE;AACP,gBAAA;AACE,oBAAA,IAAI,EAAE,MAAM;AACZ,oBAAA,IAAI,EAAE,OAAO;AACd,iBAAA;AACF,aAAA;AACF,SAAA,CAAC,CAAC;AACL,KAAC,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,EAAE,SAAS,EAAyB,KAAI;AACnE,QAAA,iBAAiB,CAAC,OAAO;AACvB,cAAE,SAAS,CAAC;AACV,YAAA,EAAE,EAAE,SAAS;AACb,YAAA,IAAI,EAAE,SAAS;AACf,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,KAAK;AACd,YAAA,QAAQ,EAAE,EAAE;SACb,CAAC;aACD,IAAI,CAAC,MAAK;AACT,YAAA,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACzD,SAAC,CAAC,CAAC;AACP,KAAC,CAAC,CAAC;AAEH,IAAA,MAAM,aAAa,GAAG,aAAa,CAAC,MAAK;AACvC,QAAA,OAAO,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,EAAE,CAAC;AACvD,KAAC,CAAC,CAAC;IACH,OAAO;AACL,QAAA,aAAa,EAAE,iBAAiB;QAChC,WAAW;QACX,KAAK;QACL,aAAa;KACd,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/hooks/useSkillAgent/index.tsx"],"sourcesContent":["import {\n ChatController,\n createThreadManagerState,\n ThreadMessageManager,\n AdkPlugin,\n} from '@chat-lab/core';\nimport { useRef } from 'react';\nimport { v4 as uuid } from 'uuid';\nimport SkillAgentPlugin from './SkillAgentPlugin';\nimport { useMemoizedFn } from 'ahooks';\n\nexport interface SkillAgentOptions {\n api: string;\n sessionId?: string;\n adkOptions: {\n appName: string;\n userID: string;\n };\n query?: Record<string, string>;\n onError?: (error: Error) => void;\n onStateChange?: (state: {}) => void;\n onUploadFiles?: (files: File[]) => Promise<string[]>;\n}\n\nconst useSkillAgent = (options: SkillAgentOptions) => {\n const chatControllerRef = useRef<ChatController>();\n const pluginRef = useRef<SkillAgentPlugin>();\n if (!pluginRef.current) {\n pluginRef.current = new SkillAgentPlugin({\n onStateChange: options.onStateChange,\n onUploadFiles: options.onUploadFiles,\n });\n }\n const adkPlugin = useRef<AdkPlugin>();\n if (!adkPlugin.current) {\n adkPlugin.current = new AdkPlugin({\n appName: options.adkOptions.appName,\n userId: options.adkOptions.userID,\n });\n }\n pluginRef.current.updateOptions(options);\n adkPlugin.current.updateOptions({\n appName: options.adkOptions.appName,\n userId: options.adkOptions.userID,\n onStateChange: options.onStateChange,\n });\n\n if (!chatControllerRef.current) {\n const store = new ThreadMessageManager(createThreadManagerState());\n const plugin = pluginRef.current;\n const adlPlugin = new AdkPlugin({\n appName: options.adkOptions.appName,\n userId: options.adkOptions.userID,\n });\n chatControllerRef.current = new ChatController({\n requestOptions: {\n api: options.api,\n meta: options.query,\n headers: {\n Authorization: 'Bearer',\n },\n defaultParams: {\n streaming: true,\n },\n },\n protocolOptions: {\n protocol: 'ADK',\n },\n storeManager: store,\n plugins: [plugin, adlPlugin],\n });\n }\n\n const sendMessage = useMemoizedFn(({ message }: { message: string }) => {\n chatControllerRef.current?.sendMessage({\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n });\n });\n const ready = useMemoizedFn(({ sessionId }: { sessionId: string }) => {\n chatControllerRef.current\n ?.addThread({\n id: sessionId,\n name: sessionId,\n metadata: {},\n sending: false,\n messages: [],\n })\n .then(() => {\n chatControllerRef.current?.setCurrentThread(sessionId);\n });\n });\n\n const getState = useMemoizedFn(() => {\n return chatControllerRef.current?.getCurrentThread()?.metadata?.state;\n });\n return {\n controllerRef: chatControllerRef,\n sendMessage,\n ready,\n getState,\n };\n};\n\nexport { useSkillAgent };\n"],"names":[],"mapp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,CAAC,CAAC;AAEH,IAAA,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAK;QAClC,OAAO,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC;AACxE,KAAC,CAAC,CAAC;IACH,OAAO;AACL,QAAA,aAAa,EAAE,iBAAiB;QAChC,WAAW;QACX,KAAK;QACL,QAAQ;KACT,CAAC;AACJ;;;;"}
@@ -6,6 +6,7 @@ var mitt = require('../../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dis
6
6
  var vanilla = require('../../../node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/vanilla.cjs');
7
7
  var v4 = require('../../../node_modules/.pnpm/uuid@13.0.0/node_modules/uuid/dist/v4.cjs');
8
8
  var last = require('../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/last.cjs');
9
+ var isNil = require('../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNil.cjs');
9
10
  var throttle = require('../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/throttle.cjs');
10
11
  var keys = require('../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/keys.cjs');
11
12
  var compact = require('../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/compact.cjs');
@@ -1447,6 +1448,9 @@ var AdkPlugin = class extends ChatkitPlugin {
1447
1448
  this.setAppName = (appName) => {
1448
1449
  this.options.appName = appName;
1449
1450
  };
1451
+ this.updateOptions = (options) => {
1452
+ this.options = options;
1453
+ };
1450
1454
  this.options = options;
1451
1455
  this.adkProtocol = new Adk_default({
1452
1456
  omitCompleteText: false,
@@ -1573,6 +1577,7 @@ var AdkPlugin = class extends ChatkitPlugin {
1573
1577
  if (getFetchResponse.ok) {
1574
1578
  const data = await getFetchResponse.json();
1575
1579
  const xSessionId = getFetchResponse.headers.get("x-session-id");
1580
+ this.options.onStateChange?.(data.state);
1576
1581
  this.chatController?.updateThread(threadId, {
1577
1582
  metadata: {
1578
1583
  ...thread.metadata,
@@ -1580,7 +1585,7 @@ var AdkPlugin = class extends ChatkitPlugin {
1580
1585
  sessionId: data.id,
1581
1586
  ["isInitingSession"]: false,
1582
1587
  ["x-session-id"]: xSessionId,
1583
- deltaStatus: data.state
1588
+ state: data.state
1584
1589
  },
1585
1590
  // id: string;
1586
1591
  // author: string;
@@ -1819,8 +1824,6 @@ var toRaw = (obj) => {
1819
1824
  return obj;
1820
1825
  }
1821
1826
  };
1822
-
1823
- // src/ChatController.ts
1824
1827
  var ChatController = class {
1825
1828
  constructor(options) {
1826
1829
  this.abortControllers = /* @__PURE__ */ new Map();
@@ -1892,7 +1895,11 @@ var ChatController = class {
1892
1895
  this.store.setLoading(id, false);
1893
1896
  }
1894
1897
  getCurrentThread() {
1895
- return this.store.getCurrentThread();
1898
+ const thread = this.store.getCurrentThread();
1899
+ if (isNil(thread)) {
1900
+ return null;
1901
+ }
1902
+ return toRaw(thread);
1896
1903
  }
1897
1904
  async setCurrentThread(threadId) {
1898
1905
  this.store.setCurrentThread(threadId);