{"record":{"id":"c31dcbdcac9e3c27","repo":"eyaltoledano/claude-task-master","slug":"the-grok-cli-model-function-cannot-be-called-with","errorCode":null,"errorMessage":"The Grok CLI model function cannot be called with the new keyword.","messagePattern":"The Grok CLI model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ai-sdk-provider-grok-cli/src/grok-cli-provider.ts","lineNumber":75,"sourceCode":"\t\tsettings: GrokCliSettings = {}\n\t): LanguageModelV2 => {\n\t\tconst mergedSettings = {\n\t\t\t...options.defaultSettings,\n\t\t\t...settings\n\t\t};\n\n\t\treturn new GrokCliLanguageModel({\n\t\t\tid: modelId,\n\t\t\tsettings: mergedSettings\n\t\t});\n\t};\n\n\tconst provider = function (\n\t\tmodelId: GrokCliModelId,\n\t\tsettings?: GrokCliSettings\n\t) {\n\t\tif (new.target) {\n\t\t\tthrow new Error(\n\t\t\t\t'The Grok CLI model function cannot be called with the new keyword.'\n\t\t\t);\n\t\t}\n\n\t\treturn createModel(modelId, settings);\n\t};\n\n\tprovider.languageModel = createModel;\n\tprovider.chat = createModel; // Alias for languageModel\n\n\t// Add textEmbeddingModel method that throws NoSuchModelError\n\tprovider.textEmbeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({\n\t\t\tmodelId,\n\t\t\tmodelType: 'textEmbeddingModel'\n\t\t});\n\t};\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/ai-sdk-provider-grok-cli/src/grok-cli-provider.ts#L57-L93","documentation":"The grokCli provider function is designed to be called as a plain function (grokCli(...)), not with `new`. JavaScript allows constructing ordinary functions, which would bind a wrong `this` and break the factory pattern, so the provider explicitly throws if `new.target` is set.","triggerScenarios":"Writing `new grokCli({ ... })` or `new grokCli('model-id')` instead of calling it directly.","commonSituations":"Copy-pasting patterns from class-based providers; TypeScript auto-suggestions; older AI SDK examples where provider factories were constructor-style.","solutions":["Remove the `new` keyword and call the provider directly: `const grok = grokCli({...})`.","Update code derived from outdated AI SDK provider examples.","If wrapping, delegate without `new`: `const create = () => grokCli(settings);`"],"exampleFix":"// before\nconst provider = new grokCli({ apiKey });\n// after\nconst provider = grokCli({ apiKey });","handlingStrategy":"validation","validationCode":"// Convention check in code review/CI: flag `new grokCli` usage via lint rule (no-new-native-nonconstructor or custom rule)","typeGuard":"null","tryCatchPattern":"try { const p = new (grokCli as any)(settings); } catch (e) { if (e.message.includes('cannot be called with the new keyword')) { const p = grokCli(settings); } else { throw e; } }","preventionTips":["Call provider factories without `new` (current AI SDK convention)","Update internal snippets/templates copied from older SDK examples","Add a lint rule banning `new` on factory functions"],"tags":["javascript","new-keyword","provider","ai-sdk"],"backgroundTag":"constructor-misuse","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}