@proteinjs/conversation 2.1.2 → 2.1.4

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 (31) hide show
  1. package/dist/index.d.ts +8 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +8 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/Conversation.d.ts +36 -1
  6. package/dist/src/Conversation.d.ts.map +1 -1
  7. package/dist/src/Conversation.js +163 -5
  8. package/dist/src/Conversation.js.map +1 -1
  9. package/dist/src/OpenAi.d.ts +29 -0
  10. package/dist/src/OpenAi.d.ts.map +1 -1
  11. package/dist/src/OpenAi.js +77 -30
  12. package/dist/src/OpenAi.js.map +1 -1
  13. package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts +1 -0
  14. package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts.map +1 -1
  15. package/dist/src/fs/conversation_fs/ConversationFsModule.js +6 -2
  16. package/dist/src/fs/conversation_fs/ConversationFsModule.js.map +1 -1
  17. package/dist/src/fs/conversation_fs/FsFunctions.d.ts +36 -3
  18. package/dist/src/fs/conversation_fs/FsFunctions.d.ts.map +1 -1
  19. package/dist/src/fs/conversation_fs/FsFunctions.js +142 -20
  20. package/dist/src/fs/conversation_fs/FsFunctions.js.map +1 -1
  21. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts +4 -1
  22. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts.map +1 -1
  23. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +13 -9
  24. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js.map +1 -1
  25. package/index.ts +10 -1
  26. package/package.json +4 -3
  27. package/src/Conversation.ts +213 -5
  28. package/src/OpenAi.ts +123 -13
  29. package/src/fs/conversation_fs/ConversationFsModule.ts +8 -2
  30. package/src/fs/conversation_fs/FsFunctions.ts +97 -17
  31. package/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts +14 -9
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,9 +46,76 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
47
  }
37
48
  };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
38
52
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.fsFunctions = exports.moveFunctionName = exports.copyFunctionName = exports.renameFunctionName = exports.getFilePathsMatchingGlobFunctionName = exports.fileOrDirectoryExistsFunction = exports.fileOrDirectoryExistsFunctionName = exports.getRecentlyAccessedFilePathsFunction = exports.getRecentlyAccessedFilePathsFunctionName = exports.writeFilesFunction = exports.writeFilesFunctionName = exports.readFilesFunction = exports.readFilesFunctionName = void 0;
53
+ exports.fsFunctions = exports.grepFunction = exports.grepFunctionName = exports.moveFunctionName = exports.copyFunctionName = exports.renameFunctionName = exports.getFilePathsMatchingGlobFunctionName = exports.fileOrDirectoryExistsFunction = exports.fileOrDirectoryExistsFunctionName = exports.getRecentlyAccessedFilePathsFunction = exports.getRecentlyAccessedFilePathsFunctionName = exports.writeFilesFunction = exports.writeFilesFunctionName = exports.readFilesFunction = exports.readFilesFunctionName = void 0;
40
54
  var util_node_1 = require("@proteinjs/util-node");
