osagent 0.2.78 → 0.2.79

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 (2) hide show
  1. package/cli.js +306 -16
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -133087,7 +133087,7 @@ var init_geminiContentGenerator = __esm({
133087
133087
  }
133088
133088
  models;
133089
133089
  constructor(contentGeneratorConfig, config2) {
133090
- const version3 = "0.2.77";
133090
+ const version3 = "0.2.79";
133091
133091
  const userAgent2 = `OSAgent/${version3} (${process.platform}; ${process.arch})`;
133092
133092
  let headers = {
133093
133093
  "User-Agent": userAgent2
@@ -146884,13 +146884,295 @@ var init_openaiContentGenerator2 = __esm({
146884
146884
  }
146885
146885
  });
146886
146886
 
146887
+ // packages/core/dist/src/core/ollamaCloudContentGenerator/nativeOllamaCloudGenerator.js
146888
+ function createNativeOllamaCloudGenerator(contentGeneratorConfig, cliConfig) {
146889
+ return new NativeOllamaCloudGenerator(contentGeneratorConfig, cliConfig);
146890
+ }
146891
+ var OLLAMA_CLOUD_API_URL, NativeOllamaCloudGenerator;
146892
+ var init_nativeOllamaCloudGenerator = __esm({
146893
+ "packages/core/dist/src/core/ollamaCloudContentGenerator/nativeOllamaCloudGenerator.js"() {
146894
+ "use strict";
146895
+ init_esbuild_shims();
146896
+ init_request_tokenizer();
146897
+ init_uiTelemetry();
146898
+ init_converter();
146899
+ OLLAMA_CLOUD_API_URL = "https://ollama.com/api/chat";
146900
+ NativeOllamaCloudGenerator = class {
146901
+ static {
146902
+ __name(this, "NativeOllamaCloudGenerator");
146903
+ }
146904
+ apiKey;
146905
+ model;
146906
+ baseUrl;
146907
+ timeout;
146908
+ cliConfig;
146909
+ constructor(contentGeneratorConfig, cliConfig) {
146910
+ this.apiKey = contentGeneratorConfig.apiKey || "";
146911
+ this.model = contentGeneratorConfig.model || "qwen3-coder:480b-cloud";
146912
+ this.baseUrl = OLLAMA_CLOUD_API_URL;
146913
+ this.timeout = contentGeneratorConfig.timeout || 12e4;
146914
+ this.cliConfig = cliConfig;
146915
+ }
146916
+ /**
146917
+ * Build headers for Ollama Cloud API
146918
+ */
146919
+ buildHeaders() {
146920
+ const version3 = this.cliConfig.getCliVersion() || "unknown";
146921
+ return {
146922
+ "Authorization": `Bearer ${this.apiKey}`,
146923
+ "Content-Type": "application/json",
146924
+ "User-Agent": `OSAgent/${version3} (${process.platform}; ${process.arch})`
146925
+ };
146926
+ }
146927
+ /**
146928
+ * Convert Gemini-format content to Ollama messages
146929
+ */
146930
+ convertToOllamaMessages(contents) {
146931
+ const messages = [];
146932
+ for (const content of contents) {
146933
+ const role = content.role === "model" ? "assistant" : content.role;
146934
+ let textContent2 = "";
146935
+ const images = [];
146936
+ for (const part of content.parts || []) {
146937
+ if ("text" in part && part.text) {
146938
+ textContent2 += part.text;
146939
+ } else if ("inlineData" in part && part.inlineData?.data) {
146940
+ images.push(part.inlineData.data);
146941
+ }
146942
+ }
146943
+ if (textContent2 || images.length > 0) {
146944
+ const message2 = { role, content: textContent2 };
146945
+ if (images.length > 0) {
146946
+ message2.images = images;
146947
+ }
146948
+ messages.push(message2);
146949
+ }
146950
+ }
146951
+ return messages;
146952
+ }
146953
+ /**
146954
+ * Convert Ollama response to Gemini format
146955
+ */
146956
+ convertToGeminiResponse(ollamaResponse) {
146957
+ const parts = [];
146958
+ if (ollamaResponse.message?.content) {
146959
+ parts.push({ text: ollamaResponse.message.content });
146960
+ }
146961
+ return {
146962
+ candidates: [
146963
+ {
146964
+ content: {
146965
+ role: "model",
146966
+ parts
146967
+ },
146968
+ finishReason: ollamaResponse.done ? "STOP" : void 0,
146969
+ index: 0
146970
+ }
146971
+ ],
146972
+ usageMetadata: {
146973
+ promptTokenCount: ollamaResponse.prompt_eval_count,
146974
+ candidatesTokenCount: ollamaResponse.eval_count,
146975
+ totalTokenCount: (ollamaResponse.prompt_eval_count || 0) + (ollamaResponse.eval_count || 0)
146976
+ }
146977
+ };
146978
+ }
146979
+ /**
146980
+ * Generate content (non-streaming)
146981
+ */
146982
+ async generateContent(request4, _userPromptId) {
146983
+ const normalizedContents = request4.contents ? toContents(request4.contents) : [];
146984
+ const messages = this.convertToOllamaMessages(normalizedContents);
146985
+ if (request4.config?.systemInstruction) {
146986
+ const systemParts = request4.config.systemInstruction.parts || [];
146987
+ const systemText = systemParts.map((p) => "text" in p ? p.text : "").join("");
146988
+ if (systemText) {
146989
+ messages.unshift({ role: "system", content: systemText });
146990
+ }
146991
+ }
146992
+ const ollamaRequest = {
146993
+ model: this.model,
146994
+ messages,
146995
+ stream: false,
146996
+ options: {
146997
+ temperature: request4.config?.temperature,
146998
+ top_p: request4.config?.topP,
146999
+ top_k: request4.config?.topK,
147000
+ num_predict: request4.config?.maxOutputTokens
147001
+ }
147002
+ };
147003
+ const controller = new AbortController();
147004
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
147005
+ try {
147006
+ const response = await fetch(this.baseUrl, {
147007
+ method: "POST",
147008
+ headers: this.buildHeaders(),
147009
+ body: JSON.stringify(ollamaRequest),
147010
+ signal: request4.config?.abortSignal || controller.signal
147011
+ });
147012
+ clearTimeout(timeoutId);
147013
+ if (!response.ok) {
147014
+ const errorText = await response.text();
147015
+ throw new Error(`Ollama Cloud API error ${response.status}: ${errorText}`);
147016
+ }
147017
+ const ollamaResponse = await response.json();
147018
+ const geminiResponse = this.convertToGeminiResponse(ollamaResponse);
147019
+ if (geminiResponse.usageMetadata?.promptTokenCount !== void 0) {
147020
+ uiTelemetryService.setLastPromptTokenCount(geminiResponse.usageMetadata.promptTokenCount);
147021
+ }
147022
+ return geminiResponse;
147023
+ } catch (error2) {
147024
+ clearTimeout(timeoutId);
147025
+ if (error2 instanceof Error && error2.name === "AbortError") {
147026
+ throw new Error("Request timed out");
147027
+ }
147028
+ throw error2;
147029
+ }
147030
+ }
147031
+ /**
147032
+ * Generate content with streaming
147033
+ */
147034
+ async generateContentStream(request4, _userPromptId) {
147035
+ const normalizedContents = request4.contents ? toContents(request4.contents) : [];
147036
+ const messages = this.convertToOllamaMessages(normalizedContents);
147037
+ if (request4.config?.systemInstruction) {
147038
+ const systemParts = request4.config.systemInstruction.parts || [];
147039
+ const systemText = systemParts.map((p) => "text" in p ? p.text : "").join("");
147040
+ if (systemText) {
147041
+ messages.unshift({ role: "system", content: systemText });
147042
+ }
147043
+ }
147044
+ const ollamaRequest = {
147045
+ model: this.model,
147046
+ messages,
147047
+ stream: true,
147048
+ options: {
147049
+ temperature: request4.config?.temperature,
147050
+ top_p: request4.config?.topP,
147051
+ top_k: request4.config?.topK,
147052
+ num_predict: request4.config?.maxOutputTokens
147053
+ }
147054
+ };
147055
+ const response = await fetch(this.baseUrl, {
147056
+ method: "POST",
147057
+ headers: this.buildHeaders(),
147058
+ body: JSON.stringify(ollamaRequest),
147059
+ signal: request4.config?.abortSignal
147060
+ });
147061
+ if (!response.ok) {
147062
+ const errorText = await response.text();
147063
+ throw new Error(`Ollama Cloud API error ${response.status}: ${errorText}`);
147064
+ }
147065
+ if (!response.body) {
147066
+ throw new Error("No response body for streaming");
147067
+ }
147068
+ return async function* () {
147069
+ const reader = response.body.getReader();
147070
+ const decoder2 = new TextDecoder();
147071
+ let buffer = "";
147072
+ try {
147073
+ while (true) {
147074
+ const { done, value } = await reader.read();
147075
+ if (done)
147076
+ break;
147077
+ buffer += decoder2.decode(value, { stream: true });
147078
+ const lines = buffer.split("\n");
147079
+ buffer = lines.pop() || "";
147080
+ for (const line of lines) {
147081
+ if (!line.trim())
147082
+ continue;
147083
+ try {
147084
+ const chunk = JSON.parse(line);
147085
+ const parts = [];
147086
+ if (chunk.message?.content) {
147087
+ parts.push({ text: chunk.message.content });
147088
+ }
147089
+ const geminiChunk = {
147090
+ candidates: [
147091
+ {
147092
+ content: {
147093
+ role: "model",
147094
+ parts
147095
+ },
147096
+ finishReason: chunk.done ? "STOP" : void 0,
147097
+ index: 0
147098
+ }
147099
+ ],
147100
+ usageMetadata: chunk.done ? {
147101
+ promptTokenCount: chunk.prompt_eval_count,
147102
+ candidatesTokenCount: chunk.eval_count,
147103
+ totalTokenCount: (chunk.prompt_eval_count || 0) + (chunk.eval_count || 0)
147104
+ } : void 0
147105
+ };
147106
+ if (chunk.done && chunk.prompt_eval_count !== void 0) {
147107
+ uiTelemetryService.setLastPromptTokenCount(chunk.prompt_eval_count);
147108
+ }
147109
+ yield geminiChunk;
147110
+ } catch {
147111
+ continue;
147112
+ }
147113
+ }
147114
+ }
147115
+ if (buffer.trim()) {
147116
+ try {
147117
+ const chunk = JSON.parse(buffer);
147118
+ const parts = [];
147119
+ if (chunk.message?.content) {
147120
+ parts.push({ text: chunk.message.content });
147121
+ }
147122
+ yield {
147123
+ candidates: [
147124
+ {
147125
+ content: {
147126
+ role: "model",
147127
+ parts
147128
+ },
147129
+ finishReason: chunk.done ? "STOP" : void 0,
147130
+ index: 0
147131
+ }
147132
+ ]
147133
+ };
147134
+ } catch {
147135
+ }
147136
+ }
147137
+ } finally {
147138
+ reader.releaseLock();
147139
+ }
147140
+ }();
147141
+ }
147142
+ /**
147143
+ * Count tokens in request
147144
+ */
147145
+ async countTokens(request4) {
147146
+ try {
147147
+ const tokenizer = getDefaultTokenizer();
147148
+ const result = await tokenizer.calculateTokens(request4, {
147149
+ textEncoding: "cl100k_base"
147150
+ });
147151
+ return { totalTokens: result.totalTokens };
147152
+ } catch {
147153
+ const content = JSON.stringify(request4.contents);
147154
+ return { totalTokens: Math.ceil(content.length / 4) };
147155
+ }
147156
+ }
147157
+ /**
147158
+ * Embed content (not supported by Ollama Cloud chat API)
147159
+ */
147160
+ async embedContent(_request) {
147161
+ throw new Error("Embedding not supported by Ollama Cloud chat API");
147162
+ }
147163
+ };
147164
+ __name(createNativeOllamaCloudGenerator, "createNativeOllamaCloudGenerator");
147165
+ }
147166
+ });
147167
+
146887
147168
  // packages/core/dist/src/core/ollamaCloudContentGenerator/constants.js
146888
- var OLLAMA_CLOUD_BASE_URL, DEFAULT_OLLAMA_CLOUD_MODEL, DEFAULT_TIMEOUT4, DEFAULT_MAX_RETRIES4;
147169
+ var OLLAMA_CLOUD_BASE_URL, OLLAMA_CLOUD_CHAT_URL, DEFAULT_OLLAMA_CLOUD_MODEL, DEFAULT_TIMEOUT4, DEFAULT_MAX_RETRIES4;
146889
147170
  var init_constants7 = __esm({
146890
147171
  "packages/core/dist/src/core/ollamaCloudContentGenerator/constants.js"() {
146891
147172
  "use strict";
146892
147173
  init_esbuild_shims();
146893
- OLLAMA_CLOUD_BASE_URL = "https://ollama.com/v1";
147174
+ OLLAMA_CLOUD_BASE_URL = "https://ollama.com";
147175
+ OLLAMA_CLOUD_CHAT_URL = "https://ollama.com/api/chat";
146894
147176
  DEFAULT_OLLAMA_CLOUD_MODEL = "qwen2.5-coder:32b";
146895
147177
  DEFAULT_TIMEOUT4 = 12e4;
146896
147178
  DEFAULT_MAX_RETRIES4 = 3;
@@ -146965,31 +147247,39 @@ __export(ollamaCloudContentGenerator_exports, {
146965
147247
  DEFAULT_MAX_RETRIES: () => DEFAULT_MAX_RETRIES4,
146966
147248
  DEFAULT_OLLAMA_CLOUD_MODEL: () => DEFAULT_OLLAMA_CLOUD_MODEL,
146967
147249
  DEFAULT_TIMEOUT: () => DEFAULT_TIMEOUT4,
147250
+ NativeOllamaCloudGenerator: () => NativeOllamaCloudGenerator,
146968
147251
  OLLAMA_CLOUD_BASE_URL: () => OLLAMA_CLOUD_BASE_URL,
147252
+ OLLAMA_CLOUD_CHAT_URL: () => OLLAMA_CLOUD_CHAT_URL,
146969
147253
  OllamaCloudProvider: () => OllamaCloudProvider,
147254
+ createNativeOllamaCloudGenerator: () => createNativeOllamaCloudGenerator,
146970
147255
  createOllamaCloudContentGenerator: () => createOllamaCloudContentGenerator,
146971
147256
  isOllamaCloudConfig: () => isOllamaCloudConfig
146972
147257
  });
146973
147258
  function createOllamaCloudContentGenerator(contentGeneratorConfig, cliConfig, options2) {
146974
- const provider = new OllamaCloudProvider(contentGeneratorConfig, cliConfig);
147259
+ const apiKey = contentGeneratorConfig.apiKey;
146975
147260
  if (options2?.validateCredentials) {
146976
- return provider.validateCredentials().then(() => {
146977
- return new OpenAIContentGenerator(contentGeneratorConfig, cliConfig, provider);
147261
+ if (!apiKey) {
147262
+ return Promise.reject(new Error("Ollama Cloud API key is required"));
147263
+ }
147264
+ return validateOllamaCloudCredentials(apiKey).then(() => {
147265
+ return createNativeOllamaCloudGenerator(contentGeneratorConfig, cliConfig);
146978
147266
  });
146979
147267
  }
146980
- return new OpenAIContentGenerator(contentGeneratorConfig, cliConfig, provider);
147268
+ return createNativeOllamaCloudGenerator(contentGeneratorConfig, cliConfig);
146981
147269
  }
146982
147270
  function isOllamaCloudConfig(config2) {
146983
- return OllamaCloudProvider.isOllamaCloudProvider(config2);
147271
+ const baseUrl = config2.baseUrl?.toLowerCase() || "";
147272
+ return baseUrl.includes("ollama.com");
146984
147273
  }
146985
147274
  var init_ollamaCloudContentGenerator = __esm({
146986
147275
  "packages/core/dist/src/core/ollamaCloudContentGenerator/index.js"() {
146987
147276
  "use strict";
146988
147277
  init_esbuild_shims();
146989
- init_openaiContentGenerator();
146990
- init_ollamaCloudProvider();
147278
+ init_nativeOllamaCloudGenerator();
147279
+ init_credentialValidator();
146991
147280
  init_ollamaCloudProvider();
146992
147281
  init_constants7();
147282
+ init_nativeOllamaCloudGenerator();
146993
147283
  __name(createOllamaCloudContentGenerator, "createOllamaCloudContentGenerator");
146994
147284
  __name(isOllamaCloudConfig, "isOllamaCloudConfig");
146995
147285
  }
@@ -152955,8 +153245,8 @@ function createContentGeneratorConfig(config2, authType, generationConfig) {
152955
153245
  return {
152956
153246
  ...baseConfig,
152957
153247
  model: ollamaModel,
152958
- // Ollama Cloud uses OpenAI-compatible API at /v1 endpoint
152959
- baseUrl: "https://ollama.com/v1",
153248
+ // Ollama Cloud uses native API at /api/chat endpoint
153249
+ baseUrl: "https://ollama.com",
152960
153250
  apiKey: ollamaApiKey,
152961
153251
  authType: AuthType.OLLAMA_CLOUD,
152962
153252
  // Ollama doesn't need special cache control handling
@@ -153007,7 +153297,7 @@ function createContentGeneratorConfig(config2, authType, generationConfig) {
153007
153297
  };
153008
153298
  }
153009
153299
  async function createContentGenerator(config2, gcConfig, sessionId2, isInitialAuth) {
153010
- const version3 = "0.2.77";
153300
+ const version3 = "0.2.79";
153011
153301
  const userAgent2 = `OSAgent/${version3} (${process.platform}; ${process.arch})`;
153012
153302
  const baseHeaders = {
153013
153303
  "User-Agent": userAgent2
@@ -340555,7 +340845,7 @@ __name(getPackageJson, "getPackageJson");
340555
340845
  // packages/cli/src/utils/version.ts
340556
340846
  async function getCliVersion() {
340557
340847
  const pkgJson = await getPackageJson();
340558
- return "0.2.77";
340848
+ return "0.2.79";
340559
340849
  }
340560
340850
  __name(getCliVersion, "getCliVersion");
340561
340851
 
@@ -344756,8 +345046,8 @@ var formatDuration = /* @__PURE__ */ __name((milliseconds) => {
344756
345046
 
344757
345047
  // packages/cli/src/generated/git-commit.ts
344758
345048
  init_esbuild_shims();
344759
- var GIT_COMMIT_INFO2 = "bc5e5a7";
344760
- var CLI_VERSION2 = "0.2.77";
345049
+ var GIT_COMMIT_INFO2 = "7c5cf3f";
345050
+ var CLI_VERSION2 = "0.2.79";
344761
345051
 
344762
345052
  // packages/cli/src/utils/systemInfo.ts
344763
345053
  async function getNpmVersion() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osagent",
3
- "version": "0.2.78",
3
+ "version": "0.2.79",
4
4
  "description": "OS Agent - AI-powered CLI for autonomous coding with Ollama Cloud and Qwen models",
5
5
  "repository": {
6
6
  "type": "git",