git-coco 0.14.1 → 0.14.2

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.
package/dist/index.js CHANGED
@@ -72,473 +72,19 @@ var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
72
72
  var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
73
73
  var readline__namespace = /*#__PURE__*/_interopNamespaceDefault(readline$1);
74
74
 
75
- const isInteractive = (config) => {
76
- return config?.mode === 'interactive' || !!config?.interactive;
77
- };
78
- const SEPERATOR = chalk.blue('─────────────');
79
- const DIVIDER = chalk.dim(`\\`);
80
- const LOGO = chalk.green(`┌──────┐
81
- │┏┏┓┏┏┓│
82
- │┗┗┛┗┗┛│
83
- └──────┘`);
84
- chalk.green(`┌────┐
85
- │coco│
86
- └────┘`);
87
- const bannerWithHeader = (banner) => {
88
- return chalk.green(`┌────┐
89
- │coco│ ${banner}
90
- └────┘`);
91
- };
92
- const USAGE_BANNER = chalk.green(`${LOGO}
93
- ${chalk.bgGreen(`\xa0v${process.env.npm_package_version}\xa0`)}
94
- `);
95
- const getCommandUsageHeader = (command) => {
96
- return chalk.green(`${USAGE_BANNER}\n${chalk.white('Command:')}\n\xa0\xa0\xa0\xa0\xa0 $0 ${chalk.greenBright(command)} [options]`);
97
- };
98
- const CONFIG_ALREADY_EXISTS = (path) => {
99
- return `existing config found in '${path}', do you want to override it?`;
100
- };
101
- const severityColors = [
102
- chalk.greenBright, // 1
103
- chalk.green, // 2
104
- chalk.cyan, // 3
105
- chalk.yellowBright, // 4
106
- chalk.yellow, // 5
107
- chalk.bgYellow, // 6
108
- chalk.red, // 7
109
- chalk.redBright, // 8
110
- chalk.bgRed, // 9
111
- chalk.bgRedBright, // 10
112
- ];
113
- const severityColor = (severity) => {
114
- return severityColors[Math.min(severity - 1, severityColors.length - 1)];
115
- };
116
- const statusColor = (status) => {
117
- switch (status) {
118
- case 'completed':
119
- return chalk.green;
120
- case 'skipped':
121
- return chalk.yellow;
122
- case 'omitted':
123
- return chalk.red;
124
- default:
125
- return chalk.blue;
126
- }
127
- };
128
- const hotKey = (key) => chalk.dim(`(${key})`);
129
-
130
- /**
131
- * Returns a new object with all undefined keys removed
132
- *
133
- * @param obj Object to remove undefined keys from
134
- * @returns
135
- */
136
- function removeUndefined(obj) {
137
- return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
138
- }
139
-
140
- async function updateFileSection({ filePath, startComment, endComment, getNewContent, confirmUpdate = true, confirmMessage = (path) => `A section already exists in ${path}, do you want to override it?`, }) {
141
- const lines = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8').split(/\r?\n/) : [];
142
- const newLines = [];
143
- let foundSection = false;
144
- for (let i = 0; i < lines.length; i++) {
145
- if (lines[i].trim() === startComment) {
146
- foundSection = true;
147
- if (confirmUpdate) {
148
- const confirmOverwrite = await prompts.confirm({
149
- message: typeof confirmMessage === 'function' ? confirmMessage(filePath) : confirmMessage,
150
- default: false,
151
- });
152
- if (!confirmOverwrite) {
153
- // keep all lines until the end comment
154
- while (i < lines.length && lines[i].trim() !== endComment) {
155
- newLines.push(lines[i]);
156
- i++;
157
- }
158
- newLines.push(endComment);
159
- continue;
160
- }
161
- }
162
- newLines.push(startComment);
163
- // Insert the new content
164
- const newContent = await getNewContent();
165
- newLines.push(newContent);
166
- // Skip the existing content of the section
167
- while (i < lines.length && lines[i].trim() !== endComment) {
168
- i++;
169
- }
170
- newLines.push(endComment);
171
- continue;
172
- }
173
- if (!foundSection || lines[i].trim() !== endComment) {
174
- newLines.push(lines[i]);
175
- }
176
- }
177
- // If section wasn't found, append it at the end
178
- if (!foundSection) {
179
- newLines.push('\n' + startComment);
180
- const newContent = await getNewContent();
181
- newLines.push(newContent);
182
- newLines.push(endComment);
183
- }
184
- // Write the updated contents back to the file
185
- fs.writeFileSync(filePath, newLines.join('\n'));
186
- }
187
-
188
- const template$5 = `GOAL: Use functional abstractions to summarize the following text
189
-
190
- RULES: Avoid phrases like "this change", "this code", or "this function" etc. Instead refer to the function, variable, or class by name.
191
-
192
- TEXT:"""{text}"""
193
- `;
194
- const inputVariables$4 = ['text'];
195
- const SUMMARIZE_PROMPT = new prompts$1.PromptTemplate({
196
- inputVariables: inputVariables$4,
197
- template: template$5,
198
- });
199
-
200
- /**
201
- * Retrieves the provider and model from the given configuration object.
202
- * @param config The configuration object.
203
- * @returns An object containing the provider and model.
204
- * @throws Error if the configuration is invalid or missing required properties.
205
- */
206
- function getModelAndProviderFromConfig(config) {
207
- if (!config.service) {
208
- throw new Error('Invalid service: undefined');
209
- }
210
- const { provider, model } = config.service;
211
- if (!model || !provider) {
212
- throw new Error(`Invalid service: ${config.service}`);
213
- }
214
- return { provider, model };
215
- }
216
- /**
217
- * Retrieve appropriate API key based on selected model
218
- * @param service
219
- * @param options
220
- * @returns API Key
221
- */
222
- function getApiKeyForModel(config) {
223
- const { provider } = getModelAndProviderFromConfig(config);
224
- switch (provider) {
225
- case 'openai':
226
- return getDefaultServiceApiKey(config);
227
- default:
228
- return getDefaultServiceApiKey(config);
229
- }
230
- }
231
- /**
232
- * Retrieves the default service API key from the given configuration.
233
- * @param config The configuration object.
234
- * @returns The default service API key.
235
- */
236
- function getDefaultServiceApiKey(config) {
237
- const service = config.service;
238
- if (service.authentication.type === 'APIKey') {
239
- return service.authentication.credentials?.apiKey;
240
- }
241
- else if (service.authentication.type === 'OAuth') {
242
- return service.authentication.credentials?.token;
243
- }
244
- return '';
245
- }
246
- const DEFAULT_OPENAI_LLM_SERVICE = {
247
- provider: 'openai',
248
- model: 'gpt-4',
249
- tokenLimit: 2024,
250
- temperature: 0.32,
251
- authentication: {
252
- type: 'APIKey',
253
- credentials: {
254
- apiKey: '',
255
- },
256
- },
257
- };
258
- const DEFAULT_OLLAMA_LLM_SERVICE = {
259
- provider: 'ollama',
260
- model: 'llama3',
261
- endpoint: 'http://localhost:11434',
262
- maxConcurrent: 1,
263
- tokenLimit: 2024,
264
- temperature: 0.4,
265
- authentication: {
266
- type: 'None',
267
- credentials: undefined,
268
- },
269
- };
75
+ // This file is auto-generated - DO NOT EDIT
76
+ /* eslint-disable */
270
77
  /**
271
- * Retrieves the default service configuration based on the provided alias and optional model.
272
- * @param provider - The alias of the service.
273
- * @param model - The optional model to be used.
274
- * @returns The default service configuration.
275
- * @throws Error if the alias is invalid or undefined.
78
+ * Schema ID for JSON validation
276
79
  */
277
- function getDefaultServiceConfigFromAlias(provider, model) {
278
- switch (provider) {
279
- case 'ollama':
280
- return {
281
- ...DEFAULT_OLLAMA_LLM_SERVICE,
282
- model: model || DEFAULT_OLLAMA_LLM_SERVICE.model,
283
- };
284
- case 'openai':
285
- default:
286
- return {
287
- ...DEFAULT_OPENAI_LLM_SERVICE,
288
- model: model || DEFAULT_OPENAI_LLM_SERVICE.model,
289
- };
290
- }
291
- }
292
-
293
- const DEFAULT_IGNORED_FILES = ['package-lock.json', 'yarn.lock', 'node_modules'];
294
- const DEFAULT_IGNORED_EXTENSIONS = ['.map', '.lock'];
295
- const COCO_CONFIG_START_COMMENT = '# -- start coco config --';
296
- const COCO_CONFIG_END_COMMENT = '# -- end coco config --';
80
+ const SCHEMA_PUBLIC_URL = "http://git-co.co/schema.json";
297
81
  /**
298
- * Default Config
299
- *
300
- * @type {Config}
82
+ * Current build version from package.json
301
83
  */
302
- const DEFAULT_CONFIG$1 = {
303
- mode: 'stdout',
304
- verbose: false,
305
- defaultBranch: 'main',
306
- service: getDefaultServiceConfigFromAlias('openai'),
307
- summarizePrompt: SUMMARIZE_PROMPT.template,
308
- ignoredFiles: DEFAULT_IGNORED_FILES,
309
- ignoredExtensions: DEFAULT_IGNORED_EXTENSIONS,
310
- };
84
+ const BUILD_VERSION = "0.14.2";
311
85
  /**
312
- * Create a named export of all config keys for use in other modules.
313
- *
314
- * @see Used in `src/lib/config/services/env.ts` to validate all env vars.
315
- *
316
- * @type {string[]}
86
+ * Generated JSON schema
317
87
  */
