sliftutils 1.0.0 → 1.0.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/.cursorrules CHANGED
@@ -29,6 +29,10 @@ The code automatically updates on save, so do not ever run commands to rerun the
29
29
  Use tool calls to read files and directories where possible, instead of running "ls", "dir", etc.
30
30
 
31
31
  Coding Styles
32
+ Don't make functions that will never be reused and are short. This just makes the code too confusing. If the function is under five lines and it's not being reused, you shouldn't create it, unless instructed explicitly to create it.
33
+
34
+ Comments should be used sparingly and only if it's required to explain what's being done. If you're calling a function called create imageName and the comment is called create imageName, you will be fired because that's just stupid. It's a waste of lines.
35
+
32
36
  Comments go in the line before, never after the semicolon.
33
37
 
34
38
  Try not to use "null", and instead always use "undefined".
package/index.d.ts CHANGED
@@ -100,6 +100,9 @@ declare module "sliftutils/misc/openrouter" {
100
100
  onCost?: (cost: number) => void;
101
101
  validate?: (response: T) => void;
102
102
  }): Promise<T>;
103
+ export declare function simpleAICall(model: string, message: string): Promise<string>;
104
+ /** The message must request the result to be returned in YAML. */
105
+ export declare function simpleAICallTyped<T>(model: string, message: string): Promise<T>;
103
106
  export declare function openRouterCall(config: {
104
107
  model: string;
105
108
  messages: MessageHistory;
package/misc/apiKeys.tsx CHANGED
@@ -99,11 +99,20 @@ let getStorage = lazy((): {
99
99
  });
100
100
 
101
101
  export const getAPIKey = cache(async function getAPIKey(key: string): Promise<string> {
102
+ let innerKey = "key";
103
+ if (isNode()) {
104
+ if (key.includes(".json.")) {
105
+ let [baseKey, innerKeyPart] = key.split(".json.");
106
+ baseKey += ".json";
107
+ innerKey = innerKeyPart;
108
+ key = baseKey;
109
+ }
110
+ }
102
111
  let keyKey = getStorageKey(key);
103
112
  let localStorageValue = getStorage().getItem(keyKey);
104
113
  if (localStorageValue?.startsWith("{")) {
105
114
  try {
106
- localStorageValue = JSON.parse(localStorageValue).key;
115
+ localStorageValue = JSON.parse(localStorageValue)[innerKey];
107
116
  } catch { }
108
117
  }
109
118
  if (localStorageValue) {
@@ -28,6 +28,9 @@ export declare function yamlOpenRouterCall<T>(config: {
28
28
  onCost?: (cost: number) => void;
29
29
  validate?: (response: T) => void;
30
30
  }): Promise<T>;
31
+ export declare function simpleAICall(model: string, message: string): Promise<string>;
32
+ /** The message must request the result to be returned in YAML. */
33
+ export declare function simpleAICallTyped<T>(model: string, message: string): Promise<T>;
31
34
  export declare function openRouterCall(config: {
32
35
  model: string;
33
36
  messages: MessageHistory;
@@ -52,6 +52,20 @@ export async function yamlOpenRouterCall<T>(config: {
52
52
  }
53
53
  }
54
54
 
55
+ export async function simpleAICall(model: string, message: string): Promise<string> {
56
+ return await openRouterCallBase({
57
+ model,
58
+ messages: [{ role: "user", content: message }],
59
+ });
60
+ }
61
+ /** The message must request the result to be returned in YAML. */
62
+ export async function simpleAICallTyped<T>(model: string, message: string): Promise<T> {
63
+ return await yamlOpenRouterCall({
64
+ model,
65
+ messages: [{ role: "user", content: message }],
66
+ }) as T;
67
+ }
68
+
55
69
  let pendingLog: {
56
70
  count: number;
57
71
  duration: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [