@hashgraphonline/conversational-agent 0.2.106 → 0.2.107

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.
@@ -16,7 +16,7 @@ import { HCS10Plugin } from './plugins/hcs-10/HCS10Plugin';
16
16
  import { HCS2Plugin } from './plugins/hcs-2/HCS2Plugin';
17
17
  import { InscribePlugin } from './plugins/inscribe/InscribePlugin';
18
18
  import { getWalletBridgeProvider } from './runtime/wallet-bridge';
19
- import { InscriberBuilder } from '@hashgraphonline/standards-agent-kit';
19
+ import { InscriberBuilder, SignerProviderRegistry } from '@hashgraphonline/standards-agent-kit';
20
20
  import { HbarPlugin } from './plugins/hbar/HbarPlugin';
21
21
  import { OpenConvaiState } from '@hashgraphonline/standards-agent-kit';
22
22
  import type { IStateManager } from '@hashgraphonline/standards-agent-kit';
@@ -225,7 +225,6 @@ export class ConversationalAgent {
225
225
  const bytesMode = opMode !== 'autonomous';
226
226
  let signer: AbstractSigner;
227
227
 
228
- // Enforce wallet-only execution in Provide Bytes mode (no server fallback)
229
228
  try {
230
229
  type InscriberBuilderAug = typeof InscriberBuilder & {
231
230
  setPreferWalletOnly?: (prefer: boolean) => void;
@@ -233,9 +232,27 @@ export class ConversationalAgent {
233
232
  setWalletExecutor?: (fn: (base64: string, network: 'mainnet' | 'testnet') => Promise<{ transactionId: string }>) => void;
234
233
  setStartInscriptionDelegate?: (fn: (request: Record<string, unknown>, network: 'mainnet' | 'testnet') => Promise<unknown>) => void;
235
234
  };
236
- const IB = InscriberBuilder as InscriberBuilderAug;
235
+ type InscriberBuilderAug3 = typeof InscriberBuilder & {
236
+ setPreferWalletOnly?: (prefer: boolean) => void;
237
+ setWalletInfoResolver?: (
238
+ fn: () => Promise<{ accountId: string; network: string } | null>
239
+ ) => void;
240
+ setWalletExecutor?: (
241
+ fn: (
242
+ base64: string,
243
+ network: 'mainnet' | 'testnet'
244
+ ) => Promise<{ transactionId: string }>
245
+ ) => void;
246
+ setStartInscriptionDelegate?: (
247
+ fn: (
248
+ request: Record<string, unknown>,
249
+ network: 'mainnet' | 'testnet'
250
+ ) => Promise<unknown>
251
+ ) => void;
252
+ };
253
+ const IB = InscriberBuilder as InscriberBuilderAug3;
237
254
  if (typeof IB.setPreferWalletOnly === 'function') {
238
- IB.setPreferWalletOnly(bytesMode);
255
+ IB.setPreferWalletOnly(false);
239
256
  }
240
257
  } catch (e) {
241
258
  this.logger.warn('Failed to set wallet-only preference', e as Error);
@@ -254,11 +271,9 @@ export class ConversationalAgent {
254
271
  signerClass: Object.getPrototypeOf(signer)?.constructor?.name || 'unknown',
255
272
  });
256
273
 
257
- // Register wallet bridge providers for standards-agent-kit builders (wallet-first, DRY)
258
274
  try {
259
275
  const bridge = getWalletBridgeProvider();
260
276
  if (bridge) {
261
- // Provide wallet status and execution for builders that support delegates
262
277
  type InscriberBuilderAug2 = typeof InscriberBuilder & {
263
278
  setWalletInfoResolver?: (fn: () => Promise<{ accountId: string; network: string } | null>) => void;
264
279
  setWalletExecutor?: (fn: (base64: string, network: 'mainnet' | 'testnet') => Promise<{ transactionId: string }>) => void;
@@ -285,28 +300,66 @@ export class ConversationalAgent {
285
300
  });
286
301
  }
287
302
 
288
- // Also wire wallet info/executor into the SAK SignerProviderRegistry for HCS builders (if available)
289
303
  try {
290
- const sak = await import('@hashgraphonline/standards-agent-kit');
291
- const reg: any = (sak as any)?.SignerProviderRegistry;
292
- if (reg) {
293
- reg.setWalletInfoResolver(async () => {
294
- const status = await bridge.status();
295
- if (status.connected && status.accountId && status.network) {
296
- return { accountId: status.accountId, network: status.network as 'mainnet' | 'testnet' };
297
- }
298
- return null;
299
- });
300
- reg.setWalletExecutor(async (base64: string, network: 'mainnet' | 'testnet') => {
301
- return await bridge.executeBytes(base64, network);
302
- });
303
- if (typeof (bridge as any).startHCS === 'function') {
304
- reg.setStartHCSDelegate(async (op: any, request: Record<string, unknown>, network: 'mainnet' | 'testnet') => {
305
- return await (bridge as any).startHCS(op, request, network);
306
- });
304
+ type HCSOp =
305
+ | 'submitConnectionRequest'
306
+ | 'handleConnectionRequest'
307
+ | 'sendMessage'
308
+ | 'hcs2.createRegistry'
309
+ | 'hcs2.migrateRegistry'
310
+ | 'hcs2.registerEntry'
311
+ | 'hcs2.updateEntry'
312
+ | 'hcs2.deleteEntry'
313
+ | 'hcs2.submitMessage'
314
+ | 'hcs6.createRegistry'
315
+ | 'hcs6.registerEntry'
316
+ | 'hcs6.submitMessage';
317
+ type WalletBridgeProviderExt = ReturnType<typeof getWalletBridgeProvider> & {
318
+ startHCS?: (
319
+ op: HCSOp,
320
+ request: Record<string, unknown>,
321
+ network: 'mainnet' | 'testnet'
322
+ ) => Promise<{ transactionBytes: string }>
323
+ };
324
+
325
+ const status = await bridge.status();
326
+ const enforceWallet = !!(bytesMode && status.connected);
327
+
328
+ SignerProviderRegistry.setWalletInfoResolver(async () => {
329
+ const s = await bridge.status();
330
+ if (s.connected && s.accountId && s.network) {
331
+ return {
332
+ accountId: s.accountId,
333
+ network: s.network as 'mainnet' | 'testnet',
334
+ };
307
335
  }
308
- // In bytes modes, always require wallet execution (no server fallback)
309
- reg.setPreferWalletOnly(!!bytesMode);
336
+ return null;
337
+ });
338
+
339
+ SignerProviderRegistry.setWalletExecutor(async (
340
+ base64: string,
341
+ network: 'mainnet' | 'testnet'
342
+ ) => {
343
+ return await bridge.executeBytes(base64, network);
344
+ });
345
+
346
+ const extended = bridge as WalletBridgeProviderExt;
347
+ if (typeof extended?.startHCS === 'function') {
348
+ SignerProviderRegistry.setStartHCSDelegate(async (op, request, network) => {
349
+ return await extended.startHCS!(op as HCSOp, request, network);
350
+ });
351
+ } else {
352
+ SignerProviderRegistry.setStartHCSDelegate(null);
353
+ }
354
+
355
+ SignerProviderRegistry.setPreferWalletOnly(enforceWallet);
356
+
357
+ type InscriberBuilderAug3 = typeof InscriberBuilder & {
358
+ setPreferWalletOnly?: (prefer: boolean) => void;
359
+ };
360
+ const IB2 = InscriberBuilder as InscriberBuilderAug3;
361
+ if (typeof IB2.setPreferWalletOnly === 'function') {
362
+ IB2.setPreferWalletOnly(enforceWallet);
310
363
  }
311
364
  } catch (sakWireErr) {
312
365
  this.logger.warn('Failed to wire SAK SignerProviderRegistry wallet delegates', sakWireErr as Error);
@@ -201,7 +201,6 @@ export class ToolRegistry {
201
201
 
202
202
  this.tools.set(tool.name, entry);
203
203
 
204
- // Forward optional field guidance metadata/provider to registry
205
204
  try {
206
205
  const metaFG = metadata.fieldGuidance as FG_ToolFieldConfiguration | undefined;
207
206
  if (metaFG) {
@@ -185,7 +185,6 @@ class FieldGuidanceRegistry {
185
185
  return merged;
186
186
  }
187
187
  }
188
- // No static guidance matched; try provider-only (apply from highest to lowest)
189
188
  const providers = this.pickMatchingProviders(toolName);
190
189
  if (providers.length > 0) {
191
190
  let merged: FieldGuidance = {};
@@ -234,7 +233,6 @@ class FieldGuidanceRegistry {
234
233
  return result;
235
234
  }
236
235
  }
237
- // No static matched → provider-only
238
236
  const providers = this.pickMatchingProviders(toolName);
239
237
  if (providers.length > 0) {
240
238
  let mergedWarnings: string[] | undefined;
@@ -702,7 +702,6 @@ export class SmartMemoryManager {
702
702
  }
703
703
  }
704
704
 
705
- // Merge duplicates by entityId, preferring the newest and one that carries transactionId
706
705
  const mergedById = new Map<string, EntityAssociation>();
707
706
  const getTime = (d: Date | string): number =>
708
707
  d instanceof Date ? d.getTime() : new Date(d).getTime();
@@ -157,8 +157,6 @@ export class HCS10Plugin extends BasePlugin {
157
157
  }
158
158
  }
159
159
 
160
- // Always initialize HCS-10 tools, even in bytes mode. Some operations may execute directly
161
- // when returnBytes/provideBytes is active; that is acceptable and preferred over disabling.
162
160
  this.initializeTools();
163
161
  this.context.logger.info('HCS-10 Plugin initialized successfully');
164
162
  } catch (error) {
@@ -40,8 +40,6 @@ export class HCS2Plugin extends BasePlugin {
40
40
  }
41
41
 
42
42
  try {
43
- // Always initialize HCS-2 tools, even in bytes mode. Some tools may execute directly when
44
- // returnBytes/provideBytes is active, which is acceptable.
45
43
  this.initializeTools();
46
44
 
47
45
  this.context.logger.info(
@@ -43,7 +43,6 @@ export class InscribePlugin extends BasePlugin {
43
43
  try {
44
44
  this.initializeTools();
45
45
 
46
- // Register field guidance provider for inscribe hashinal tools
47
46
  try {
48
47
  const provider = {
49
48
  getFieldGuidance: (fieldName: string): FieldGuidance | null => {
@@ -28,6 +28,11 @@ export interface WalletBridgeProvider {
28
28
  request: Record<string, unknown>,
29
29
  network: WalletNetwork
30
30
  ) => Promise<StartInscriptionResult>;
31
+ startHCS?: (
32
+ op: string,
33
+ request: Record<string, unknown>,
34
+ network: WalletNetwork
35
+ ) => Promise<{ transactionBytes: string }>;
31
36
  }
32
37
 
33
38
  let providerRef: WalletBridgeProvider | null = null;
@@ -102,7 +102,6 @@ export class BrowserSigner extends AbstractSigner {
102
102
  network,
103
103
  new Logger({ module: 'BrowserSigner' })
104
104
  );
105
- // Avoid cross-package PublicKey type incompatibility by reconstructing from string
106
105
  const anyKey: any = await mirror.getPublicKey(this.account.toString());
107
106
  const keyStr = typeof anyKey?.toString === 'function' ? anyKey.toString() : String(anyKey);
108
107
  return PublicKey.fromString(keyStr);