55
+ var path_1 = __importDefault(require("path"));
56
+ var toRepoAbs = function (mod, p) { return (path_1.default.isAbsolute(p) ? p : path_1.default.join(mod.getRepoPath(), p)); };
57
+ // If path doesn’t exist, try to resolve "<repo>/<basename>" to the actual file under repo
58
+ function canonicalizePaths(mod, paths) {
59
+ return __awaiter(this, void 0, void 0, function () {
60
+ var repo, ignore, out, _i, paths_1, p, abs, base, parsed, pattern, matches, _a;
61
+ return __generator(this, function (_b) {
62
+ switch (_b.label) {
63
+ case 0:
64
+ repo = mod.getRepoPath();
65
+ ignore = ['**/node_modules/**', '**/dist/**', '**/.git/**'];
66
+ out = [];
67
+ _i = 0, paths_1 = paths;
68
+ _b.label = 1;
69
+ case 1:
70
+ if (!(_i < paths_1.length)) return [3 /*break*/, 8];
71
+ p = paths_1[_i];
72
+ abs = toRepoAbs(mod, p);
73
+ return [4 /*yield*/, util_node_1.Fs.exists(abs)];
74
+ case 2:
75
+ if (_b.sent()) {
76
+ out.push(abs);
77
+ return [3 /*break*/, 7];
78
+ }
79
+ base = path_1.default.basename(p);
80
+ if (!base) {
81
+ out.push(abs);
82
+ return [3 /*break*/, 7];
83
+ }
84
+ parsed = path_1.default.parse(base);
85
+ pattern = parsed.ext ? "**/".concat(parsed.name).concat(parsed.ext) : "**/".concat(parsed.name, ".*");
86
+ matches = [];
87
+ _b.label = 3;
88
+ case 3:
89
+ _b.trys.push([3, 5, , 6]);
90
+ return [4 /*yield*/, util_node_1.Fs.getFilePathsMatchingGlob(repo, pattern, ignore)];
91
+ case 4:
92
+ matches = _b.sent();
93
+ return [3 /*break*/, 6];
94
+ case 5:
95
+ _a = _b.sent();
96
+ return [3 /*break*/, 6];
97
+ case 6:
98
+ if (matches.length === 1) {
99
+ out.push(matches[0]);
100
+ }
101
+ else if (matches.length > 1) {
102
+ // Prefer the shortest match (usually “src/...” beats deeper/duplicate locations)
103
+ matches.sort(function (a, b) { return a.length - b.length; });
104
+ out.push(matches[0]);
105
+ }
106
+ else {
107
+ // No luck; keep the original absolute (will throw with a clear error)
108
+ out.push(abs);
109
+ }
110
+ _b.label = 7;
111
+ case 7:
112
+ _i++;
113
+ return [3 /*break*/, 1];
114
+ case 8: return [2 /*return*/, out];
115
+ }
116
+ });
117
+ });
118
+ }
41
119
  exports.readFilesFunctionName = 'readFiles';
42
120
  function readFilesFunction(fsModule) {
43
121
  var _this = this;
@@ -51,21 +129,23 @@ function readFilesFunction(fsModule) {
51
129
  filePaths: {
52
130
  type: 'array',
53
131
  description: 'Paths to the files',
54
- items: {
55
- type: 'string',
56
- },
132
+ items: { type: 'string' },
57
133
  },
58
134
  },
59
135
  required: ['filePaths'],
60
136
  },
61
137
  },
62
138
  call: function (params) { return __awaiter(_this, void 0, void 0, function () {
139
+ var absPaths;
63
140
  return __generator(this, function (_a) {
64
141
  switch (_a.label) {
65
142
  case 0:
66
143
  fsModule.pushRecentlyAccessedFilePath(params.filePaths);
67
- return [4 /*yield*/, util_node_1.Fs.readFiles(params.filePaths)];
68
- case 1: return [2 /*return*/, _a.sent()];
144
+ return [4 /*yield*/, canonicalizePaths(fsModule, params.filePaths)];
145
+ case 1:
146
+ absPaths = _a.sent();
147
+ return [4 /*yield*/, util_node_1.Fs.readFiles(absPaths)];
148
+ case 2: return [2 /*return*/, _a.sent()];
69
149
  }
70
150
  });
71
151
  }); },
@@ -85,19 +165,10 @@ function writeFilesFunction(fsModule) {
85
165
  properties: {
86
166
  files: {
87
167
  type: 'array',
88
- description: 'Files to write',
89
168
  items: {
90
169
  type: 'object',
91
- properties: {
92
- path: {
93
- type: 'string',
94
- description: 'the file path',
95
- },
96
- content: {
97
- type: 'string',
98
- description: 'the content to write to the file',
99
- },
100
- },
170
+ properties: { path: { type: 'string' }, content: { type: 'string' } },
171
+ required: ['path', 'content'],
101
172
  },
102
173
  },
103
174
  },
@@ -105,12 +176,17 @@ function writeFilesFunction(fsModule) {
105
176
  },
106
177
  },
