tune-sdk 0.2.13 → 0.2.15

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Reddit](https://img.shields.io/badge/Reddit-%23FF4500.svg?style=for-the-badge&logo=Reddit&logoColor=white)](https://www.reddit.com/r/tuneai/)
3
3
  [![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/hu32FNYPYD)
4
4
 
5
- Tune is a handy [extension](https://marketplace.visualstudio.com/items?itemName=iovdin.tune) for Visual Studio Code and [plugin](https://github.com/iovdin/tune.nvim) for Neovim that lets you chat with large language models (LLMs) in a text file.
5
+ Tune is a handy [extension for Visual Studio Code and](https://marketplace.visualstudio.com/items?itemName=iovdin.tune) and [plugin for Neovim](https://github.com/iovdin/tune.nvim) and [plugin for Sublime Text](https://github.com/iovdin/tune-sublime) that lets you chat with large language models (LLMs) in a text file.
6
6
  With tune [javascript sdk](https://www.npmjs.com/package/tune-sdk) you can make apps and agents.
7
7
 
8
8
  ## Demo
@@ -24,6 +24,7 @@ edit `~/.tune/.env` file and add `OPENAI_KEY` and other keys
24
24
  ## Template Language
25
25
 
26
26
  ```chat
27
+ user:
27
28
  @myprompt include file
28
29
  @image include image
29
30
  @path/to/file include file at path
@@ -39,6 +40,43 @@ edit `~/.tune/.env` file and add `OPENAI_KEY` and other keys
39
40
  ```
40
41
  [read more](https://iovdin.github.io/tune/template-language)
41
42
 
43
+
44
+ ## Diagram
45
+
46
+ ```mermaid
47
+ flowchart TD
48
+
49
+ subgraph Entry[" "]
50
+ Editor["VSCode/Neovim/Sublime Text"]
51
+ CLI["CLI"]
52
+ App["App"]
53
+ end
54
+
55
+ subgraph Core[" "]
56
+ MD1["~/.tune/default.ctx.js"]
57
+ MD2["require('tune-fs')
58
+ require('tune-models')
59
+ "]
60
+ CTX["tune.makeContext(...middlewares)"]
61
+ F2R["ctx.file2run(params)"]
62
+ end
63
+
64
+
65
+ MD1 --> |cli middlewares| CTX
66
+ MD2 --> |app middlewares| CTX
67
+ Editor -->| $ tune-sdk rpc | Core
68
+ CLI --> | $ tune-sdk --user hello | Core
69
+ App --> Core
70
+
71
+
72
+
73
+ F2R -->|ctx.resolve #40; system.txt #124; shell #124; gpt-5 #41; | CTX
74
+ CTX -->| #123; type: text #124; tool #124; llm #125; | F2R
75
+
76
+ F2R --> |fetch| LLM["https://provider.com/v1/chat/completions"]
77
+ F2R --> |call| Tool
78
+ ```
79
+
42
80
  ## Extend with Middlewares
43
81
  Extend Tune with middlewares:
44
82
 
package/dist/tune.js CHANGED
@@ -1569,12 +1569,14 @@ async function text2ast(text, ctx, resolve) {
1569
1569
  continue;
1570
1570
  }(function(it) {
1571
1571
  it = it.replace(/\\\}/g, "}");
1572
+ it = it.replace(/\\\|/g, "__PIPE_ESC__");
1572
1573
  it = it.split("|");
1573
1574
  it = it.map((function(it) {
1574
1575
  return it.trim();
1575
1576
  }));
1576
1577
  it = it.map((function(item, index) {
1577
1578
  var idx;
1579
+ item = item.replace(/__PIPE_ESC__/g, "|");
1578
1580
  if ((index === 0)) return item;
1579
1581
  var idx;
1580
1582
  idx = item.indexOf(" ");
@@ -2021,16 +2023,20 @@ TunePromise.prototype.finally = (function(onFinally) {
2021
2023
  });
2022
2024
 
2023
2025
  function text2run(text, ctx, opts) {
2024
- var msgs, stopVal, stream, resolve, reject, p, iter;
2026
+ var msgs, stopVal, stream, hookMsg, resolve, reject, p, iter;
2025
2027
  if (!ctx) throw Error("context not set");
2026
2028
  var msgs;
2027
2029
  var stopVal;
2028
2030
  var stream;
2031
+ var hookMsg;
2029
2032
  var resolve;
2030
2033
  var reject;
2031
2034
  msgs = [];
2032
2035
  stopVal = (((typeof opts !== "undefined") && (opts !== null) && !Number.isNaN(opts) && (typeof opts.stop !== "undefined") && (opts.stop !== null) && !Number.isNaN(opts.stop)) ? opts.stop : (((typeof "step" !== "undefined") && ("step" !== null) && !Number.isNaN("step")) ? "step" : undefined));
2033
2036
  stream = (((typeof opts !== "undefined") && (opts !== null) && !Number.isNaN(opts) && (typeof opts.stream !== "undefined") && (opts.stream !== null) && !Number.isNaN(opts.stream)) ? opts.stream : (((typeof false !== "undefined") && (false !== null) && !Number.isNaN(false)) ? false : undefined));
2037
+ hookMsg = (function(msg) {
2038
+ return msg;
2039
+ });
2034
2040
  resolve = undefined;
2035
2041
  reject = undefined;
2036
2042
  var p;
@@ -2069,11 +2075,20 @@ function text2run(text, ctx, opts) {
2069
2075
  var model;
2070
2076
  provider = (((typeof payload !== "undefined") && (payload !== null) && !Number.isNaN(payload) && (typeof payload.llm !== "undefined") && (payload.llm !== null) && !Number.isNaN(payload.llm) && (typeof payload.llm.source !== "undefined") && (payload.llm.source !== null) && !Number.isNaN(payload.llm.source)) ? payload.llm.source : undefined);
2071
2077
  model = (((typeof payload !== "undefined") && (payload !== null) && !Number.isNaN(payload) && (typeof payload.llm !== "undefined") && (payload.llm !== null) && !Number.isNaN(payload.llm) && (typeof payload.llm.name !== "undefined") && (payload.llm.name !== null) && !Number.isNaN(payload.llm.name)) ? payload.llm.name : undefined);
2078
+ hookMsg = (((typeof payload !== "undefined") && (payload !== null) && !Number.isNaN(payload) && (typeof payload.llm !== "undefined") && (payload.llm !== null) && !Number.isNaN(payload.llm) && (typeof payload.llm.hookMsg !== "undefined") && (payload.llm.hookMsg !== null) && !Number.isNaN(payload.llm.hookMsg)) ? payload.llm.hookMsg : (((typeof(function(msg) {
2079
+ return msg;
2080
+ }) !== "undefined") && ((function(msg) {
2081
+ return msg;
2082
+ }) !== null) && !Number.isNaN((function(msg) {
2083
+ return msg;
2084
+ }))) ? (function(msg) {
2085
+ return msg;
2086
+ }) : undefined));
2072
2087
  if (stream) payload.stream = stream;
2073
2088
  var res;
2074
2089
  res = await toolCall(payload, ctx);
2075
2090
  if (res.length) {
2076
- msgs = msgs.concat(res);
2091
+ msgs = msgs.concat(res.map(hookMsg));
2077
2092
  iter.result = {
2078
2093
  value: msgs
2079
2094
  };
@@ -2092,7 +2107,7 @@ function text2run(text, ctx, opts) {
2092
2107
  err._stack = TuneError.ctx2stack(ctx);
2093
2108
  throw err;
2094
2109
  }
2095
- msgs.push((((typeof res !== "undefined") && (res !== null) && !Number.isNaN(res) && (typeof res.message !== "undefined") && (res.message !== null) && !Number.isNaN(res.message)) ? res.message : (((typeof res !== "undefined") && (res !== null) && !Number.isNaN(res) && (typeof res.choices !== "undefined") && (res.choices !== null) && !Number.isNaN(res.choices) && (typeof res.choices[0] !== "undefined") && (res.choices[0] !== null) && !Number.isNaN(res.choices[0]) && (typeof res.choices[0].message !== "undefined") && (res.choices[0].message !== null) && !Number.isNaN(res.choices[0].message)) ? res.choices[0].message : undefined)));
2110
+ msgs.push(hookMsg((((typeof res !== "undefined") && (res !== null) && !Number.isNaN(res) && (typeof res.message !== "undefined") && (res.message !== null) && !Number.isNaN(res.message)) ? res.message : (((typeof res !== "undefined") && (res !== null) && !Number.isNaN(res) && (typeof res.choices !== "undefined") && (res.choices !== null) && !Number.isNaN(res.choices) && (typeof res.choices[0] !== "undefined") && (res.choices[0] !== null) && !Number.isNaN(res.choices[0]) && (typeof res.choices[0].message !== "undefined") && (res.choices[0].message !== null) && !Number.isNaN(res.choices[0].message)) ? res.choices[0].message : undefined))));
2096
2111
  iter.result = {
2097
2112
  value: msgs,
2098
2113
  done: true
@@ -2169,6 +2184,7 @@ function text2run(text, ctx, opts) {
2169
2184
  role: "assistant",
2170
2185
  content: ""
2171
2186
  });
2187
+ it = hookMsg(it);
2172
2188
  it = (iter.result = {
2173
2189
  value: msgs.concat(Array(it))
2174
2190
  });
@@ -2202,7 +2218,7 @@ function text2run(text, ctx, opts) {
2202
2218
  }
2203
2219
  text2run;
2204
2220
  async function file2run(args, params, ctx) {
2205
- var lctx, text, stop, node, response, res, r, chunk, itergnVy4sP, _ref;
2221
+ var lctx, text, stop, node, response, res, r, chunk, itergYbx9Yp, _ref;
2206
2222
  var lctx;
2207
2223
  lctx = ctx.clone();
2208
2224
  if (params) lctx.ms.unshift(envmd(params));
@@ -2269,7 +2285,7 @@ async function file2run(args, params, ctx) {
2269
2285
  stream: true
2270
2286
  });
2271
2287
  chunk = {};
2272
- itergnVy4sP = new AsyncIter();
2288
+ itergYbx9Yp = new AsyncIter();
2273
2289
  (async function($lastRes) {
2274
2290
  var _ref;
2275
2291
  try {
@@ -2278,20 +2294,20 @@ async function file2run(args, params, ctx) {
2278
2294
  res = (chunk.value || "");
2279
2295
  if (chunk.done) await save();
2280
2296
  $lastRes = transformOutput(res) || $lastRes;
2281
- itergnVy4sP.result = {
2297
+ itergYbx9Yp.result = {
2282
2298
  value: $lastRes
2283
2299
  }
2284
2300
  }
2285
- _ref = itergnVy4sP.result = {
2301
+ _ref = itergYbx9Yp.result = {
2286
2302
  value: $lastRes,
2287
2303
  done: true
2288
2304
  }
2289
2305
  } catch (e) {
2290
- _ref = (itergnVy4sP.err = e);
2306
+ _ref = (itergYbx9Yp.err = e);
2291
2307
  }
2292
2308
  return _ref;
2293
2309
  })();
2294
- _ref = itergnVy4sP;
2310
+ _ref = itergYbx9Yp;
2295
2311
  }
2296
2312
  return _ref;
2297
2313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tune-sdk",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "tune - LLM chat in text file",
5
5
  "main": "dist/tune.js",
6
6
  "module": "dist/tune.mjs",
@@ -10,9 +10,6 @@
10
10
  "require": "./dist/tune.js",
11
11
  "import": "./dist/tune.mjs"
12
12
  },
13
- "./fsctx": {
14
- "require": "./dist/fsctx.js"
15
- },
16
13
  "./cli": {
17
14
  "require": "./dist/cli.js"
18
15
  },
@@ -1,27 +0,0 @@
1
- name: Publish Package
2
-
3
- on:
4
- push:
5
- tags:
6
- - 'v*'
7
-
8
- permissions:
9
- id-token: write # Required for OIDC
10
- contents: read
11
-
12
- jobs:
13
- publish:
14
- runs-on: ubuntu-latest
15
- steps:
16
- - uses: actions/checkout@v4
17
-
18
- - uses: actions/setup-node@v4
19
- with:
20
- node-version: '20'
21
- registry-url: 'https://registry.npmjs.org'
22
-
23
- # Ensure npm 11.5.1 or later is installed
24
- - name: Update npm
25
- run: npm install -g npm@latest
26
- - run: npm i
27
- - run: npm publish