318
- const CONFIG_KEYS = Object.keys({
319
- ...DEFAULT_CONFIG$1,
320
- prompt: '',
321
- });
322
-
323
- /**
324
- * Load environment variables
325
- *
326
- * @param {Config} config
327
- * @returns {Config} Updated config
328
- **/
329
- function loadEnvConfig(config) {
330
- const envConfig = {};
331
- const envKeys = [...CONFIG_KEYS, 'COCO_SERVICE_PROVIDER', 'COCO_SERVICE_MODEL', 'OPEN_AI_KEY'];
332
- envKeys.forEach((key) => {
333
- const envVarName = toEnvVarName(key);
334
- const envValue = parseEnvValue(key, process.env[envVarName]);
335
- if (envValue === undefined) {
336
- return;
337
- }
338
- if (key === 'COCO_SERVICE_PROVIDER' || key === 'COCO_SERVICE_MODEL' || key === 'OPEN_AI_KEY') {
339
- // NOTE: We want to ensure that the service object is always defined
340
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
341
- // @ts-ignore
342
- envConfig.service = envConfig.service || {};
343
- handleServiceEnvVar(envConfig.service, key, envValue);
344
- }
345
- else {
346
- if (key === 'service' || !envValue) {
347
- return;
348
- }
349
- envConfig[key] = envValue;
350
- }
351
- });
352
- return { ...config, ...removeUndefined(envConfig) };
353
- }
354
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
355
- function handleServiceEnvVar(service, key, value) {
356
- switch (key) {
357
- case 'COCO_SERVICE_PROVIDER':
358
- service.provider = value;
359
- break;
360
- case 'COCO_SERVICE_MODEL':
361
- service.model = value;
362
- break;
363
- case 'OPEN_AI_KEY':
364
- if (service.provider === 'openai') {
365
- service.fields = { apiKey: value };
366
- }
367
- break;
368
- }
369
- }
370
- function parseEnvValue(key, value) {
371
- switch (true) {
372
- // Handle undefined values
373
- case value === undefined:
374
- return undefined;
375
- // Handle comma separated strings for ignoredFiles and ignoredExtensions arrays
376
- case (key === 'ignoredFiles' || key === 'ignoredExtensions') &&
377
- typeof value === 'string' &&
378
- value.includes(','):
379
- return value.split(',');
380
- // Handle boolean values
381
- case typeof value === 'string' && (value === 'false' || value === 'true'):
382
- return value === 'true';
383
- // Handle number values
384
- case typeof value === 'string' && !isNaN(Number(value)):
385
- return Number(value);
386
- default:
387
- return value;
388
- }
389
- }
390
- function toEnvVarName(key) {
391
- if (key === 'service') {
392
- return key;
393
- }
394
- if (key.includes('COCO_')) {
395
- return key;
396
- }
397
- return `COCO_${key.replace(/([A-Z])/g, '_$1').toLocaleUpperCase()}`;
398
- }
399
- function formatEnvValue(value) {
400
- if (typeof value === 'number') {
401
- return `${value}`;
402
- }
403
- else if (Array.isArray(value)) {
404
- return `${value.join(',')}`;
405
- }
406
- else if (typeof value === 'string') {
407
- // Escape newlines and tabs in strings
408
- return `${value.replace(/\n/g, '\\n').replace(/\t/g, '\\t')}`;
409
- }
410
- return `${value}`;
411
- }
412
- const appendToEnvFile = async (filePath, config) => {
413
- const getNewContent = async () => {
414
- return Object.entries(config)
415
- .map(([key, value]) => {
416
- if (key === 'service') {
417
- const service = value;
418
- return `${service.provider ? `COCO_SERVICE_PROVIDER=${service.provider}` : ''}\n${service.model ? `COCO_SERVICE_MODEL=${service.model}` : ''}\n${service.authentication.type === 'APIKey'
419
- ? `OPEN_AI_KEY=${service.authentication.credentials.apiKey}`
420
- : ''}`;
421
- }
422
- const envVarName = toEnvVarName(key);
423
- const envValue = formatEnvValue(value);
424
- return `${envVarName}=${envValue}`;
425
- })
426
- .join('\n');
427
- };
428
- await updateFileSection({
429
- filePath,
430
- startComment: COCO_CONFIG_START_COMMENT,
431
- endComment: COCO_CONFIG_END_COMMENT,
432
- getNewContent,
433
- confirmMessage: CONFIG_ALREADY_EXISTS,
434
- });
435
- };
436
-
437
- /**
438
- * Load git profile config (from ~/.gitconfig)
439
- *
440
- * @param {Config} config
441
- * @returns {Config} Updated config
442
- **/
443
- function loadGitConfig(config) {
444
- const gitConfigPath = path__namespace.join(os__namespace.homedir(), '.gitconfig');
445
- if (fs__namespace.existsSync(gitConfigPath)) {
446
- const gitConfigRaw = fs__namespace.readFileSync(gitConfigPath, 'utf-8');
447
- const gitConfigParsed = ini__namespace.parse(gitConfigRaw);
448
- const gitConfigServiceObject = gitConfigParsed.coco?.service;
449
- let service = config.service;
450
- if (gitConfigServiceObject) {
451
- const gitServiceConfig = JSON.parse(gitConfigServiceObject);
452
- service = gitServiceConfig || config?.service;
453
- }
454
- config = {
455
- ...config,
456
- service: service,
457
- prompt: gitConfigParsed.coco?.prompt || config.prompt,
458
- mode: gitConfigParsed.coco?.mode || config.mode,
459
- summarizePrompt: gitConfigParsed.coco?.summarizePrompt || config.summarizePrompt,
460
- ignoredFiles: gitConfigParsed.coco?.ignoredFiles || config.ignoredFiles,
461
- ignoredExtensions: gitConfigParsed.coco?.ignoredExtensions || config.ignoredExtensions,
462
- defaultBranch: gitConfigParsed.coco?.defaultBranch || config.defaultBranch,
463
- verbose: gitConfigParsed.coco?.verbose || config.verbose,
464
- };
465
- }
466
- return removeUndefined(config);
467
- }
468
- /**
469
- * Appends the provided configuration to a git config file.
470
- *
471
- * @param filePath - The path to the .gitconfig
472
- * @param config - The configuration object to append.
473
- */
474
- const appendToGitConfig = async (filePath, config) => {
475
- if (!fs__namespace.existsSync(filePath)) {
476
- throw new Error(`File ${filePath} does not exist.`);
477
- }
478
- const header = '[coco]';
479
- const getNewContent = async () => {
480
- const contentLines = [header];
481
- for (const key in config) {
482
- const value = config[key];
483
- if (typeof value === 'object') {
484
- // Serialize object to JSON string
485
- contentLines.push(`\t${key} = ${JSON.stringify(value)}`);
486
- }
487
- else if (typeof value === 'string' && value.includes('\n')) {
488
- // Wrap strings with new lines in quotes
489
- contentLines.push(`\t${key} = ${JSON.stringify(value)}`);
490
- }
491
- else {
492
- contentLines.push(`\t${key} = ${value}`);
493
- }
494
- }
495
- return contentLines.join('\n');
496
- };
497
- await updateFileSection({
498
- filePath,
499
- startComment: COCO_CONFIG_START_COMMENT,
500
- endComment: COCO_CONFIG_END_COMMENT,
501
- getNewContent,
502
- confirmUpdate: true,
503
- confirmMessage: CONFIG_ALREADY_EXISTS,
504
- });
505
- };
506
-
507
- /**
508
- * Load .gitignore in project root
509
- *
510
- * @param {Config} config
511
- * @returns
512
- */
513
- function loadGitignore(config) {
514
- if (fs__namespace.existsSync('.gitignore')) {
515
- const gitignoreContent = fs__namespace.readFileSync('.gitignore', 'utf-8');
516
- config.ignoredFiles = [
517
- ...(config?.ignoredFiles || []),
518
- ...gitignoreContent.split('\n').filter((line) => line.trim() !== '' && !line.startsWith('#')),
519
- ];
520
- }
521
- return config;
522
- }
523
- /**
524
- * Load .ignore in project root
525
- *
526
- * @param {Config} config
527
- * @returns
528
- */
529
- function loadIgnore(config) {
530
- if (fs__namespace.existsSync('.ignore')) {
531
- const ignoreContent = fs__namespace.readFileSync('.ignore', 'utf-8');
532
- config.ignoredFiles = [
533
- ...(config?.ignoredFiles || []),
534
- ...ignoreContent.split('\n').filter((line) => line.trim() !== '' && !line.startsWith('#')),
535
- ];
536
- }
537
- return config;
538
- }
539
-
540
- // this file is auto-generated by the 'build:schema' script
541
- const SCHEMA_PUBLIC_URL = "http://git-co.co/schema.json";
542
88
  const schema$1 = {
543
89
  "$id": "http://git-co.co/schema.json",
544
90
  "$schema": "http://json-schema.org/draft-07/schema#",
@@ -554,14 +100,17 @@ const schema$1 = {
554
100
  "interactive": {
555
101
  "type": "boolean"
556
102
  },
557
- "help": {
558
- "type": "boolean"
559
- },
560
103
  "verbose": {
561
104
  "type": "boolean",
562
105
  "description": "Enable verbose logging.",
563
106
  "default": false
564
107
  },
108
+ "version": {
109
+ "type": "boolean"
110
+ },
111
+ "help": {
112
+ "type": "boolean"
113
+ },
565
114
  "mode": {
566
115
  "type": "string",
567
116
  "enum": [
@@ -628,6 +177,9 @@ const schema$1 = {
628
177
  },
629
178
  {
630
179
  "$ref": "#/definitions/OllamaLLMService"
180
+ },
181
+ {
182
+ "$ref": "#/definitions/AnthropicLLMService"
631
183
  }
632
184
  ]
633
185
  },
@@ -642,321 +194,151 @@ const schema$1 = {
642
194
  "$ref": "#/definitions/LLMModel"
643
195
  },
644
196
  "fields": {
645
- "anyOf": [
646
- {
197
+ "type": "object",
198
+ "additionalProperties": false,
199
+ "properties": {
200
+ "verbose": {
201
+ "type": "boolean"
202
+ },
203
+ "callbacks": {
204
+ "$ref": "#/definitions/Callbacks"
205
+ },
206
+ "tags": {
207
+ "type": "array",
208
+ "items": {
209
+ "type": "string"
210
+ }
211
+ },
212
+ "metadata": {
647
213
  "type": "object",
648
- "additionalProperties": false,
649
- "properties": {
650
- "verbose": {
651
- "type": "boolean"
652
- },
653
- "callbacks": {
654
- "$ref": "#/definitions/Callbacks"
655
- },
656
- "tags": {
657
- "type": "array",
658
- "items": {
659
- "type": "string"
660
- }
661
- },
662
- "metadata": {
663
- "type": "object",
664
- "additionalProperties": {}
665
- },
666
- "maxConcurrency": {
667
- "type": "number",
668
- "description": "The maximum number of concurrent calls that can be made. Defaults to `Infinity`, which means no limit."
669
- },
670
- "maxRetries": {
671
- "type": "number",
672
- "description": "The maximum number of retries that can be made for a single call, with an exponential backoff between each attempt. Defaults to 6."
673
- },
674
- "onFailedAttempt": {
675
- "$ref": "#/definitions/FailedAttemptHandler",
676
- "description": "Custom handler to handle failed attempts. Takes the originally thrown error object as input, and should itself throw an error if the input error is not retryable."
677
- },
678
- "callbackManager": {
679
- "$ref": "#/definitions/CallbackManager",
680
- "deprecated": "Use `callbacks` instead"
681
- },
682
- "cache": {
683
- "anyOf": [
684
- {
685
- "$ref": "#/definitions/BaseCache"
686
- },
687
- {
688
- "type": "boolean"
689
- }
690
- ]
691
- },
692
- "concurrency": {
693
- "type": "number",
694
- "deprecated": "Use `maxConcurrency` instead"
695
- },
696
- "bestOf": {
697
- "type": "number",
698
- "description": "Generates `bestOf` completions server side and returns the \"best\""
699
- },
700
- "batchSize": {
701
- "type": "number",
702
- "description": "Batch size to use when passing multiple documents to generate"
703
- },
704
- "temperature": {
705
- "type": "number",
706
- "description": "Sampling temperature to use"
707
- },
708
- "maxTokens": {
709
- "type": "number",
710
- "description": "Maximum number of tokens to generate in the completion. -1 returns as many tokens as possible given the prompt and the model's maximum context size."
711
- },
712
- "topP": {
713
- "type": "number",
714
- "description": "Total probability mass of tokens to consider at each step"
715
- },
716
- "frequencyPenalty": {
717
- "type": "number",
718
- "description": "Penalizes repeated tokens according to frequency"
719
- },
720
- "presencePenalty": {
721
- "type": "number",
722
- "description": "Penalizes repeated tokens"
723
- },
724
- "n": {
725
- "type": "number",
726
- "description": "Number of completions to generate for each prompt"
727
- },
728
- "logitBias": {
729
- "type": "object",
730
- "additionalProperties": {
731
- "type": "number"
732
- },
733
- "description": "Dictionary used to adjust the probability of specific tokens being generated"
734
- },
735
- "user": {
736
- "type": "string",
737
- "description": "Unique string identifier representing your end-user, which can help OpenAI to monitor and detect abuse."
738
- },
739
- "streaming": {
740
- "type": "boolean",
741
- "description": "Whether to stream the results or not. Enabling disables tokenUsage reporting"
214
+ "additionalProperties": {}
215
+ },
216
+ "maxConcurrency": {
217
+ "type": "number",
218
+ "description": "The maximum number of concurrent calls that can be made. Defaults to `Infinity`, which means no limit."
219
+ },
220
+ "maxRetries": {
221
+ "type": "number",
222
+ "description": "The maximum number of retries that can be made for a single call, with an exponential backoff between each attempt. Defaults to 6."
223
+ },
224
+ "onFailedAttempt": {
225
+ "$ref": "#/definitions/FailedAttemptHandler",
226
+ "description": "Custom handler to handle failed attempts. Takes the originally thrown error object as input, and should itself throw an error if the input error is not retryable."
227
+ },
228
+ "callbackManager": {
229
+ "$ref": "#/definitions/CallbackManager",
230
+ "deprecated": "Use `callbacks` instead"
231
+ },
232
+ "cache": {
233
+ "anyOf": [
234
+ {
235
+ "$ref": "#/definitions/BaseCache"
742
236
  },
743
- "streamUsage": {
744
- "type": "boolean",
745
- "description": "Whether or not to include token usage data in streamed chunks.",
746
- "default": true
747
- },
748
- "modelName": {
749
- "type": "string",
750
- "description": "Model name to use Alias for `model`"
751
- },
752
- "model": {
753
- "type": "string",
754
- "description": "Model name to use"
755
- },
756
- "modelKwargs": {
757
- "type": "object",
758
- "description": "Holds any additional parameters that are valid to pass to {@link * https://platform.openai.com/docs/api-reference/completions/create | } * `openai.createCompletion`} that are not explicitly specified on this class."
759
- },
760
- "stop": {
761
- "type": "array",
762
- "items": {
763
- "type": "string"
764
- },
765
- "description": "List of stop words to use when generating Alias for `stopSequences`"
766
- },
767
- "stopSequences": {
768
- "type": "array",
769
- "items": {
770
- "type": "string"
771
- },
772
- "description": "List of stop words to use when generating"
773
- },
774
- "timeout": {
775
- "type": "number",
776
- "description": "Timeout to use when making requests to OpenAI."
777
- },
778
- "openAIApiKey": {
779
- "type": "string",
780
- "description": "API key to use when making requests to OpenAI. Defaults to the value of `OPENAI_API_KEY` environment variable. Alias for `apiKey`"
781
- },
782
- "apiKey": {
783
- "type": "string",
784
- "description": "API key to use when making requests to OpenAI. Defaults to the value of `OPENAI_API_KEY` environment variable."
237
+ {
238
+ "type": "boolean"
785
239
  }
786
- }
240
+ ]
787
241
  },
788
- {
242
+ "concurrency": {
243
+ "type": "number",
244
+ "deprecated": "Use `maxConcurrency` instead"
245
+ },
246
+ "bestOf": {
247
+ "type": "number",
248
+ "description": "Generates `bestOf` completions server side and returns the \"best\""
249
+ },
250
+ "batchSize": {
251
+ "type": "number",
252
+ "description": "Batch size to use when passing multiple documents to generate"
253
+ },
254
+ "temperature": {
255
+ "type": "number",
256
+ "description": "Sampling temperature to use"
257
+ },
258
+ "maxTokens": {
259
+ "type": "number",
260
+ "description": "Maximum number of tokens to generate in the completion. -1 returns as many tokens as possible given the prompt and the model's maximum context size."
261
+ },
262
+ "topP": {
263
+ "type": "number",
264
+ "description": "Total probability mass of tokens to consider at each step"
265
+ },
266
+ "frequencyPenalty": {
267
+ "type": "number",
268
+ "description": "Penalizes repeated tokens according to frequency"
269
+ },
270
+ "presencePenalty": {
271
+ "type": "number",
272
+ "description": "Penalizes repeated tokens"
273
+ },
274
+ "n": {
275
+ "type": "number",
276
+ "description": "Number of completions to generate for each prompt"
277
+ },
278
+ "logitBias": {
789
279
  "type": "object",
790
- "additionalProperties": false,
791
- "properties": {
792
- "verbose": {
793
- "type": "boolean"
794
- },
795
- "callbacks": {
796
- "$ref": "#/definitions/Callbacks"
797
- },
798
- "tags": {
799
- "type": "array",
800
- "items": {
801
- "type": "string"
802
- }
803
- },
804
- "metadata": {
805
- "type": "object",
806
- "additionalProperties": {}
807
- },
808
- "maxConcurrency": {
809
- "type": "number",
810
- "description": "The maximum number of concurrent calls that can be made. Defaults to `Infinity`, which means no limit."
811
- },
812
- "maxRetries": {
813
- "type": "number",
814
- "description": "The maximum number of retries that can be made for a single call, with an exponential backoff between each attempt. Defaults to 6."
815
- },
816
- "onFailedAttempt": {
817
- "$ref": "#/definitions/FailedAttemptHandler",
818
- "description": "Custom handler to handle failed attempts. Takes the originally thrown error object as input, and should itself throw an error if the input error is not retryable."
819
- },
820
- "callbackManager": {
821
- "$ref": "#/definitions/CallbackManager",
822
- "deprecated": "Use `callbacks` instead"
823
- },
824
- "cache": {
825
- "anyOf": [
826
- {
827
- "$ref": "#/definitions/BaseCache"
828
- },
829
- {
830
- "type": "boolean"
831
- }
832
- ]
833
- },
834
- "concurrency": {
835
- "type": "number",
836
- "deprecated": "Use `maxConcurrency` instead"
837
- },
838
- "embeddingOnly": {
839
- "type": "boolean"
840
- },
841
- "f16KV": {
842
- "type": "boolean"
843
- },
844
- "frequencyPenalty": {
845
- "type": "number"
846
- },
847
- "headers": {
848
- "type": "object",
849
- "additionalProperties": {
850
- "type": "string"
851
- }
852
- },
853
- "keepAlive": {
854
- "type": "string"
855
- },
856
- "logitsAll": {
857
- "type": "boolean"
858
- },
859
- "lowVram": {
860
- "type": "boolean"
861
- },
862
- "mainGpu": {
863
- "type": "number"
864
- },
865
- "model": {
866
- "type": "string"
867
- },
868
- "baseUrl": {
869
- "type": "string"
870
- },
871
- "mirostat": {
872
- "type": "number"
873
- },
874
- "mirostatEta": {
875
- "type": "number"
876
- },
877
- "mirostatTau": {
878
- "type": "number"
879
- },
880
- "numBatch": {
881
- "type": "number"
882
- },
883
- "numCtx": {
884
- "type": "number"
885
- },
886
- "numGpu": {
887
- "type": "number"
888
- },
889
- "numGqa": {
890
- "type": "number"
891
- },
892
- "numKeep": {
893
- "type": "number"
894
- },
895
- "numPredict": {
896
- "type": "number"
897
- },
898
- "numThread": {
899
- "type": "number"
900
- },
901
- "penalizeNewline": {
902
- "type": "boolean"
903
- },
904
- "presencePenalty": {
905
- "type": "number"
906
- },
907
- "repeatLastN": {
908
- "type": "number"
909
- },
910
- "repeatPenalty": {
911
- "type": "number"
912
- },
913
- "ropeFrequencyBase": {
914
- "type": "number"
915
- },
916
- "ropeFrequencyScale": {
917
- "type": "number"
918
- },
919
- "temperature": {
920
- "type": "number"
921
- },
922
- "stop": {
923
- "type": "array",
924
- "items": {
925
- "type": "string"
926
- }
927
- },
928
- "tfsZ": {
929
- "type": "number"
930
- },
931
- "topK": {
932
- "type": "number"
933
- },
934
- "topP": {
935
- "type": "number"
936
- },
937
- "typicalP": {
938
- "type": "number"
939
- },
940
- "useMLock": {
941
- "type": "boolean"
942
- },
943
- "useMMap": {
944
- "type": "boolean"
945
- },
946
- "vocabOnly": {
947
- "type": "boolean"
948
- },
949
- "format": {
950
- "$ref": "#/definitions/StringWithAutocomplete%3C%22json%22%3E"
951
- }
952
- }
280
+ "additionalProperties": {
281
+ "type": "number"
282
+ },
283
+ "description": "Dictionary used to adjust the probability of specific tokens being generated"
284
+ },
285
+ "user": {
286
+ "type": "string",
287
+ "description": "Unique string identifier representing your end-user, which can help OpenAI to monitor and detect abuse."
288
+ },
289
+ "streaming": {
290
+ "type": "boolean",
291
+ "description": "Whether to stream the results or not. Enabling disables tokenUsage reporting"
292
+ },
293
+ "streamUsage": {
294
+ "type": "boolean",
295
+ "description": "Whether or not to include token usage data in streamed chunks.",
296
+ "default": true
297
+ },
298
+ "modelName": {
299
+ "type": "string",
300
+ "description": "Model name to use Alias for `model`"
301
+ },
302
+ "model": {
303
+ "type": "string",
304
+ "description": "Model name to use"
305
+ },
306
+ "modelKwargs": {
307
+ "type": "object",
308
+ "description": "Holds any additional parameters that are valid to pass to {@link * https://platform.openai.com/docs/api-reference/completions/create | } * `openai.createCompletion`} that are not explicitly specified on this class."
309
+ },
310
+ "stop": {
311
+ "type": "array",
312
+ "items": {
313
+ "type": "string"
314
+ },
315
+ "description": "List of stop words to use when generating Alias for `stopSequences`"
316
+ },
317
+ "stopSequences": {
318
+ "type": "array",
319
+ "items": {
320
+ "type": "string"
321
+ },
322
+ "description": "List of stop words to use when generating"
323
+ },
324
+ "timeout": {
325
+ "type": "number",
326
+ "description": "Timeout to use when making requests to OpenAI."
327
+ },
328
+ "openAIApiKey": {
329
+ "type": "string",
330
+ "description": "API key to use when making requests to OpenAI. Defaults to the value of `OPENAI_API_KEY` environment variable. Alias for `apiKey`"
331
+ },
332
+ "apiKey": {
333
+ "type": "string",
334
+ "description": "API key to use when making requests to OpenAI. Defaults to the value of `OPENAI_API_KEY` environment variable."
953
335
  }
954
- ]
336
+ }
955
337
  },
956
338
  "tokenLimit": {
957
339
  "type": "number",
958
340
  "description": "The maximum number of tokens per request.",
959
- "default": 1024
341
+ "default": 2048
960
342
  },
961
343
  "temperature": {
962
344
  "type": "number",
@@ -1066,7 +448,8 @@ const schema$1 = {
1066
448
  "type": "string",
1067
449
  "enum": [
1068
450
  "openai",
1069
- "ollama"
451
+ "ollama",
452
+ "anthropic"
1070
453
  ]
1071
454
  },
1072
455
  "LLMModel": {
@@ -1134,51 +517,76 @@ const schema$1 = {
1134
517
  },
1135
518
  {
1136
519
  "$ref": "#/definitions/OllamaModel"
520
+ },
521
+ {
522
+ "$ref": "#/definitions/AnthropicModel"
1137
523
  }
1138
524
  ]
1139
525
  },
1140
526
  "OllamaModel": {
1141
527
  "type": "string",
1142
528
  "enum": [
1143
- "neural-chat",
1144
- "aya:8b",
1145
- "aya:35b",
1146
- "mistral",
1147
- "llama2",
1148
- "codellama",
1149
- "codellama:7b",
529
+ "codegemma:2b",
530
+ "codegemma:7b-code",
531
+ "codegemma",
1150
532
  "codellama:13b",
1151
533
  "codellama:34b",
1152
534
  "codellama:70b",
1153
- "llama2-uncensored",
535
+ "codellama:7b",
536
+ "codellama:instruct",
537
+ "codellama:latest",
538
+ "codellama",
539
+ "gemma:2b",
540
+ "gemma:7b",
541
+ "gemma:latest",
542
+ "gemma",
1154
543
  "llama2:13b",
1155
544
  "llama2:70b",
1156
- "llama3",
545
+ "llama2:chat",
546
+ "llama2:latest",
547
+ "llama2:text",
548
+ "llama2",
549
+ "llama3:70b-text",
550
+ "llama3:70b",
1157
551
  "llama3:latest",
1158
552
  "llama3:text",
1159
- "llama3:70b",
1160
- "llama3:70b-text",
1161
- "orca2",
1162
- "orca2:13b",
1163
- "orca-mini",
1164
- "orca-mini:latest",
1165
- "orca-mini:13b",
1166
- "orca-mini:70b",
1167
- "phi3",
1168
- "phi3:mini",
1169
- "phi3:medium",
553
+ "llama3.1:70b",
554
+ "llama3.1:8b",
555
+ "llama3.1:latest",
556
+ "llama3.2",
557
+ "llama3.2:latest",
558
+ "llama3.2:1b",
559
+ "llama3.2:3b",
560
+ "llama3.2:1b-instruct-fp16",
561
+ "llama3.2:1b-instruct-q3_K_M",
562
+ "llama3",
563
+ "mistral:7b",
564
+ "mistral:latest",
565
+ "mistral:text",
566
+ "mistral",
567
+ "phi3:14b",
568
+ "phi3:3.8b",
569
+ "phi3:instruct",
1170
570
  "phi3:medium-128k",
1171
- "qwen2",
1172
- "qwen2:72b",
1173
- "qwen2:72b-text",
1174
- "qwen2:1.5b",
571
+ "phi3:medium-4k",
572
+ "phi3:medium",
573
+ "phi3",
1175
574
  "qwen2:0.5b",
1176
- "gemma",
1177
- "gemma:7b`",
1178
- "gemma:2b",
1179
- "codegemma",
1180
- "codegemma:7b-code",
1181
- "codegemma:2b"
575
+ "qwen2:1.5b",
576
+ "qwen2:72b-text",
577
+ "qwen2:72b",
578
+ "qwen2"
579
+ ]
580
+ },
581
+ "AnthropicModel": {
582
+ "type": "string",
583
+ "enum": [
584
+ "claude-3-5-sonnet-20240620",
585
+ "claude-3-opus-20240229",
586
+ "claude-3-sonnet-20240229",
587
+ "claude-3-haiku-20240307",
588
+ "claude-2.1",
589
+ "claude-2.0"
1182
590
  ]
1183
591
  },
1184
592
  "Callbacks": {
@@ -1343,20 +751,6 @@ const schema$1 = {
1343
751
  "additionalProperties": false,
1344
752
  "description": "Base class for all caches. All caches should extend this class."
1345
753
  },
1346
- "StringWithAutocomplete<\"json\">": {
1347
- "anyOf": [
1348
- {
1349
- "type": "string"
1350
- },
1351
- {
1352
- "type": "string",
1353
- "enum": [
1354
- "json"
1355
- ]
1356
- }
1357
- ],
1358
- "description": "Represents a string value with autocompleted, but not required, suggestions."
1359
- },
1360
754
  "OllamaLLMService": {
1361
755
  "type": "object",
1362
756
  "additionalProperties": false,
@@ -1371,321 +765,321 @@ const schema$1 = {
1371
765
  "type": "string"
1372
766
  },
1373
767
  "fields": {
1374
- "anyOf": [
1375
- {
1376
- "type": "object",
1377
- "additionalProperties": false,
1378
- "properties": {
1379
- "verbose": {
1380
- "type": "boolean"
1381
- },
1382
- "callbacks": {
1383
- "$ref": "#/definitions/Callbacks"
1384
- },
1385
- "tags": {
1386
- "type": "array",
1387
- "items": {
1388
- "type": "string"
1389
- }
1390
- },
1391
- "metadata": {
1392
- "type": "object",
1393
- "additionalProperties": {}
1394
- },
1395
- "maxConcurrency": {
1396
- "type": "number",
1397
- "description": "The maximum number of concurrent calls that can be made. Defaults to `Infinity`, which means no limit."
1398
- },
1399
- "maxRetries": {
1400
- "type": "number",
1401
- "description": "The maximum number of retries that can be made for a single call, with an exponential backoff between each attempt. Defaults to 6."
1402
- },
1403
- "onFailedAttempt": {
1404
- "$ref": "#/definitions/FailedAttemptHandler",
1405
- "description": "Custom handler to handle failed attempts. Takes the originally thrown error object as input, and should itself throw an error if the input error is not retryable."
1406
- },
1407
- "callbackManager": {
1408
- "$ref": "#/definitions/CallbackManager",
1409
- "deprecated": "Use `callbacks` instead"
1410
- },
1411
- "cache": {
1412
- "anyOf": [
1413
- {
1414
- "$ref": "#/definitions/BaseCache"
1415
- },
1416
- {
1417
- "type": "boolean"
1418
- }
1419
- ]
1420
- },
1421
- "concurrency": {
1422
- "type": "number",
1423
- "deprecated": "Use `maxConcurrency` instead"
1424
- },
1425
- "bestOf": {
1426
- "type": "number",
1427
- "description": "Generates `bestOf` completions server side and returns the \"best\""
1428
- },
1429
- "batchSize": {
1430
- "type": "number",
1431
- "description": "Batch size to use when passing multiple documents to generate"
1432
- },
1433
- "temperature": {
1434
- "type": "number",
1435
- "description": "Sampling temperature to use"
1436
- },
1437
- "maxTokens": {
1438
- "type": "number",
1439
- "description": "Maximum number of tokens to generate in the completion. -1 returns as many tokens as possible given the prompt and the model's maximum context size."
1440
- },
1441
- "topP": {
1442
- "type": "number",
1443
- "description": "Total probability mass of tokens to consider at each step"
1444
- },
1445
- "frequencyPenalty": {
1446
- "type": "number",
1447
- "description": "Penalizes repeated tokens according to frequency"
1448
- },
1449
- "presencePenalty": {
1450
- "type": "number",
1451
- "description": "Penalizes repeated tokens"
1452
- },
1453
- "n": {
1454
- "type": "number",
1455
- "description": "Number of completions to generate for each prompt"
1456
- },
1457
- "logitBias": {
1458
- "type": "object",
1459
- "additionalProperties": {
1460
- "type": "number"
1461
- },
1462
- "description": "Dictionary used to adjust the probability of specific tokens being generated"
1463
- },
1464
- "user": {
1465
- "type": "string",
1466
- "description": "Unique string identifier representing your end-user, which can help OpenAI to monitor and detect abuse."
1467
- },
1468
- "streaming": {
1469
- "type": "boolean",
1470
- "description": "Whether to stream the results or not. Enabling disables tokenUsage reporting"
1471
- },
1472
- "streamUsage": {
1473
- "type": "boolean",
1474
- "description": "Whether or not to include token usage data in streamed chunks.",
1475
- "default": true
1476
- },
1477
- "modelName": {
1478
- "type": "string",
1479
- "description": "Model name to use Alias for `model`"
1480
- },
1481
- "model": {
1482
- "type": "string",
1483
- "description": "Model name to use"
1484
- },
1485
- "modelKwargs": {
1486
- "type": "object",
1487
- "description": "Holds any additional parameters that are valid to pass to {@link * https://platform.openai.com/docs/api-reference/completions/create | } * `openai.createCompletion`} that are not explicitly specified on this class."
1488
- },
1489
- "stop": {
1490
- "type": "array",
1491
- "items": {
1492
- "type": "string"
1493
- },
1494
- "description": "List of stop words to use when generating Alias for `stopSequences`"
1495
- },
1496
- "stopSequences": {
1497
- "type": "array",
1498
- "items": {
1499
- "type": "string"
1500
- },
1501
- "description": "List of stop words to use when generating"
1502
- },
1503
- "timeout": {
1504
- "type": "number",
1505
- "description": "Timeout to use when making requests to OpenAI."
1506
- },
1507
- "openAIApiKey": {
1508
- "type": "string",
1509
- "description": "API key to use when making requests to OpenAI. Defaults to the value of `OPENAI_API_KEY` environment variable. Alias for `apiKey`"
1510
- },
1511
- "apiKey": {
1512
- "type": "string",
1513
- "description": "API key to use when making requests to OpenAI. Defaults to the value of `OPENAI_API_KEY` environment variable."
1514
- }
768
+ "type": "object",
769
+ "additionalProperties": false,
770
+ "properties": {
771
+ "verbose": {
772
+ "type": "boolean"
773
+ },
774
+ "callbacks": {
775
+ "$ref": "#/definitions/Callbacks"
776
+ },
777
+ "tags": {
778
+ "type": "array",
779
+ "items": {
780
+ "type": "string"
1515
781
  }
1516
782
  },
1517
- {
783
+ "metadata": {
1518
784
  "type": "object",
1519
- "additionalProperties": false,
1520
- "properties": {
1521
- "verbose": {
1522
- "type": "boolean"
1523
- },
1524
- "callbacks": {
1525
- "$ref": "#/definitions/Callbacks"
1526
- },
1527
- "tags": {
1528
- "type": "array",
1529
- "items": {
1530
- "type": "string"
1531
- }
1532
- },
1533
- "metadata": {
1534
- "type": "object",
1535
- "additionalProperties": {}
1536
- },
1537
- "maxConcurrency": {
1538
- "type": "number",
1539
- "description": "The maximum number of concurrent calls that can be made. Defaults to `Infinity`, which means no limit."
1540
- },
1541
- "maxRetries": {
1542
- "type": "number",
1543
- "description": "The maximum number of retries that can be made for a single call, with an exponential backoff between each attempt. Defaults to 6."
1544
- },
1545
- "onFailedAttempt": {
1546
- "$ref": "#/definitions/FailedAttemptHandler",
1547
- "description": "Custom handler to handle failed attempts. Takes the originally thrown error object as input, and should itself throw an error if the input error is not retryable."
1548
- },
1549
- "callbackManager": {
1550
- "$ref": "#/definitions/CallbackManager",
1551
- "deprecated": "Use `callbacks` instead"
1552
- },
1553
- "cache": {
1554
- "anyOf": [
1555
- {
1556
- "$ref": "#/definitions/BaseCache"
1557
- },
1558
- {
1559
- "type": "boolean"
1560
- }
1561
- ]
1562
- },
1563
- "concurrency": {
1564
- "type": "number",
1565
- "deprecated": "Use `maxConcurrency` instead"
1566
- },
1567
- "embeddingOnly": {
1568
- "type": "boolean"
1569
- },
1570
- "f16KV": {
1571
- "type": "boolean"
1572
- },
1573
- "frequencyPenalty": {
1574
- "type": "number"
1575
- },
1576
- "headers": {
1577
- "type": "object",
1578
- "additionalProperties": {
1579
- "type": "string"
1580
- }
1581
- },
1582
- "keepAlive": {
1583
- "type": "string"
1584
- },
1585
- "logitsAll": {
1586
- "type": "boolean"
1587
- },
1588
- "lowVram": {
1589
- "type": "boolean"
1590
- },
1591
- "mainGpu": {
1592
- "type": "number"
1593
- },
1594
- "model": {
1595
- "type": "string"
1596
- },
1597
- "baseUrl": {
1598
- "type": "string"
1599
- },
1600
- "mirostat": {
1601
- "type": "number"
1602
- },
1603
- "mirostatEta": {
1604
- "type": "number"
1605
- },
1606
- "mirostatTau": {
1607
- "type": "number"
1608
- },
1609
- "numBatch": {
1610
- "type": "number"
1611
- },
1612
- "numCtx": {
1613
- "type": "number"
1614
- },
1615
- "numGpu": {
1616
- "type": "number"
1617
- },
1618
- "numGqa": {
1619
- "type": "number"
1620
- },
1621
- "numKeep": {
1622
- "type": "number"
1623
- },
1624
- "numPredict": {
1625
- "type": "number"
1626
- },
1627
- "numThread": {
1628
- "type": "number"
785
+ "additionalProperties": {}
786
+ },
787
+ "maxConcurrency": {
788
+ "type": "number",
789
+ "description": "The maximum number of concurrent calls that can be made. Defaults to `Infinity`, which means no limit."
790
+ },
791
+ "maxRetries": {
792
+ "type": "number",
793
+ "description": "The maximum number of retries that can be made for a single call, with an exponential backoff between each attempt. Defaults to 6."
794
+ },
795
+ "onFailedAttempt": {
796
+ "$ref": "#/definitions/FailedAttemptHandler",
797
+ "description": "Custom handler to handle failed attempts. Takes the originally thrown error object as input, and should itself throw an error if the input error is not retryable."
798
+ },
799
+ "callbackManager": {
800
+ "$ref": "#/definitions/CallbackManager",
801
+ "deprecated": "Use `callbacks` instead"
802
+ },
803
+ "cache": {
804
+ "anyOf": [
805
+ {
806
+ "$ref": "#/definitions/BaseCache"
1629
807
  },
1630
- "penalizeNewline": {
1631
- "type": "boolean"
1632
- },
1633
- "presencePenalty": {
1634
- "type": "number"
1635
- },
1636
- "repeatLastN": {
1637
- "type": "number"
1638
- },
1639
- "repeatPenalty": {
1640
- "type": "number"
1641
- },
1642
- "ropeFrequencyBase": {
1643
- "type": "number"
1644
- },
1645
- "ropeFrequencyScale": {
1646
- "type": "number"
1647
- },
1648
- "temperature": {
1649
- "type": "number"
1650
- },
1651
- "stop": {
1652
- "type": "array",
1653
- "items": {
1654
- "type": "string"
1655
- }
1656
- },
1657
- "tfsZ": {
1658
- "type": "number"
1659
- },
1660
- "topK": {
1661
- "type": "number"
1662
- },
1663
- "topP": {
1664
- "type": "number"
1665
- },
1666
- "typicalP": {
1667
- "type": "number"
1668
- },
1669
- "useMLock": {
808
+ {
1670
809
  "type": "boolean"
810
+ }
811
+ ]
812
+ },
813
+ "concurrency": {
814
+ "type": "number",
815
+ "deprecated": "Use `maxConcurrency` instead"
816
+ },
817
+ "embeddingOnly": {
818
+ "type": "boolean"
819
+ },
820
+ "f16KV": {
821
+ "type": "boolean"
822
+ },
823
+ "frequencyPenalty": {
824
+ "type": "number"
825
+ },
826
+ "headers": {
827
+ "type": "object",
828
+ "additionalProperties": {
829
+ "type": "string"
830
+ }
831
+ },
832
+ "keepAlive": {
833
+ "type": "string"
834
+ },
835
+ "logitsAll": {
836
+ "type": "boolean"
837
+ },
838
+ "lowVram": {
839
+ "type": "boolean"
840
+ },
841
+ "mainGpu": {
842
+ "type": "number"
843
+ },
844
+ "model": {
845
+ "type": "string"
846
+ },
847
+ "baseUrl": {
848
+ "type": "string"
849
+ },
850
+ "mirostat": {
851
+ "type": "number"
852
+ },
853
+ "mirostatEta": {
854
+ "type": "number"
855
+ },
856
+ "mirostatTau": {
857
+ "type": "number"
858
+ },
859
+ "numBatch": {
860
+ "type": "number"
861
+ },
862
+ "numCtx": {
863
+ "type": "number"
864
+ },
865
+ "numGpu": {
866
+ "type": "number"
867
+ },
868
+ "numGqa": {
869
+ "type": "number"
870
+ },
871
+ "numKeep": {
872
+ "type": "number"
873
+ },
874
+ "numPredict": {
875
+ "type": "number"
876
+ },
877
+ "numThread": {
878
+ "type": "number"
879
+ },
880
+ "penalizeNewline": {
881
+ "type": "boolean"
882
+ },
883
+ "presencePenalty": {
884
+ "type": "number"
885
+ },
886
+ "repeatLastN": {
887
+ "type": "number"
888
+ },
889
+ "repeatPenalty": {
890
+ "type": "number"
891
+ },
892
+ "ropeFrequencyBase": {
893
+ "type": "number"
894
+ },
895
+ "ropeFrequencyScale": {
896
+ "type": "number"
897
+ },
898
+ "temperature": {
899
+ "type": "number"
900
+ },
901
+ "stop": {
902
+ "type": "array",
903
+ "items": {
904
+ "type": "string"
905
+ }
906
+ },
907
+ "tfsZ": {
908
+ "type": "number"
909
+ },
910
+ "topK": {
911
+ "type": "number"
912
+ },
913
+ "topP": {
914
+ "type": "number"
915
+ },
916
+ "typicalP": {
917
+ "type": "number"
918
+ },
919
+ "useMLock": {
920
+ "type": "boolean"
921
+ },
922
+ "useMMap": {
923
+ "type": "boolean"
924
+ },
925
+ "vocabOnly": {
926
+ "type": "boolean"
927
+ },
928
+ "format": {
929
+ "$ref": "#/definitions/StringWithAutocomplete%3C%22json%22%3E"
930
+ }
931
+ }
932
+ },
933
+ "tokenLimit": {
934
+ "type": "number",
935
+ "description": "The maximum number of tokens per request.",
936
+ "default": 2048
937
+ },
938
+ "temperature": {
939
+ "type": "number",
940
+ "description": "The temperature value controls the randomness of the generated output. Higher values (e.g., 0.8) make the output more random, while lower values (e.g., 0.2) make it more deterministic.",
941
+ "default": 0.4
942
+ },
943
+ "maxConcurrent": {
944
+ "type": "number",
945
+ "description": "The maximum number of requests to make concurrently.",
946
+ "default": 6
947
+ },
948
+ "authentication": {
949
+ "anyOf": [
950
+ {
951
+ "type": "object",
952
+ "properties": {
953
+ "type": {
954
+ "type": "string",
955
+ "const": "None"
1671
956
  },
1672
- "useMMap": {
1673
- "type": "boolean"
957
+ "credentials": {
958
+ "not": {}
959
+ }
960
+ },
961
+ "required": [
962
+ "type"
963
+ ],
964
+ "additionalProperties": false
965
+ },
966
+ {
967
+ "type": "object",
968
+ "properties": {
969
+ "type": {
970
+ "type": "string",
971
+ "const": "OAuth"
1674
972
  },
1675
- "vocabOnly": {
1676
- "type": "boolean"
973
+ "credentials": {
974
+ "type": "object",
975
+ "properties": {
976
+ "clientId": {
977
+ "type": "string"
978
+ },
979
+ "clientSecret": {
980
+ "type": "string"
981
+ },
982
+ "token": {
983
+ "type": "string"
984
+ }
985
+ },
986
+ "additionalProperties": false
987
+ }
988
+ },
989
+ "required": [
990
+ "type",
991
+ "credentials"
992
+ ],
993
+ "additionalProperties": false
994
+ },
995
+ {
996
+ "type": "object",
997
+ "properties": {
998
+ "type": {
999
+ "type": "string",
1000
+ "const": "APIKey"
1677
1001
  },
1678
- "format": {
1679
- "$ref": "#/definitions/StringWithAutocomplete%3C%22json%22%3E"
1002
+ "credentials": {
1003
+ "type": "object",
1004
+ "properties": {
1005
+ "apiKey": {
1006
+ "type": "string"
1007
+ }
1008
+ },
1009
+ "required": [
1010
+ "apiKey"
1011
+ ],
1012
+ "additionalProperties": false
1680
1013
  }
1681
- }
1014
+ },
1015
+ "required": [
1016
+ "type",
1017
+ "credentials"
1018
+ ],
1019
+ "additionalProperties": false
1020
+ }
1021
+ ]
1022
+ },
1023
+ "requestOptions": {
1024
+ "type": "object",
1025
+ "properties": {
1026
+ "timeout": {
1027
+ "type": "number"
1028
+ },
1029
+ "maxRetries": {
1030
+ "type": "number"
1682
1031
  }
1032
+ },
1033
+ "additionalProperties": false
1034
+ }
1035
+ },
1036
+ "required": [
1037
+ "authentication",
1038
+ "endpoint",
1039
+ "model",
1040
+ "provider"
1041
+ ]
1042
+ },
1043
+ "StringWithAutocomplete<\"json\">": {
1044
+ "anyOf": [
1045
+ {
1046
+ "type": "string"
1047
+ },
1048
+ {
1049
+ "type": "string",
1050
+ "enum": [
1051
+ "json"
1683
1052
  ]
1053
+ }
1054
+ ],
1055
+ "description": "Represents a string value with autocompleted, but not required, suggestions."
1056
+ },
1057
+ "AnthropicLLMService": {
1058
+ "type": "object",
1059
+ "additionalProperties": false,
1060
+ "properties": {
1061
+ "provider": {
1062
+ "$ref": "#/definitions/LLMProvider"
1063
+ },
1064
+ "model": {
1065
+ "$ref": "#/definitions/LLMModel"
1066
+ },
1067
+ "fields": {
1068
+ "type": "object",
1069
+ "properties": {
1070
+ "temperature": {
1071
+ "type": "number"
1072
+ },
1073
+ "maxTokens": {
1074
+ "type": "number"
1075
+ }
1076
+ },
1077
+ "additionalProperties": false
1684
1078
  },
1685
1079
  "tokenLimit": {
1686
1080
  "type": "number",
1687
1081
  "description": "The maximum number of tokens per request.",
1688
- "default": 1024
1082
+ "default": 2048
1689
1083
  },
1690
1084
  "temperature": {
1691
1085
  "type": "number",
@@ -1787,13 +1181,482 @@ const schema$1 = {
1787
1181
  },
1788
1182
  "required": [
1789
1183
  "authentication",
1790
- "endpoint",
1791
1184
  "model",
1792
1185
  "provider"
1793
1186
  ]
1794
1187
  }
1795
1188
  }
1796
- };
1189
+ };
1190
+
1191
+ const isInteractive = (config) => {
1192
+ return config?.mode === 'interactive' || !!config?.interactive;
1193
+ };
1194
+ const SEPERATOR = chalk.blue('─────────────');
1195
+ const DIVIDER = chalk.dim(`\\`);
1196
+ const LOGO = chalk.green(`┌──────┐
1197
+ │┏┏┓┏┏┓│
1198
+ │┗┗┛┗┗┛│
1199
+ └──────┘`);
1200
+ chalk.green(`┌────┐
1201
+ │coco│
1202
+ └────┘`);
1203
+ const bannerWithHeader = (banner) => {
1204
+ return chalk.green(`┌────┐
1205
+ │coco│ ${banner}
1206
+ └────┘`);
1207
+ };
1208
+ const USAGE_BANNER = chalk.green(`${LOGO}
1209
+ ${chalk.bgGreen(`\xa0v${BUILD_VERSION}\xa0`)}
1210
+ `);
1211
+ const getCommandUsageHeader = (command) => {
1212
+ return chalk.green(`${USAGE_BANNER}\n${chalk.white('Command:')}\n\xa0\xa0\xa0\xa0\xa0 $0 ${chalk.greenBright(command)} [options]`);
1213
+ };
1214
+ const CONFIG_ALREADY_EXISTS = (path) => {
1215
+ return `existing config found in '${path}', do you want to override it?`;
1216
+ };
1217
+ const severityColors = [
1218
+ chalk.greenBright, // 1
1219
+ chalk.green, // 2
1220
+ chalk.cyan, // 3
1221
+ chalk.yellowBright, // 4
1222
+ chalk.yellow, // 5
1223
+ chalk.bgYellow, // 6
1224
+ chalk.red, // 7
1225
+ chalk.redBright, // 8
1226
+ chalk.bgRed, // 9
1227
+ chalk.bgRedBright, // 10
1228
+ ];
1229
+ const severityColor = (severity) => {
1230
+ return severityColors[Math.min(severity - 1, severityColors.length - 1)];
1231
+ };
1232
+ const statusColor = (status) => {
1233
+ switch (status) {
1234
+ case 'completed':
1235
+ return chalk.green;
1236
+ case 'skipped':
1237
+ return chalk.yellow;
1238
+ case 'omitted':
1239
+ return chalk.red;
1240
+ default:
1241
+ return chalk.blue;
1242
+ }
1243
+ };
1244
+ const hotKey = (key) => chalk.dim(`(${key})`);
1245
+
1246
+ /**
1247
+ * Returns a new object with all undefined keys removed
1248
+ *
1249
+ * @param obj Object to remove undefined keys from
1250
+ * @returns
1251
+ */
1252
+ function removeUndefined(obj) {
1253
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
1254
+ }
1255
+
1256
+ async function updateFileSection({ filePath, startComment, endComment, getNewContent, confirmUpdate = true, confirmMessage = (path) => `A section already exists in ${path}, do you want to override it?`, }) {
1257
+ const lines = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8').split(/\r?\n/) : [];
1258
+ const newLines = [];
1259
+ let foundSection = false;
1260
+ for (let i = 0; i < lines.length; i++) {
1261
+ if (lines[i].trim() === startComment) {
1262
+ foundSection = true;
1263
+ if (confirmUpdate) {
1264
+ const confirmOverwrite = await prompts.confirm({
1265
+ message: typeof confirmMessage === 'function' ? confirmMessage(filePath) : confirmMessage,
1266
+ default: false,
1267
+ });
1268
+ if (!confirmOverwrite) {
1269
+ // keep all lines until the end comment
1270
+ while (i < lines.length && lines[i].trim() !== endComment) {
1271
+ newLines.push(lines[i]);
1272
+ i++;
1273
+ }
1274
+ newLines.push(endComment);
1275
+ continue;
1276
+ }
1277
+ }
1278
+ newLines.push(startComment);
1279
+ // Insert the new content
1280
+ const newContent = await getNewContent();
1281
+ newLines.push(newContent);
1282
+ // Skip the existing content of the section
1283
+ while (i < lines.length && lines[i].trim() !== endComment) {
1284
+ i++;
1285
+ }
1286
+ newLines.push(endComment);
1287
+ continue;
1288
+ }
1289
+ if (!foundSection || lines[i].trim() !== endComment) {
1290
+ newLines.push(lines[i]);
1291
+ }
1292
+ }
1293
+ // If section wasn't found, append it at the end
1294
+ if (!foundSection) {
1295
+ newLines.push('\n' + startComment);
1296
+ const newContent = await getNewContent();
1297
+ newLines.push(newContent);
1298
+ newLines.push(endComment);
1299
+ }
1300
+ // Write the updated contents back to the file
1301
+ fs.writeFileSync(filePath, newLines.join('\n'));
1302
+ }
1303
+
1304
+ const template$5 = `GOAL: Use functional abstractions to summarize the following text
1305
+
1306
+ RULES: Avoid phrases like "this change", "this code", or "this function" etc. Instead refer to the function, variable, or class by name.
1307
+
1308
+ TEXT:"""{text}"""
1309
+ `;
1310
+ const inputVariables$4 = ['text'];
1311
+ const SUMMARIZE_PROMPT = new prompts$1.PromptTemplate({
1312
+ inputVariables: inputVariables$4,
1313
+ template: template$5,
1314
+ });
1315
+
1316
+ /**
1317
+ * Retrieves the provider and model from the given configuration object.
1318
+ * @param config The configuration object.
1319
+ * @returns An object containing the provider and model.
1320
+ * @throws Error if the configuration is invalid or missing required properties.
1321
+ */
1322
+ function getModelAndProviderFromConfig(config) {
1323
+ if (!config.service) {
1324
+ throw new Error('Invalid service: undefined');
1325
+ }
1326
+ const { provider, model } = config.service;
1327
+ if (!model || !provider) {
1328
+ throw new Error(`Invalid service: ${config.service}`);
1329
+ }
1330
+ return { provider, model };
1331
+ }
1332
+ /**
1333
+ * Retrieve appropriate API key based on selected model
1334
+ * @param service
1335
+ * @param options
1336
+ * @returns API Key
1337
+ */
1338
+ function getApiKeyForModel(config) {
1339
+ const { provider } = getModelAndProviderFromConfig(config);
1340
+ switch (provider) {
1341
+ case 'openai':
1342
+ return getDefaultServiceApiKey(config);
1343
+ default:
1344
+ return getDefaultServiceApiKey(config);
1345
+ }
1346
+ }
1347
+ /**
1348
+ * Retrieves the default service API key from the given configuration.
1349
+ * @param config The configuration object.
1350
+ * @returns The default service API key.
1351
+ */
1352
+ function getDefaultServiceApiKey(config) {
1353
+ const service = config.service;
1354
+ if (service.authentication.type === 'APIKey') {
1355
+ return service.authentication.credentials?.apiKey;
1356
+ }
1357
+ else if (service.authentication.type === 'OAuth') {
1358
+ return service.authentication.credentials?.token;
1359
+ }
1360
+ return '';
1361
+ }
1362
+ const DEFAULT_OPENAI_LLM_SERVICE = {
1363
+ provider: 'openai',
1364
+ model: 'gpt-4',
1365
+ tokenLimit: 2024,
1366
+ temperature: 0.32,
1367
+ authentication: {
1368
+ type: 'APIKey',
1369
+ credentials: {
1370
+ apiKey: '',
1371
+ },
1372
+ },
1373
+ };
1374
+ const DEFAULT_OLLAMA_LLM_SERVICE = {
1375
+ provider: 'ollama',
1376
+ model: 'llama3',
1377
+ endpoint: 'http://localhost:11434',
1378
+ maxConcurrent: 1,
1379
+ tokenLimit: 2024,
1380
+ temperature: 0.4,
1381
+ authentication: {
1382
+ type: 'None',
1383
+ credentials: undefined,
1384
+ },
1385
+ };
1386
+ /**
1387
+ * Retrieves the default service configuration based on the provided alias and optional model.
1388
+ * @param provider - The alias of the service.
1389
+ * @param model - The optional model to be used.
1390
+ * @returns The default service configuration.
1391
+ * @throws Error if the alias is invalid or undefined.
1392
+ */
1393
+ function getDefaultServiceConfigFromAlias(provider, model) {
1394
+ switch (provider) {
1395
+ case 'anthropic':
1396
+ return {
1397
+ ...DEFAULT_OPENAI_LLM_SERVICE,
1398
+ model: model || DEFAULT_OPENAI_LLM_SERVICE.model,
1399
+ };
1400
+ case 'ollama':
1401
+ return {
1402
+ ...DEFAULT_OLLAMA_LLM_SERVICE,
1403
+ model: model || DEFAULT_OLLAMA_LLM_SERVICE.model,
1404
+ };
1405
+ case 'openai':
1406
+ default:
1407
+ return {
1408
+ ...DEFAULT_OPENAI_LLM_SERVICE,
1409
+ model: model || DEFAULT_OPENAI_LLM_SERVICE.model,
1410
+ };
1411
+ }
1412
+ }
1413
+
1414
+ const DEFAULT_IGNORED_FILES = ['package-lock.json', 'yarn.lock', 'node_modules'];
1415
+ const DEFAULT_IGNORED_EXTENSIONS = ['.map', '.lock'];
1416
+ const COCO_CONFIG_START_COMMENT = '# -- start coco config --';
1417
+ const COCO_CONFIG_END_COMMENT = '# -- end coco config --';
1418
+ /**
1419
+ * Default Config
1420
+ *
1421
+ * @type {Config}
1422
+ */
1423
+ const DEFAULT_CONFIG$1 = {
1424
+ mode: 'stdout',
1425
+ verbose: false,
1426
+ defaultBranch: 'main',
1427
+ service: getDefaultServiceConfigFromAlias('openai'),
1428
+ summarizePrompt: SUMMARIZE_PROMPT.template,
1429
+ ignoredFiles: DEFAULT_IGNORED_FILES,
1430
+ ignoredExtensions: DEFAULT_IGNORED_EXTENSIONS,
1431
+ };
1432
+ /**
1433
+ * Create a named export of all config keys for use in other modules.
1434
+ *
1435
+ * @see Used in `src/lib/config/services/env.ts` to validate all env vars.
1436
+ *
1437
+ * @type {string[]}
1438
+ */
1439
+ const CONFIG_KEYS = Object.keys({
1440
+ ...DEFAULT_CONFIG$1,
1441
+ prompt: '',
1442
+ });
1443
+
1444
+ /**
1445
+ * Load environment variables
1446
+ *
1447
+ * @param {Config} config
1448
+ * @returns {Config} Updated config
1449
+ **/
1450
+ function loadEnvConfig(config) {
1451
+ const envConfig = {};
1452
+ const envKeys = [...CONFIG_KEYS, 'COCO_SERVICE_PROVIDER', 'COCO_SERVICE_MODEL', 'OPEN_AI_KEY'];
1453
+ envKeys.forEach((key) => {
1454
+ const envVarName = toEnvVarName(key);
1455
+ const envValue = parseEnvValue(key, process.env[envVarName]);
1456
+ if (envValue === undefined) {
1457
+ return;
1458
+ }
1459
+ if (key === 'COCO_SERVICE_PROVIDER' || key === 'COCO_SERVICE_MODEL' || key === 'OPEN_AI_KEY') {
1460
+ // NOTE: We want to ensure that the service object is always defined
1461
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1462
+ // @ts-ignore
1463
+ envConfig.service = envConfig.service || {};
1464
+ handleServiceEnvVar(envConfig.service, key, envValue);
1465
+ }
1466
+ else {
1467
+ if (key === 'service' || !envValue) {
1468
+ return;
1469
+ }
1470
+ envConfig[key] = envValue;
1471
+ }
1472
+ });
1473
+ return { ...config, ...removeUndefined(envConfig) };
1474
+ }
1475
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1476
+ function handleServiceEnvVar(service, key, value) {
1477
+ switch (key) {
1478
+ case 'COCO_SERVICE_PROVIDER':
1479
+ service.provider = value;
1480
+ break;
1481
+ case 'COCO_SERVICE_MODEL':
1482
+ service.model = value;
1483
+ break;
1484
+ case 'OPEN_AI_KEY':
1485
+ if (service.provider === 'openai') {
1486
+ service.fields = { apiKey: value };
1487
+ }
1488
+ break;
1489
+ }
1490
+ }
1491
+ function parseEnvValue(key, value) {
1492
+ switch (true) {
1493
+ // Handle undefined values
1494
+ case value === undefined:
1495
+ return undefined;
1496
+ // Handle comma separated strings for ignoredFiles and ignoredExtensions arrays
1497
+ case (key === 'ignoredFiles' || key === 'ignoredExtensions') &&
1498
+ typeof value === 'string' &&
1499
+ value.includes(','):
1500
+ return value.split(',');
1501
+ // Handle boolean values
1502
+ case typeof value === 'string' && (value === 'false' || value === 'true'):
1503
+ return value === 'true';
1504
+ // Handle number values
1505
+ case typeof value === 'string' && !isNaN(Number(value)):
1506
+ return Number(value);
1507
+ default:
1508
+ return value;
1509
+ }
1510
+ }
1511
+ function toEnvVarName(key) {
1512
+ if (key === 'service') {
1513
+ return key;
1514
+ }
1515
+ if (key.includes('COCO_')) {
1516
+ return key;
1517
+ }
1518
+ return `COCO_${key.replace(/([A-Z])/g, '_$1').toLocaleUpperCase()}`;
1519
+ }
1520
+ function formatEnvValue(value) {
1521
+ if (typeof value === 'number') {
1522
+ return `${value}`;
1523
+ }
1524
+ else if (Array.isArray(value)) {
1525
+ return `${value.join(',')}`;
1526
+ }
1527
+ else if (typeof value === 'string') {
1528
+ // Escape newlines and tabs in strings
1529
+ return `${value.replace(/\n/g, '\\n').replace(/\t/g, '\\t')}`;
1530
+ }
1531
+ return `${value}`;
1532
+ }
1533
+ const appendToEnvFile = async (filePath, config) => {
1534
+ const getNewContent = async () => {
1535
+ return Object.entries(config)
1536
+ .map(([key, value]) => {
1537
+ if (key === 'service') {
1538
+ const service = value;
1539
+ return `${service.provider ? `COCO_SERVICE_PROVIDER=${service.provider}` : ''}\n${service.model ? `COCO_SERVICE_MODEL=${service.model}` : ''}\n${service.authentication.type === 'APIKey'
1540
+ ? `OPEN_AI_KEY=${service.authentication.credentials.apiKey}`
1541
+ : ''}`;
1542
+ }
1543
+ const envVarName = toEnvVarName(key);
1544
+ const envValue = formatEnvValue(value);
1545
+ return `${envVarName}=${envValue}`;
1546
+ })
1547
+ .join('\n');
1548
+ };
1549
+ await updateFileSection({
1550
+ filePath,
1551
+ startComment: COCO_CONFIG_START_COMMENT,
1552
+ endComment: COCO_CONFIG_END_COMMENT,
1553
+ getNewContent,
1554
+ confirmMessage: CONFIG_ALREADY_EXISTS,
1555
+ });
1556
+ };
1557
+
1558
+ /**
1559
+ * Load git profile config (from ~/.gitconfig)
1560
+ *
1561
+ * @param {Config} config
1562
+ * @returns {Config} Updated config
1563
+ **/
1564
+ function loadGitConfig(config) {
1565
+ const gitConfigPath = path__namespace.join(os__namespace.homedir(), '.gitconfig');
1566
+ if (fs__namespace.existsSync(gitConfigPath)) {
1567
+ const gitConfigRaw = fs__namespace.readFileSync(gitConfigPath, 'utf-8');
1568
+ const gitConfigParsed = ini__namespace.parse(gitConfigRaw);
1569
+ const gitConfigServiceObject = gitConfigParsed.coco?.service;
1570
+ let service = config.service;
1571
+ if (gitConfigServiceObject) {
1572
+ const gitServiceConfig = JSON.parse(gitConfigServiceObject);
1573
+ service = gitServiceConfig || config?.service;
1574
+ }
1575
+ config = {
1576
+ ...config,
1577
+ service: service,
1578
+ prompt: gitConfigParsed.coco?.prompt || config.prompt,
1579
+ mode: gitConfigParsed.coco?.mode || config.mode,
1580
+ summarizePrompt: gitConfigParsed.coco?.summarizePrompt || config.summarizePrompt,
1581
+ ignoredFiles: gitConfigParsed.coco?.ignoredFiles || config.ignoredFiles,
1582
+ ignoredExtensions: gitConfigParsed.coco?.ignoredExtensions || config.ignoredExtensions,
1583
+ defaultBranch: gitConfigParsed.coco?.defaultBranch || config.defaultBranch,
1584
+ verbose: gitConfigParsed.coco?.verbose || config.verbose,
1585
+ };
1586
+ }
1587
+ return removeUndefined(config);
1588
+ }
1589
+ /**
1590
+ * Appends the provided configuration to a git config file.
1591
+ *
1592
+ * @param filePath - The path to the .gitconfig
1593
+ * @param config - The configuration object to append.
1594
+ */
1595
+ const appendToGitConfig = async (filePath, config) => {
1596
+ if (!fs__namespace.existsSync(filePath)) {
1597
+ throw new Error(`File ${filePath} does not exist.`);
1598
+ }
1599
+ const header = '[coco]';
1600
+ const getNewContent = async () => {
1601
+ const contentLines = [header];
1602
+ for (const key in config) {
1603
+ const value = config[key];
1604
+ if (typeof value === 'object') {
1605
+ // Serialize object to JSON string
1606
+ contentLines.push(`\t${key} = ${JSON.stringify(value)}`);
1607
+ }
1608
+ else if (typeof value === 'string' && value.includes('\n')) {
1609
+ // Wrap strings with new lines in quotes
1610
+ contentLines.push(`\t${key} = ${JSON.stringify(value)}`);
1611
+ }
1612
+ else {
1613
+ contentLines.push(`\t${key} = ${value}`);
1614
+ }
1615
+ }
1616
+ return contentLines.join('\n');
1617
+ };
1618
+ await updateFileSection({
1619
+ filePath,
1620
+ startComment: COCO_CONFIG_START_COMMENT,
1621
+ endComment: COCO_CONFIG_END_COMMENT,
1622
+ getNewContent,
1623
+ confirmUpdate: true,
1624
+ confirmMessage: CONFIG_ALREADY_EXISTS,
1625
+ });
1626
+ };
1627
+
1628
+ /**
1629
+ * Load .gitignore in project root
1630
+ *
1631
+ * @param {Config} config
1632
+ * @returns
1633
+ */
1634
+ function loadGitignore(config) {
1635
+ if (fs__namespace.existsSync('.gitignore')) {
1636
+ const gitignoreContent = fs__namespace.readFileSync('.gitignore', 'utf-8');
1637
+ config.ignoredFiles = [
1638
+ ...(config?.ignoredFiles || []),
1639
+ ...gitignoreContent.split('\n').filter((line) => line.trim() !== '' && !line.startsWith('#')),
1640
+ ];
1641
+ }
1642
+ return config;
1643
+ }
1644
+ /**
1645
+ * Load .ignore in project root
1646
+ *
1647
+ * @param {Config} config
1648
+ * @returns
1649
+ */
1650
+ function loadIgnore(config) {
1651
+ if (fs__namespace.existsSync('.ignore')) {
1652
+ const ignoreContent = fs__namespace.readFileSync('.ignore', 'utf-8');
1653
+ config.ignoredFiles = [
1654
+ ...(config?.ignoredFiles || []),
1655
+ ...ignoreContent.split('\n').filter((line) => line.trim() !== '' && !line.startsWith('#')),
1656
+ ];
1657
+ }
1658
+ return config;
1659
+ }
1797
1660
 
1798
1661
  const ajv = new Ajv({
1799
1662
  allErrors: true,
@@ -1867,6 +1730,18 @@ function parseServiceConfig(service) {
1867
1730
  }
1868
1731
  }
1869
1732
  };
1733
+ case 'anthropic':
1734
+ return {
1735
+ provider: 'anthropic',
1736
+ model: service.model,
1737
+ authentication: {
1738
+ type: 'APIKey',
1739
+ credentials: {
1740
+ apiKey: service.apiKey
1741
+ }
1742
+ },
1743
+ fields: service.fields
1744
+ };
1870
1745
  case 'ollama':
1871
1746
  return {
1872
1747
  provider: 'ollama',
@@ -1975,6 +1850,31 @@ function commandExecutor(handler) {
1975
1850
  };
1976
1851
  }
1977
1852
 
1853
+ const command$4 = 'changelog';
1854
+ /**
1855
+ * Command line options via yargs
1856
+ */
1857
+ const options$4 = {
1858
+ range: {
1859
+ type: 'string',
1860
+ alias: 'r',
1861
+ description: 'Commit range e.g `HEAD~2:HEAD`',
1862
+ },
1863
+ branch: {
1864
+ type: 'string',
1865
+ alias: 'b',
1866
+ description: 'Target branch to compare against',
1867
+ },
1868
+ i: {
1869
+ type: 'boolean',
1870
+ alias: 'interactive',
1871
+ description: 'Toggle interactive mode',
1872
+ },
1873
+ };
1874
+ const builder$4 = (yargs) => {
1875
+ return yargs.options(options$4).usage(getCommandUsageHeader(command$4));
1876
+ };
1877
+
1978
1878
  /**
1979
1879
  * Get LLM Model Based on Configuration
1980
1880
  *
@@ -2513,36 +2413,47 @@ const handler$4 = async (argv, logger) => {
2513
2413
  });
2514
2414
  };
2515
2415
 
2416
+ var changelog = {
2417
+ command: command$4,
2418
+ desc: 'Generate a changelog from current or target branch or provided commit range.',
2419
+ builder: builder$4,
2420
+ handler: commandExecutor(handler$4),
2421
+ options: options$4,
2422
+ };
2423
+
2424
+ const command$3 = 'commit';
2516
2425
  /**
2517
2426
  * Command line options via yargs
2518
2427
  */
2519
- const options$4 = {
2520
- range: {
2521
- type: 'string',
2522
- alias: 'r',
2523
- description: 'Commit range e.g `HEAD~2:HEAD`',
2428
+ const options$3 = {
2429
+ i: {
2430
+ alias: 'interactive',
2431
+ description: 'Toggle interactive mode',
2432
+ type: 'boolean',
2524
2433
  },
2525
- branch: {
2434
+ ignoredFiles: {
2435
+ description: 'Ignored files',
2436
+ type: 'array',
2437
+ },
2438
+ ignoredExtensions: {
2439
+ description: 'Ignored extensions',
2440
+ type: 'array',
2441
+ },
2442
+ append: {
2443
+ description: 'Add content to the end of the generated commit message',
2526
2444
  type: 'string',
2527
- alias: 'b',
2528
- description: 'Target branch to compare against',
2529
2445
  },
2530
- i: {
2446
+ appendTicket: {
2447
+ description: 'Append ticket ID from branch name to the commit message',
2531
2448
  type: 'boolean',
2532
- alias: 'interactive',
2533
- description: 'Toggle interactive mode',
2449
+ },
2450
+ additional: {
2451
+ description: 'Add extra contextual information to the prompt',
2452
+ type: 'string',
2534
2453
  },
2535
2454
  };
2536
- const builder$4 = (yargs) => {
2537
- return yargs.options(options$4).usage(getCommandUsageHeader(changelog.command));
2538
- };
2539
-
2540
- var changelog = {
2541
- command: 'changelog',
2542
- desc: 'Generate a changelog from current or target branch or provided commit range.',
2543
- builder: builder$4,
2544
- handler: commandExecutor(handler$4),
2545
- options: options$4,
2455
+ const builder$3 = (yargs) => {
2456
+ return yargs.options(options$3).usage(getCommandUsageHeader(command$3));
2546
2457
  };
2547
2458
 
2548
2459
  /**
@@ -6344,7 +6255,13 @@ const handler$3 = async (argv, logger) => {
6344
6255
  logger.log(LOGO);
6345
6256
  }
6346
6257
  async function factory() {
6347
- const changes = await getChanges({ git });
6258
+ const changes = await getChanges({
6259
+ git,
6260
+ options: {
6261
+ ignoredFiles: config.ignoredFiles || undefined,
6262
+ ignoredExtensions: config.ignoredExtensions || undefined,
6263
+ },
6264
+ });
6348
6265
  return changes.staged;
6349
6266
  }
6350
6267
  async function parser(changes) {
@@ -6414,46 +6331,27 @@ const handler$3 = async (argv, logger) => {
6414
6331
  });
6415
6332
  };
6416
6333
 
6334
+ var commit = {
6335
+ command: command$3,
6336
+ desc: 'Summarize the staged changes in a commit message.',
6337
+ builder: builder$3,
6338
+ handler: commandExecutor(handler$3),
6339
+ options: options$3,
6340
+ };
6341
+
6342
+ const command$2 = 'init';
6417
6343
  /**
6418
6344
  * Command line options via yargs
6419
6345
  */
6420
- const options$3 = {
6421
- i: {
6422
- alias: 'interactive',
6423
- description: 'Toggle interactive mode',
6424
- type: 'boolean',
6425
- },
6426
- ignoredFiles: {
6427
- description: 'Ignored files',
6428
- type: 'array',
6429
- },
6430
- ignoredExtensions: {
6431
- description: 'Ignored extensions',
6432
- type: 'array',
6433
- },
6434
- append: {
6435
- description: 'Add content to the end of the generated commit message',
6436
- type: 'string',
6437
- },
6438
- appendTicket: {
6439
- description: 'Append ticket ID from branch name to the commit message',
6440
- type: 'boolean',
6441
- },
6442
- additional: {
6443
- description: 'Add extra contextual information to the prompt',
6346
+ const options$2 = {
6347
+ scope: {
6444
6348
  type: 'string',
6349
+ description: 'configure coco for the current user or project?',
6350
+ choices: ['global', 'project'],
6445
6351
  },
6446
6352
  };
6447
- const builder$3 = (yargs) => {
6448
- return yargs.options(options$3).usage(getCommandUsageHeader(commit.command));
6449
- };
6450
-
6451
- var commit = {
6452
- command: 'commit',
6453
- desc: 'Summarize the staged changes in a commit message.',
6454
- builder: builder$3,
6455
- handler: commandExecutor(handler$3),
6456
- options: options$3,
6353
+ const builder$2 = (yargs) => {
6354
+ return yargs.options(options$2).usage(getCommandUsageHeader(command$2));
6457
6355
  };
6458
6356
 
6459
6357
  /**
@@ -6889,28 +6787,48 @@ const handler$2 = async (argv, logger) => {
6889
6787
  }
6890
6788
  };
6891
6789
 
6892
- /**
6893
- * Command line options via yargs
6894
- */
6895
- const options$2 = {
6896
- scope: {
6897
- type: 'string',
6898
- description: 'configure coco for the current user or project?',
6899
- choices: ['global', 'project'],
6900
- },
6901
- };
6902
- const builder$2 = (yargs) => {
6903
- return yargs.options(options$2).usage(getCommandUsageHeader(init.command));
6904
- };
6905
-
6906
6790
  var init = {
6907
- command: 'init',
6791
+ command: command$2,
6908
6792
  desc: 'install & configure coco globally or for the current project',
6909
6793
  builder: builder$2,
6910
6794
  handler: commandExecutor(handler$2),
6911
6795
  options: options$2,
6912
6796
  };
6913
6797
 
6798
+ const command$1 = 'recap';
6799
+ /**
6800
+ * Command line options via yargs
6801
+ */
6802
+ const options$1 = {
6803
+ yesterday: {
6804
+ type: 'boolean',
6805
+ description: 'Recap for yesterday',
6806
+ },
6807
+ 'last-week': {
6808
+ alias: 'week',
6809
+ type: 'boolean',
6810
+ description: 'Recap for last week',
6811
+ },
6812
+ 'last-month': {
6813
+ alias: 'month',
6814
+ type: 'boolean',
6815
+ description: 'Recap for last month',
6816
+ },
6817
+ 'last-tag': {
6818
+ alias: 'tag',
6819
+ type: 'boolean',
6820
+ description: 'Recap for last tag',
6821
+ },
6822
+ i: {
6823
+ type: 'boolean',
6824
+ alias: 'interactive',
6825
+ description: 'Toggle interactive mode',
6826
+ },
6827
+ };
6828
+ const builder$1 = (yargs) => {
6829
+ return yargs.options(options$1).usage(getCommandUsageHeader(command$1));
6830
+ };
6831
+
6914
6832
  /**
6915
6833
  * Formats a commit log into a readable string format.
6916
6834
  *
@@ -7089,45 +7007,32 @@ const handler$1 = async (argv, logger) => {
7089
7007
  });
7090
7008
  };
7091
7009
 
7010
+ var recap = {
7011
+ command: command$1,
7012
+ desc: 'Summarize the changes in the repository over a specified timeframe.',
7013
+ builder: builder$1,
7014
+ handler: commandExecutor(handler$1),
7015
+ options: options$1,
7016
+ };
7017
+
7018
+ const command = 'review';
7092
7019
  /**
7093
7020
  * Command line options via yargs
7094
7021
  */
7095
- const options$1 = {
7096
- yesterday: {
7097
- type: 'boolean',
7098
- description: 'Recap for yesterday',
7099
- },
7100
- 'last-week': {
7101
- alias: 'week',
7102
- type: 'boolean',
7103
- description: 'Recap for last week',
7104
- },
7105
- 'last-month': {
7106
- alias: 'month',
7107
- type: 'boolean',
7108
- description: 'Recap for last month',
7109
- },
7110
- 'last-tag': {
7111
- alias: 'tag',
7112
- type: 'boolean',
7113
- description: 'Recap for last tag',
7114
- },
7022
+ const options = {
7115
7023
  i: {
7116
7024
  type: 'boolean',
7117
7025
  alias: 'interactive',
7118
7026
  description: 'Toggle interactive mode',
7119
7027
  },
7028
+ 'b': {
7029
+ type: 'string',
7030
+ alias: 'branch',
7031
+ description: 'Branch to review',
7032
+ },
7120
7033
  };
7121
- const builder$1 = (yargs) => {
7122
- return yargs.options(options$1).usage(getCommandUsageHeader(recap.command));
7123
- };
7124
-
7125
- var recap = {
7126
- command: 'recap',
7127
- desc: 'Summarize the changes in the repository over a specified timeframe.',
7128
- builder: builder$1,
7129
- handler: commandExecutor(handler$1),
7130
- options: options$1,
7034
+ const builder = (yargs) => {
7035
+ return yargs.options(options).usage(getCommandUsageHeader(command));
7131
7036
  };
7132
7037
 
7133
7038
  /**
@@ -28444,27 +28349,8 @@ const handler = async (argv, logger) => {
28444
28349
  await reviewer.start();
28445
28350
  };
28446
28351
 
28447
- /**
28448
- * Command line options via yargs
28449
- */
28450
- const options = {
28451
- i: {
28452
- type: 'boolean',
28453
- alias: 'interactive',
28454
- description: 'Toggle interactive mode',
28455
- },
28456
- 'b': {
28457
- type: 'string',
28458
- alias: 'branch',
28459
- description: 'Branch to review',
28460
- },
28461
- };
28462
- const builder = (yargs) => {
28463
- return yargs.options(options).usage(getCommandUsageHeader(review.command));
28464
- };
28465
-
28466
28352
  var review = {
28467
- command: 'review',
28353
+ command,
28468
28354
  desc: 'Review the staged changes',
28469
28355
  builder,
28470
28356
  handler: commandExecutor(handler),