107
178
  call: function (params) { return __awaiter(_this, void 0, void 0, function () {
179
+ var canon, absFiles;
108
180
  return __generator(this, function (_a) {
109
181
  switch (_a.label) {
110
182
  case 0:
111
- fsModule.pushRecentlyAccessedFilePath(params.files.map(function (file) { return file.path; }));
112
- return [4 /*yield*/, util_node_1.Fs.writeFiles(params.files)];
113
- case 1: return [2 /*return*/, _a.sent()];
183
+ fsModule.pushRecentlyAccessedFilePath(params.files.map(function (f) { return f.path; }));
184
+ return [4 /*yield*/, canonicalizePaths(fsModule, params.files.map(function (f) { return f.path; }))];
185
+ case 1:
186
+ canon = _a.sent();
187
+ absFiles = params.files.map(function (f, i) { return (__assign(__assign({}, f), { path: canon[i] })); });
188
+ return [4 /*yield*/, util_node_1.Fs.writeFiles(absFiles)];
189
+ case 2: return [2 /*return*/, _a.sent()];
114
190
  }
115
191
  });
116
192
  }); },
@@ -306,6 +382,52 @@ var moveFunction = {
306
382
  }); }); },
307
383
  instructions: ["To move a file or directory, use the ".concat(exports.moveFunctionName, " function")],
308
384
  };
