tarsk 0.2.4 → 0.2.5

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.
@@ -14,8 +14,16 @@ export async function completion(request, options) {
14
14
  repeating = false;
15
15
  count++;
16
16
  logStart({ type: `completion_request_${count}`, args: request });
17
- response = await call(options, req);
18
- logEnd(`completion_request_${count}`);
17
+ try {
18
+ response = await call(options, req);
19
+ }
20
+ catch (error) {
21
+ logWrite({ type: 'completion_error', args: { error } });
22
+ throw new Error(`Error calling completion: ${error}`);
23
+ }
24
+ finally {
25
+ logEnd(`completion_request_${count}`);
26
+ }
19
27
  if (response.error) {
20
28
  const message = JSON.stringify(response.error.metadata);
21
29
  logError({ type: 'completion_error', message, args: { ...response.error } });
@@ -100,7 +108,8 @@ export async function callFunction(_function, args) {
100
108
  }
101
109
  catch (error) {
102
110
  var err = new Error();
103
- logWrite({ type: 'test_call_error', args: { functionName: _function.name, error: `${error}` },
111
+ logWrite({
112
+ type: 'test_call_error', args: { functionName: _function.name, error: `${error}` },
104
113
  });
105
114
  return { error: `Error calling ${_function.name}: ${error}` };
106
115
  }
@@ -1,5 +1,12 @@
1
+ import { getSettings } from "./settings.js";
1
2
  export async function api_get_models(c) {
2
- const res = await fetch("https://openrouter.ai/api/v1/models");
3
+ const setttings = await getSettings();
4
+ const res = await fetch("https://api.tarsk.io/api/v1/models", {
5
+ method: "GET",
6
+ headers: {
7
+ Authorization: `Bearer ${setttings.tarskApiKey}`
8
+ }
9
+ });
3
10
  const data = await res.json();
4
11
  const models = [];
5
12
  for (const model of data.data) {
@@ -1,40 +1,43 @@
1
1
  import {} from "../interfaces/settings.js";
2
2
  import { getJSON, setJSON } from "../utils/json-file.js";
3
3
  import { httpValidationErrror as httpValidationError, isEmpty } from "./utils.js";
4
- const defaultOpenRouterURL = "https://openrouter.ai/api/v1";
4
+ const defaultTarskURL = "https://api.tarsk.io/api/v1";
5
5
  export const defaultModel = "meta-llama/llama-3.3-70b-instruct";
6
6
  export async function api_get_settings(c) {
7
7
  return c.json(getSettings());
8
8
  }
9
9
  export async function api_save_settings(c) {
10
10
  const settings = await c.req.json();
11
- if (settings.openRouterApiKey == undefined) {
12
- httpValidationError("openRouterApiKey is required");
11
+ if (isEmpty(settings.tarskApiKey)) {
12
+ httpValidationError("tarskApiKey is required");
13
13
  }
14
- if (isEmpty(settings.openRouterURL)) {
15
- settings.openRouterURL = defaultOpenRouterURL;
14
+ if (isEmpty(settings.apiURL)) {
15
+ settings.apiURL = defaultTarskURL;
16
16
  }
17
17
  if (isEmpty(settings.defaultModel) || settings.defaultModel == 'Select a Model') {
18
18
  settings.defaultModel = defaultModel;
19
19
  }
20
- if (settings.openRouterURL == undefined) {
21
- httpValidationError("openRouterURL is required");
20
+ if (settings.apiURL == undefined) {
21
+ httpValidationError("apiURL is required");
22
22
  }
23
- if (!settings.openRouterURL.startsWith("https://")) {
24
- httpValidationError("openRouterURL must start with https://");
23
+ if (!settings.apiURL.startsWith("https://")) {
24
+ httpValidationError("apiURL must start with https://");
25
25
  }
26
- if (settings.openRouterURL.endsWith("/")) {
27
- settings.openRouterURL = settings.openRouterURL.slice(0, -1);
26
+ if (settings.apiURL.endsWith("/")) {
27
+ settings.apiURL = settings.apiURL.slice(0, -1);
28
28
  }
29
29
  setJSON('settings', settings);
30
30
  return c.json(getSettings());
31
31
  }
32
32
  export function getSettings() {
33
33
  const defaultSettings = {
34
- openRouterApiKey: "",
35
- openRouterURL: defaultOpenRouterURL,
34
+ tarskApiKey: "",
35
+ apiURL: defaultTarskURL,
36
36
  defaultModel: defaultModel
37
37
  };
38
38
  const settings = getJSON("settings", defaultSettings);
39
+ if (isEmpty(settings.tarskApiKey)) {
40
+ settings.tarskApiKey = 'aedf201d-bf05-4fa0-912c-15a924f32c65';
41
+ }
39
42
  return settings;
40
43
  }
package/dist/prompt.js CHANGED
@@ -6,12 +6,10 @@ import { isEmpty } from "./api/utils.js";
6
6
  import { logWrite, logEnd, logStart } from "./log/log.js";
7
7
  export async function prompt(content, promptOptions) {
8
8
  const settings = await getSettings();
9
- if (settings.openRouterApiKey == "") {
10
- return "You need to set the OpenRouter API key in the settings.";
11
- }
9
+ let apiKey = settings.tarskApiKey;
12
10
  const options = {
13
- baseUrl: settings.openRouterURL,
14
- apiKey: settings.openRouterApiKey,
11
+ baseUrl: isEmpty(settings.apiURL) ? "https://api.tarsk.io/api/v1" : settings.apiURL,
12
+ apiKey,
15
13
  };
16
14
  const messages = [];
17
15
  if (promptOptions?.firstMessage) {
@@ -45,7 +43,7 @@ function friendlyError(e, settings) {
45
43
  return `The model "${settings.defaultModel}" does not support tool use. Please select a different model (A good default is ${defaultModel}).`;
46
44
  }
47
45
  if (e.startsWith("Error: No auth credentials found")) {
48
- return `The OpenRouter API key is invalid. Please check your account at https://openrouter.ai and get a new key.`;
46
+ return `The API key is invalid. Please check your account and get a new key.`;
49
47
  }
50
48
  return e;
51
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tarsk",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "author": "WebNative LLC",
5
5
  "description": "Tarsk is a AI tool available at https://tarsk.io",
6
6
  "license": "MIT",