Skip to content

Commit ee29110

Browse files
nvidiaclaude
authored andcommitted
Fix ain-js ESM/CJS interop and lesson tag deduplication
- ain-client.ts: use `.default ?? module` pattern for ain-js import to handle Node ESM wrapping CJS default exports as { default: Ain } - record-lesson.js: resolve ain-js from cogito/node_modules using require.resolve paths, and deduplicate lesson_learned tag Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dd93c74 commit ee29110

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

.claude/skills/lesson/scripts/record-lesson.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ async function recordViaApi(lesson) {
4444
async function recordViaAinJs(lesson) {
4545
// Try to use ain-js directly if available
4646
try {
47-
const AinModule = await import('@ainblockchain/ain-js');
47+
const path = require('path');
48+
// Resolve ain-js from the cogito directory where it's installed
49+
const cogitoDir = path.resolve(__dirname, '..', '..', '..', '..', 'cogito');
50+
const ainJsPath = require.resolve('@ainblockchain/ain-js', { paths: [cogitoDir] });
51+
const AinModule = require(ainJsPath);
4852
const Ain = AinModule.default || AinModule;
4953

5054
const providerUrl = process.env.AIN_PROVIDER_URL || 'https://devnet-api.ainetwork.ai';
@@ -74,7 +78,7 @@ async function recordViaAinJs(lesson) {
7478
content: lesson.content,
7579
summary: lesson.summary || lesson.content.slice(0, 200),
7680
depth: 2,
77-
tags: ['lesson_learned', ...tags].join(','),
81+
tags: [...new Set(['lesson_learned', ...tags])].join(','),
7882
});
7983

8084
return { success: true, entryId: result.entryId, method: 'ain-js' };

cogito/src/ain-client.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66
import AinModule from '@ainblockchain/ain-js';
77
import { EnrichedContent } from './types.js';
88

9-
// ain-js uses `export default class Ain` from CommonJS
10-
const Ain = AinModule as unknown as typeof AinModule.default extends undefined
11-
? typeof AinModule
12-
: typeof AinModule.default;
13-
14-
type AinInstance = InstanceType<typeof Ain>;
9+
// ESM/CJS interop: ain-js is CJS with `module.exports = class Ain`.
10+
// In Node ESM, the default import is `{ default: Ain }`, not Ain directly.
11+
const Ain: any = (AinModule as any).default ?? AinModule;
1512

1613
export class AinClient {
17-
private ain: AinInstance;
14+
private ain: any;
1815
private address: string = '';
1916

2017
constructor(
2118
private providerUrl: string,
2219
private privateKey: string,
2320
) {
24-
this.ain = new (Ain as any)(providerUrl);
21+
this.ain = new Ain(providerUrl);
2522
}
2623

2724
async init(): Promise<void> {

0 commit comments

Comments
 (0)