385
+ exports.grepFunctionName = 'grep';
386
+ function grepFunction(fsModule) {
387
+ var _this = this;
388
+ return {
389
+ definition: {
390
+ name: exports.grepFunctionName,
391
+ description: "Run system grep recursively (-F literal) within the repository and return raw stdout/stderr/code. Excludes node_modules, dist, and .git. Use 'maxResults' to cap output.",
392
+ parameters: {
393
+ type: 'object',
394
+ properties: {
395
+ pattern: {
396
+ type: 'string',
397
+ description: 'Literal text to search for (grep -F). For parentheses or special characters, pass them as-is; no regex needed.',
398
+ },
399
+ dir: {
400
+ type: 'string',
401
+ description: 'Directory to search under. If relative, it is resolved against the repo root. Defaults to the repo root.',
402
+ },
403
+ maxResults: {
404
+ type: 'number',
405
+ description: 'Maximum number of matching lines to return (uses grep -m N).',
406
+ },
407
+ },
408
+ required: ['pattern'],
409
+ },
410
+ },
411
+ call: function (params) { return __awaiter(_this, void 0, void 0, function () {
412
+ var repo, cwd;
413
+ return __generator(this, function (_a) {
414
+ switch (_a.label) {
415
+ case 0:
416
+ repo = fsModule.getRepoPath();
417
+ cwd = params.dir ? toRepoAbs(fsModule, params.dir) : repo;
418
+ return [4 /*yield*/, util_node_1.Fs.grep({ pattern: params.pattern, dir: cwd, maxResults: params.maxResults })];
419
+ case 1: return [2 /*return*/, _a.sent()];
420
+ }
421
+ });
422
+ }); },
423
+ instructions: [
424
+ "Use ".concat(exports.grepFunctionName, " to search for literal text across the repo."),
425
+ "Prefer small 'maxResults' (e.g., 5-20) to avoid flooding the context.",
426
+ "Parse the returned stdout yourself (format: \"<path>:<line>:<text>\") to pick files to read.",
427
+ ],
428
+ };
429
+ }
430
+ exports.grepFunction = grepFunction;
309
431
  exports.fsFunctions = [
310
432
  createFolderFunction,
311
433
  exports.fileOrDirectoryExistsFunction,
@@ -1 +1 @@
1
- {"version":3,"file":"FsFunctions.js","sourceRoot":"","sources":["../../../../src/fs/conversation_fs/FsFunctions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAgD;AAInC,QAAA,qBAAqB,GAAG,WAAW,CAAC;AACjD,SAAgB,iBAAiB,CAAC,QAA8B;IAAhE,iBAyBC;IAxBC,OAAO;QACL,UAAU,EAAE;YACV,IAAI,EAAE,6BAAqB;YAC3B,WAAW,EAAE,0BAA0B;YACvC,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,SAAS,EAAE;wBACT,IAAI,EAAE,OAAO;wBACb,WAAW,EAAE,oBAAoB;wBACjC,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;yBACf;qBACF;iBACF;gBACD,QAAQ,EAAE,CAAC,WAAW,CAAC;aACxB;SACF;QACD,IAAI,EAAE,UAAO,MAA+B;;;;wBAC1C,QAAQ,CAAC,4BAA4B,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;wBACjD,qBAAM,cAAE,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,EAAA;4BAA3C,sBAAO,SAAoC,EAAC;;;aAC7C;QACD,YAAY,EAAE,CAAC,4DAAqD,6BAAqB,cA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uleParams = {
4
4
  dir: string;
5
5
  keywordFilesIndex: {
6
- [keyword: string]: string[]; /** file paths */
6
+ [keyword: string]: string[];
7
7
  };
8
8
  };
9
9
  export declare class KeywordToFilesIndexModule implements ConversationModule {
@@ -11,6 +11,9 @@ export declare class KeywordToFilesIndexModule implements ConversationModule {
11
11
  params: KeywordToFilesIndexModuleParams;
12
12
  constructor(params: KeywordToFilesIndexModuleParams);
13
13
  getName(): string;
14
+ /**
15
+ * Case-insensitive file name search that ignores extension.
16
+ */
14
17
  searchFiles(params: {
15
18
  keyword: string;
16
19
  }): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"KeywordToFilesIndexModule.d.ts","sourceRoot":"","sources":["../../../../src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C,MAAM,MAAM,+BAA+B,GAAG;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA,CAAC,iBAAiB;KAAE,CAAC;CACtE,CAAC;AAEF,qBAAa,yBAA0B,YAAW,kBAAkB;IAClE,OAAO,CAAC,MAAM,CAA+C;IAC7D,MAAM,EAAE,+BAA+B,CAAC;gBAE5B,MAAM,EAAE,+BAA+B;IAInD,OAAO,IAAI,MAAM;IAIjB,WAAW,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;IAMvC,iBAAiB,IAAI,MAAM,EAAE;IAM7B,YAAY,IAAI,QAAQ,EAAE;IAI1B,oBAAoB;CAGrB;AAED,qBAAa,gCAAiC,YAAW,yBAAyB;IAChF,OAAO,CAAC,MAAM,CAA+C;IAEvD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAA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14 +61,18 @@ var KeywordToFilesIndexModule = /** @class */ (function () {
61
61
  KeywordToFilesIndexModule.prototype.getName = function () {
62
62
  return 'Keyword to files index';
63
63
  };
64
+ /**
65
+ * Case-insensitive file name search that ignores extension.
66
+ */
64
67
  KeywordToFilesIndexModule.prototype.searchFiles = function (params) {
65
- this.logger.info({ message: "Searching for file, keyword: ".concat(params.keyword) });
66
- var filePaths = this.params.keywordFilesIndex[params.keyword];
68
+ this.logger.debug({ message: "Searching for file, keyword: ".concat(params.keyword) });
69
+ var keywordLowerNoExtension = path_1.default.parse(params.keyword).name.toLowerCase();
70
+ var filePaths = this.params.keywordFilesIndex[keywordLowerNoExtension];
67
71
  return filePaths || [];
68
72
  };
69
73
  KeywordToFilesIndexModule.prototype.getSystemMessages = function () {
70
74
  return [
71
- "If you're searching for something, use the ".concat(KeywordToFilesIndexFunctions_1.searchFilesFunctionName, " function to find a file matching the search string"),
75
+ "If you're searching for something, use the ".concat(KeywordToFilesIndexFunctions_1.searchFilesFunctionName, " function to find a file (by name) matching the search string"),
72
76
  ];
73
77
  };
74
78
  KeywordToFilesIndexModule.prototype.getFunctions = function () {
@@ -111,7 +115,7 @@ var KeywordToFilesIndexModuleFactory = /** @class */ (function () {
111
115
  KeywordToFilesIndexModuleFactory.prototype.createKeywordFilesIndex = function (baseDir, globIgnorePatterns) {
112
116
  if (globIgnorePatterns === void 0) { globIgnorePatterns = []; }
113
117
  return __awaiter(this, void 0, void 0, function () {
114
- var filePaths, keywordFilesIndex, _i, filePaths_1, filePath, fileName;
118
+ var filePaths, keywordFilesIndex, _i, filePaths_1, filePath, fileNameLower;
115
119
  return __generator(this, function (_a) {
116
120
  switch (_a.label) {
117
121
  case 0:
@@ -126,12 +130,12 @@ var KeywordToFilesIndexModuleFactory = /** @class */ (function () {
126
130
  // Process each file path
127
131
  for (_i = 0, filePaths_1 = filePaths; _i < filePaths_1.length; _i++) {
128
132
  filePath = filePaths_1[_i];
129
- fileName = path_1.default.parse(filePath).name;
130
- if (!keywordFilesIndex[fileName]) {
131
- keywordFilesIndex[fileName] = [];
133
+ fileNameLower = path_1.default.parse(filePath).name.toLowerCase();
134
+ if (!keywordFilesIndex[fileNameLower]) {
135
+ keywordFilesIndex[fileNameLower] = [];
132
136
  }
133
- this.logger.debug({ message: "fileName: ".concat(fileName, ", filePath: ").concat(filePath) });
134
- keywordFilesIndex[fileName].push(filePath);
137
+ this.logger.debug({ message: "fileName: ".concat(fileNameLower, ", filePath: ").concat(filePath) });
138
+ keywordFilesIndex[fileNameLower].push(filePath);
135
139
  }
136
140
  return [2 /*return*/, keywordFilesIndex];
137
141
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KeywordToFilesIndexModule.js","sourceRoot":"","sources":["../../../../src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAC3C,kDAA0C;AAG1C,8CAAwB;AACxB,+EAA8F;AAO9F;IAIE,mCAAY,MAAuC;QAH3C,WAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QAI3D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,2CAAO,GAAP;QACE,OAAO,wBAAwB,CAAC;IAClC,CAAC;IAED,+CAAW,GAAX,UAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,uCAAgC,MAAM,CAAC,OAAO,CAAE,EAAE,CAAC,CAAC;QAChF,IAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAChE,OAAO,SAAS,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,qDAAiB,GAAjB;QACE,OAAO;YACL,qDAA8C,sDAAuB,wDAAqD;SAC3H,CAAC;IACJ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D;IAED;;;;;OAKG;IACG,kEAAuB,GAA7B,UACE,OAAe,EACf,kBAAiC;QAAjC,mCAAA,EAAA,uBAAiC;;;;;;wBAEjC,iDAAiD;wBACjD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAI,CAAC,GAAG,CAAC,EAAE;4BAC/B,OAAO,IAAI,cAAI,CAAC,GAAG,CAAC;yBACrB;wBAGiB,qBAAM,cAAE,CAAC,YAAY,CAAC,OAAO,iBAAG,oBAAoB,EAAE,YAAY,GAAK,kBAAkB,QAAE,EAAA;;wBAAvG,SAAS,GAAG,SAA2F;wBAEvG,iBAAiB,GAAoC,EAAE,CAAC;wBAE9D,yBAAyB;wBACzB,WAAgC,EAAT,uBAAS,EAAT,uBAAS,EAAT,IAAS,EAAE;4BAAvB,QAAQ;4BACX,aAAa,GAAG,cAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;4BAE9D,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE;gCACrC,iBAAiB,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC;6BACvC;4BAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,oBAAa,aAAa,yBAAe,QAAQ,CAAE,EAAE,CAAC,CAAC;4BACpF,iBAAiB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;yBACjD;wBAED,sBAAO,iBAAiB,EAAC;;;;KAC1B;IACH,uCAAC;AAAD,CAAC,AA7CD,IA6CC;AA7CY,4EAAgC"}
package/index.ts CHANGED
@@ -11,4 +11,13 @@ export * from './src/history/MessageModerator';
11
11
  export * from './src/history/MessageHistory';
12
12
  export * from './src/ChatCompletionMessageParamFactory';
13
13
  export { AssistantResponseStreamChunk } from './src/OpenAiStreamProcessor';
14
- export { UsageData } from './src/UsageData';
14
+ export { UsageData, TokenUsage } from './src/UsageData';
15
+
16
+ // Conversation modules
17
+ export * from './src/fs/conversation_fs/ConversationFsModule';
18
+ export * from './src/fs/conversation_fs/FsFunctions';
19
+ export * from './src/fs/git/GitModule';
20
+ export * from './src/fs/keyword_to_files_index/KeywordToFilesIndexModule';
21
+ export * from './src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions';
22
+ export * from './src/fs/package/PackageModule';
23
+ export * from './src/fs/package/PackageFunctions';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/conversation",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {
@@ -28,9 +28,10 @@
28
28
  "ts-jest": "^29.1.1"
29
29
  },
30
30
  "dependencies": {
31
- "@proteinjs/logger": "1.0.9",
31
+ "@proteinjs/logger": "1.0.11",
32
32
  "@proteinjs/util": "1.5.0",
33
- "@proteinjs/util-node": "1.4.2",
33
+ "@proteinjs/util-node": "1.5.0",
34
+ "ai": "5.0.57",
34
35
  "fs-extra": "11.1.1",
35
36
  "openai": "4.85.3",
36
37
  "readline-sync": "1.4.10",
@@ -1,5 +1,5 @@
1
1
  import { ChatCompletionMessageParam } from 'openai/resources/chat';
2
- import { DEFAULT_MODEL, OpenAi } from './OpenAi';
2
+ import { DEFAULT_MODEL, OpenAi, ToolInvocationProgressEvent } from './OpenAi';
3
3
  import { MessageHistory } from './history/MessageHistory';
4
4
  import { Function } from './Function';
5
5
  import { Logger, LogLevel } from '@proteinjs/logger';
@@ -9,6 +9,8 @@ import { ConversationModule } from './ConversationModule';
9
9
  import { TiktokenModel, encoding_for_model } from 'tiktoken';
10
10
  import { searchLibrariesFunctionName } from './fs/package/PackageFunctions';
11
11
  import { UsageData } from './UsageData';
12
+ import type { ModelMessage, LanguageModel } from 'ai';
13
+ import { generateObject as aiGenerateObject, jsonSchema } from 'ai';
12
14
 
13
15
  export type ConversationParams = {
14
16
  name: string;
@@ -21,8 +23,36 @@ export type ConversationParams = {
21
23
  };
22
24
  };
23
25
 
26
+ /** Object-only generation (no tool calls in this run). */
27
+ export type GenerateObjectParams<S> = {
28
+ /** Same input contract as generateResponse */
29
+ messages: (string | ChatCompletionMessageParam)[];
30
+
31
+ /** A ready AI SDK model, e.g., openai('gpt-5') / openai('gpt-4o') */
32
+ model: LanguageModel;
33
+
34
+ /** Zod schema or JSON Schema */
35
+ schema: S;
36
+
37
+ /** Sampling & limits */
38
+ temperature?: number;
39
+ topP?: number;
40
+ maxTokens?: number;
41
+
42
+ /** Usage callback */
43
+ onUsageData?: (usageData: UsageData) => Promise<void>;
44
+
45
+ /** Append final JSON to history as assistant text; default true */
46
+ recordInHistory?: boolean;
47
+ };
48
+
49
+ export type GenerateObjectOutcome<T> = {
50
+ object: T; // validated final object
51
+ usageData: UsageData;
52
+ };
53
+
24
54
  export class Conversation {
25
- private tokenLimit = 3000;
55
+ private tokenLimit = 50000;
26
56
  private history;
27
57
  private systemMessages: ChatCompletionMessageParam[] = [];
28
58
  private functions: Function[] = [];
@@ -42,7 +72,7 @@ export class Conversation {
42
72
  });
43
73
  this.logger = new Logger({ name: params.name, logLevel: params.logLevel });
44
74
 
45
- if (typeof params.limits?.enforceLimits === 'undefined' || params.limits.enforceLimits) {
75
+ if (params?.limits?.enforceLimits) {
46
76
  this.addFunctions('Conversation', [summarizeConversationHistoryFunction(this)]);
47
77
  }
48
78
 
@@ -137,7 +167,7 @@ export class Conversation {
137
167
  }
138
168
 
139
169
  private async enforceTokenLimit(messages: (string | ChatCompletionMessageParam)[], model?: TiktokenModel) {
140
- if (this.params.limits?.enforceLimits === false) {
170
+ if (!this.params.limits?.enforceLimits) {
141
171
  return;
142
172
  }
143
173
 
@@ -234,9 +264,12 @@ export class Conversation {
234
264
  async generateResponse({
235
265
  messages,
236
266
  model,
267
+ ...rest
237
268
  }: {
238
269
  messages: (string | ChatCompletionMessageParam)[];
239
270
  model?: TiktokenModel;
271
+ onUsageData?: (usageData: UsageData) => Promise<void>;
272
+ onToolInvocation?: (evt: ToolInvocationProgressEvent) => void;
240
273
  }) {
241
274
  await this.ensureModulesProcessed();
242
275
  await this.enforceTokenLimit(messages, model);
@@ -245,7 +278,7 @@ export class Conversation {
245
278
  functions: this.functions,
246
279
  messageModerators: this.messageModerators,
247
280
  logLevel: this.params.logLevel,
248
- }).generateResponse({ messages, model });
281
+ }).generateResponse({ messages, model, ...rest });
249
282
  }
250
283
 
251
284
  async generateStreamingResponse({
@@ -257,6 +290,7 @@ export class Conversation {
257
290
  model?: TiktokenModel;
258
291
  abortSignal?: AbortSignal;
259
292
  onUsageData?: (usageData: UsageData) => Promise<void>;
293
+ onToolInvocation?: (evt: ToolInvocationProgressEvent) => void;
260
294
  }) {
261
295
  await this.ensureModulesProcessed();
262
296
  await this.enforceTokenLimit(messages, model);
@@ -268,6 +302,180 @@ export class Conversation {
268
302
  }).generateStreamingResponse({ messages, model, ...rest });
269
303
  }
270
304
 
305
+ /**
306
+ * Generate a validated JSON object (no tools in this run).
307
+ * Uses AI SDK `generateObject` which leverages provider-native structured outputs when available.
308
+ */
309
+ async generateObject<T>({
310
+ messages,
311
+ model,
312
+ schema,
313
+ temperature,
314
+ topP,
315
+ maxTokens,
316
+ onUsageData,
317
+ recordInHistory = true,
318
+ }: GenerateObjectParams<unknown>): Promise<GenerateObjectOutcome<T>> {
319
+ await this.ensureModulesProcessed();
320
+
321
+ const combined: ModelMessage[] = [
322
+ ...this.toModelMessages(this.history.getMessages()),
323
+ ...this.toModelMessages(messages),
324
+ ];
325
+
326
+ // Schema normalization (Zod OR JSON Schema supported)
327
+ const isZod =
328
+ schema &&
329
+ (typeof (schema as any).safeParse === 'function' ||
330
+ (!!(schema as any)._def && typeof (schema as any)._def.typeName === 'string'));
331
+ const normalizedSchema = isZod ? (schema as any) : jsonSchema(schema as any);
332
+
333
+ const result = await aiGenerateObject({
334
+ model,
335
+ messages: combined as any,
336
+ schema: normalizedSchema,
337
+ maxOutputTokens: maxTokens,
338
+ temperature,
339
+ topP,
340
+ experimental_repairText: async ({ text }: any) => {
341
+ const cleaned = String(text ?? '')
342
+ .trim()
343
+ .replace(/^```(?:json)?/i, '')
344
+ .replace(/```$/, '');
345
+ try {
346
+ JSON.parse(cleaned);
347
+ return cleaned;
348
+ } catch {
349
+ return null;
350
+ }
351
+ },
352
+ } as any);
353
+
354
+ // Record user messages to history (parity with other methods)
355
+ const chatCompletions: ChatCompletionMessageParam[] = messages.map((m) =>
356
+ typeof m === 'string' ? ({ role: 'user', content: m } as ChatCompletionMessageParam) : m
357
+ );
358
+ this.addMessagesToHistory(chatCompletions);
359
+
360
+ // Optionally persist the final JSON in history
361
+ if (recordInHistory) {
362
+ try {
363
+ const toRecord = typeof result?.object === 'object' ? JSON.stringify(result.object) : '';
364
+ if (toRecord) {
365
+ this.addAssistantMessagesToHistory([toRecord]);
366
+ }
367
+ } catch {
368
+ /* ignore */
369
+ }
370
+ }
371
+
372
+ const usageData = this.processUsageData({
373
+ result,
374
+ model,
375
+ });
376
+
377
+ if (onUsageData) {
378
+ await onUsageData(usageData);
379
+ }
380
+
381
+ return {
382
+ object: (result?.object ?? ({} as any)) as T,
383
+ usageData,
384
+ };
385
+ }
386
+
387
+ /** Convert (string | ChatCompletionMessageParam)[] -> AI SDK ModelMessage[] */
388
+ private toModelMessages(input: (string | ChatCompletionMessageParam)[]): ModelMessage[] {
389
+ return input.map((m) => {
390
+ if (typeof m === 'string') {
391
+ return { role: 'user', content: m };
392
+ }
393
+ const text = Array.isArray(m.content)
394
+ ? m.content.map((p: any) => (typeof p === 'string' ? p : p?.text ?? '')).join('\n')
395
+ : (m.content as string | undefined) ?? '';
396
+ const role = m.role === 'system' || m.role === 'user' || m.role === 'assistant' ? m.role : 'user';
397
+ return { role, content: text };
398
+ });
399
+ }
400
+
401
+ // ---- Usage + provider metadata normalization ----
402
+
403
+ private processUsageData(args: {
404
+ result: any;
405
+ model?: LanguageModel;
406
+ toolCounts?: Map<string, number>;
407
+ toolLedgerLen?: number;
408
+ }): UsageData {
409
+ const { result, model, toolCounts, toolLedgerLen } = args;
410
+
411
+ // Try several shapes used by AI SDK / providers
412
+ const u: any = result?.usage ?? result?.response?.usage ?? result?.response?.metadata?.usage;
413
+
414
+ // Provider-specific extras (OpenAI Responses variants)
415
+ const { cachedInputTokens } = this.extractOpenAiUsageDetails?.(result) ?? {};
416
+
417
+ const input = Number.isFinite(u?.inputTokens) ? Number(u.inputTokens) : 0;
418
+ const output = Number.isFinite(u?.outputTokens) ? Number(u.outputTokens) : 0;
419
+ const total = Number.isFinite(u?.totalTokens) ? Number(u.totalTokens) : input + output;
420
+ const cached = Number.isFinite(cachedInputTokens) ? Number(cachedInputTokens) : 0;
421
+
422
+ // Resolve model id for pricing/telemetry
423
+ const modelId: any =
424
+ (model as any)?.modelId ??
425
+ result?.response?.providerMetadata?.openai?.model ??
426
+ result?.providerMetadata?.openai?.model ??
427
+ result?.response?.model ??
428
+ undefined;
429
+
430
+ const tokenUsage = {
431
+ promptTokens: input,
432
+ cachedPromptTokens: cached,
433
+ completionTokens: output,
434
+ totalTokens: total,
435
+ };
436
+
437
+ const callsPerTool = toolCounts ? Object.fromEntries(toolCounts) : {};
438
+ const totalToolCalls =
439
+ typeof toolLedgerLen === 'number' ? toolLedgerLen : Object.values(callsPerTool).reduce((a, b) => a + (b || 0), 0);
440
+
441
+ return {
442
+ model: modelId,
443
+ initialRequestTokenUsage: { ...tokenUsage },
444
+ totalTokenUsage: { ...tokenUsage },
445
+ totalRequestsToAssistant: 1,
446
+ totalToolCalls,
447
+ callsPerTool,
448
+ };
449
+ }
450
+
451
+ // Pull OpenAI-specific cached/extra usage from provider metadata or raw usage.
452
+ // Safe across providers; returns undefined if not available.
453
+ private extractOpenAiUsageDetails(result: any): {
454
+ cachedInputTokens?: number;
455
+ reasoningTokens?: number;
456
+ } {
457
+ try {
458
+ const md = result?.providerMetadata?.openai ?? result?.response?.providerMetadata?.openai;
459
+ const usage = md?.usage ?? result?.response?.usage ?? result?.usage;
460
+
461
+ // OpenAI Responses API has used different shapes over time; try both:
462
+ const cachedInputTokens =
463
+ usage?.input_tokens_details?.cached_tokens ??
464
+ usage?.prompt_tokens_details?.cached_tokens ??
465
+ usage?.cached_input_tokens;
466
+
467
+ // Reasoning tokens (when available on reasoning models)
468
+ const reasoningTokens = usage?.output_tokens_details?.reasoning_tokens ?? usage?.reasoning_tokens;
469
+
470
+ return {
471
+ cachedInputTokens: typeof cachedInputTokens === 'number' ? cachedInputTokens : undefined,
472
+ reasoningTokens: typeof reasoningTokens === 'number' ? reasoningTokens : undefined,
473
+ };
474
+ } catch {
475
+ return {};
476
+ }
477
+ }
478
+
271
479
  async generateCode({ description, model }: { description: string[]; model?: TiktokenModel }) {
272
480
  this.logger.debug({ message: `Generating code`, obj: { description } });
273
481
  await this.ensureModulesProcessed();