@hashgraphonline/conversational-agent 0.2.107 → 0.2.110

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.
Files changed (52) hide show
  1. package/README.md +64 -27
  2. package/dist/cjs/config/system-message.d.ts +1 -1
  3. package/dist/cjs/conversational-agent.d.ts +16 -0
  4. package/dist/cjs/core/tool-registry.d.ts +26 -0
  5. package/dist/cjs/index.cjs +1 -1
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/mcp/types.d.ts +1 -1
  8. package/dist/cjs/services/attachment-processor.d.ts +1 -2
  9. package/dist/cjs/services/content-store-manager.d.ts +1 -1
  10. package/dist/cjs/services/formatters/types.d.ts +3 -1
  11. package/dist/cjs/services/index.d.ts +1 -1
  12. package/dist/esm/index15.js +2 -2
  13. package/dist/esm/index15.js.map +1 -1
  14. package/dist/esm/index2.js +33 -39
  15. package/dist/esm/index2.js.map +1 -1
  16. package/dist/esm/index21.js.map +1 -1
  17. package/dist/esm/index23.js +2 -2
  18. package/dist/esm/index24.js.map +1 -1
  19. package/dist/esm/index26.js.map +1 -1
  20. package/dist/esm/index30.js.map +1 -1
  21. package/dist/esm/index4.js +1 -1
  22. package/dist/esm/index4.js.map +1 -1
  23. package/dist/esm/index40.js +2 -2
  24. package/dist/esm/index40.js.map +1 -1
  25. package/dist/esm/index43.js +52 -1
  26. package/dist/esm/index43.js.map +1 -1
  27. package/dist/esm/index47.js +1 -1
  28. package/dist/esm/index47.js.map +1 -1
  29. package/dist/esm/index6.js +75 -17
  30. package/dist/esm/index6.js.map +1 -1
  31. package/dist/types/config/system-message.d.ts +1 -1
  32. package/dist/types/conversational-agent.d.ts +16 -0
  33. package/dist/types/core/tool-registry.d.ts +26 -0
  34. package/dist/types/mcp/types.d.ts +1 -1
  35. package/dist/types/services/attachment-processor.d.ts +1 -2
  36. package/dist/types/services/content-store-manager.d.ts +1 -1
  37. package/dist/types/services/formatters/types.d.ts +3 -1
  38. package/dist/types/services/index.d.ts +1 -1
  39. package/package.json +12 -10
  40. package/src/config/system-message.ts +3 -3
  41. package/src/conversational-agent.ts +164 -56
  42. package/src/core/tool-registry.ts +61 -0
  43. package/src/mcp/mcp-client-manager.ts +2 -2
  44. package/src/mcp/types.ts +1 -1
  45. package/src/memory/content-storage.ts +19 -6
  46. package/src/plugins/hbar/AccountBuilder.ts +1 -1
  47. package/src/plugins/hcs-10/HCS10Plugin.ts +50 -52
  48. package/src/plugins/inscribe/InscribePlugin.ts +1 -1
  49. package/src/services/attachment-processor.ts +1 -1
  50. package/src/services/content-store-manager.ts +1 -1
  51. package/src/services/formatters/types.ts +3 -1
  52. package/src/services/index.ts +1 -1
@@ -19,33 +19,15 @@ import {
19
19
  AcceptConnectionRequestTool,
20
20
  RetrieveProfileTool,
21
21
  ListUnapprovedConnectionRequestsTool,
22
+ RegisteredAgent,
22
23
  } from '@hashgraphonline/standards-agent-kit';
23
24
  import { HCS10Client } from '@hashgraphonline/standards-sdk';
25
+ import { PrivateKey } from 'node_modules/@hashgraph/sdk/lib/Mnemonic';
24
26
 
25
27
  interface HCS10ClientManager {
26
28
  initializeConnectionsManager(client: HCS10Client): void;
27
29
  }
28
30
 
29
- /**
30
- * Extracts private key string from operator key
31
- */
32
- function extractPrivateKey(opKey: unknown): string {
33
- const key = opKey as {
34
- toString?: () => string;
35
- toStringRaw?: () => string;
36
- };
37
-
38
- if (typeof key?.toStringRaw === 'function') {
39
- return key.toStringRaw();
40
- }
41
-
42
- if (typeof key?.toString === 'function') {
43
- return key.toString();
44
- }
45
-
46
- return String(key);
47
- }
48
-
49
31
  function hasInitializeConnectionsManager(
50
32
  stateManager: IStateManager
51
33
  ): stateManager is IStateManager & HCS10ClientManager {
@@ -89,30 +71,40 @@ export class HCS10Plugin extends BasePlugin {
89
71
  new OpenConvaiState();
90
72
 
91
73
  const accountId = hederaKit.signer.getAccountId().toString();
92
- const isBytesMode = String(hederaKit.operationalMode || 'returnBytes') === 'returnBytes';
74
+ const isBytesMode =
75
+ String(hederaKit.operationalMode || 'returnBytes') === 'returnBytes';
93
76
  let inboundTopicId = '';
94
77
  let outboundTopicId = '';
95
78
 
96
- if (!isBytesMode) {
97
- try {
98
- const opKey = hederaKit.signer.getOperatorPrivateKey();
99
- const privateKey = extractPrivateKey(opKey);
100
-
101
- const hcs10Client = new HCS10Client({
102
- network: hederaKit.network as 'mainnet' | 'testnet',
103
- operatorId: accountId,
104
- operatorPrivateKey: privateKey,
105
- logLevel: 'error',
106
- });
107
-
108
- const profileResponse = await hcs10Client.retrieveProfile(accountId);
109
- if (profileResponse.success && profileResponse.topicInfo) {
110
- inboundTopicId = profileResponse.topicInfo.inboundTopic;
111
- outboundTopicId = profileResponse.topicInfo.outboundTopic;
112
- }
113
- } catch (profileError) {
114
- this.context.logger.warn('Skipping profile topic discovery', profileError);
79
+ let operatorPrivateKeyRef: PrivateKey =
80
+ hederaKit.signer.getOperatorPrivateKey();
81
+ let operatorPrivateKeySerialized: string | undefined;
82
+
83
+ try {
84
+ const resolved =
85
+ typeof operatorPrivateKeyRef?.toString === 'function'
86
+ ? operatorPrivateKeyRef.toString()
87
+ : '';
88
+
89
+ operatorPrivateKeySerialized = resolved;
90
+
91
+ const hcs10Client = new HCS10Client({
92
+ network: hederaKit.network as 'mainnet' | 'testnet',
93
+ operatorId: accountId,
94
+ operatorPrivateKey: operatorPrivateKeyRef,
95
+ logLevel: 'error',
96
+ });
97
+
98
+ const profileResponse = await hcs10Client.retrieveProfile(accountId);
99
+ if (profileResponse.success && profileResponse.topicInfo) {
100
+ inboundTopicId = profileResponse.topicInfo.inboundTopic;
101
+ outboundTopicId = profileResponse.topicInfo.outboundTopic;
115
102
  }
103
+ } catch (profileError) {
104
+ this.context.logger.warn(
105
+ 'Skipping profile topic discovery',
106
+ profileError
107
+ );
116
108
  }
117
109
 
118
110
  const agentRecord: Record<string, unknown> = {
@@ -121,39 +113,45 @@ export class HCS10Plugin extends BasePlugin {
121
113
  inboundTopicId,
122
114
  outboundTopicId,
123
115
  };
124
- if (!isBytesMode) {
125
- try {
126
- const opKey = hederaKit.signer.getOperatorPrivateKey();
127
- agentRecord.privateKey = extractPrivateKey(opKey);
128
- } catch {}
116
+ if (!isBytesMode && operatorPrivateKeySerialized) {
117
+ agentRecord.privateKey = operatorPrivateKeySerialized;
129
118
  }
130
- this.stateManager.setCurrentAgent(agentRecord as any);
119
+ this.stateManager.setCurrentAgent(
120
+ agentRecord as unknown as RegisteredAgent
121
+ );
131
122
 
132
123
  this.context.logger.info(
133
124
  `Set current agent: ${accountId} with topics ${inboundTopicId}/${outboundTopicId}`
134
125
  );
135
126
 
136
- if (!isBytesMode && this.stateManager && !this.stateManager.getConnectionsManager()) {
127
+ if (
128
+ !isBytesMode &&
129
+ this.stateManager &&
130
+ !this.stateManager.getConnectionsManager()
131
+ ) {
137
132
  try {
138
- const opKey = hederaKit.signer.getOperatorPrivateKey();
139
- const privateKey = extractPrivateKey(opKey);
140
133
  const hcs10Client = new HCS10Client({
141
134
  network: hederaKit.network as 'mainnet' | 'testnet',
142
135
  operatorId: accountId,
143
- operatorPrivateKey: privateKey,
136
+ operatorPrivateKey: operatorPrivateKeyRef ?? '',
144
137
  logLevel: 'error',
145
138
  });
146
139
 
147
140
  if (hasInitializeConnectionsManager(this.stateManager)) {
148
141
  this.stateManager.initializeConnectionsManager(hcs10Client);
149
142
  } else {
150
- this.context.logger.warn('StateManager does not support connection manager initialization');
143
+ this.context.logger.warn(
144
+ 'StateManager does not support connection manager initialization'
145
+ );
151
146
  }
152
147
  this.context.logger.info(
153
148
  'ConnectionsManager initialized in HCS10Plugin'
154
149
  );
155
150
  } catch (cmError) {
156
- this.context.logger.warn('Could not initialize ConnectionsManager:', cmError);
151
+ this.context.logger.warn(
152
+ 'Could not initialize ConnectionsManager:',
153
+ cmError
154
+ );
157
155
  }
158
156
  }
159
157
 
@@ -71,7 +71,7 @@ export class InscribePlugin extends BasePlugin {
71
71
  }),
72
72
  };
73
73
  this.providerId = fieldGuidanceRegistry.registerToolProvider(
74
- /inscribe.*hashinal/i,
74
+ /hashinal/i,
75
75
  provider,
76
76
  { id: 'inscribe:hashinal:provider', priority: 1 }
77
77
  );
@@ -8,7 +8,7 @@ export interface AttachmentData {
8
8
  size: number;
9
9
  }
10
10
 
11
- type ContentStoreManager = PackageContentStoreManager;
11
+ export type ContentStoreManager = PackageContentStoreManager;
12
12
 
13
13
  /**
14
14
  * Utility for processing file attachments and content references
@@ -138,7 +138,7 @@ export class ContentStoreManager {
138
138
  private adapter: ContentStorageAdapter;
139
139
  private resolver: ContentResolver;
140
140
  private logger: Logger;
141
- private isRegistered = false;
141
+ protected isRegistered = false;
142
142
 
143
143
  constructor(
144
144
  maxMessageStorage: number = 1000,
@@ -1,3 +1,5 @@
1
+ import { NetworkType } from '@hashgraphonline/standards-sdk';
2
+
1
3
  export enum EntityFormat {
2
4
  TOPIC_ID = 'topicId',
3
5
  HRL = 'hrl',
@@ -16,7 +18,7 @@ export enum EntityFormat {
16
18
  }
17
19
 
18
20
  export interface ConversionContext {
19
- networkType?: string;
21
+ networkType?: NetworkType;
20
22
  sessionId?: string;
21
23
  toolName?: string;
22
24
  toolPreferences?: Record<string, string>;
@@ -2,4 +2,4 @@ export * from './entity-resolver';
2
2
  export * from './content-store-manager';
3
3
  export * from './formatters';
4
4
  export * from './parameter-service';
5
- export * from './attachment-processor';
5
+ export { AttachmentProcessor, type AttachmentData } from './attachment-processor';