@misterscan/sesi 1.1.2 → 1.2.0

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 (77) hide show
  1. package/README.md +29 -8
  2. package/bin/sesi.js +35 -34
  3. package/dist/ai-runtime.d.ts +5 -0
  4. package/dist/ai-runtime.d.ts.map +1 -1
  5. package/dist/ai-runtime.js +157 -7
  6. package/dist/ai-runtime.js.map +1 -1
  7. package/dist/builtins.d.ts +1 -1
  8. package/dist/builtins.d.ts.map +1 -1
  9. package/dist/builtins.js +114 -1
  10. package/dist/builtins.js.map +1 -1
  11. package/dist/interpreter.d.ts +6 -1
  12. package/dist/interpreter.d.ts.map +1 -1
  13. package/dist/interpreter.js +210 -36
  14. package/dist/interpreter.js.map +1 -1
  15. package/dist/parser.d.ts.map +1 -1
  16. package/dist/parser.js +2 -0
  17. package/dist/parser.js.map +1 -1
  18. package/dist/sesi.bundled.js +534 -107
  19. package/dist/types.d.ts +9 -1
  20. package/dist/types.d.ts.map +1 -1
  21. package/dist/types.js.map +1 -1
  22. package/docs/ARCHITECTURE.md +9 -9
  23. package/docs/BUILTINS.md +87 -8
  24. package/docs/DISTRIBUTED_SYSTEMS.md +1 -1
  25. package/docs/IMAGE_GENERATION.md +82 -1
  26. package/docs/IMPLEMENTATION_SUMMARY.md +544 -533
  27. package/docs/QUICKSTART.md +41 -1
  28. package/docs/README.md +19 -13
  29. package/docs/ROADMAP.md +10 -11
  30. package/docs/SPECIFICATION.md +37 -14
  31. package/docs/SYSTEMS_REASONING.md +35 -11
  32. package/docs/bakery_logo.png +0 -0
  33. package/docs/coffee_mug.png +0 -0
  34. package/docs/desk_lamp.png +0 -0
  35. package/docs/logo.png +0 -0
  36. package/docs/notebook.png +0 -0
  37. package/docs/sesi_ai_chronicles.md +209 -0
  38. package/examples/16_modules.sesi +28 -0
  39. package/examples/17_http_client.sesi +29 -0
  40. package/examples/18_parallel_requests.sesi +37 -0
  41. package/main/chatbot.sesi +36 -0
  42. package/main/conversational_classifier_weights.json +45 -0
  43. package/main/conversational_sentences.json +304 -0
  44. package/main/epochs.sesi +94 -0
  45. package/main/gpu_orchestrator.sesi +36 -0
  46. package/main/hardware_diagnostics.sesi +118 -0
  47. package/main/inference.sesi +54 -0
  48. package/main/native_chatbot.sesi +180 -0
  49. package/main/native_synthesizer.sesi +83 -0
  50. package/main/nn_personas_trainer.sesi +302 -0
  51. package/main/nn_responses_trainer.sesi +269 -0
  52. package/main/nn_sentences_trainer.sesi +330 -0
  53. package/main/personas.json +124 -0
  54. package/main/personas_classifier_weights.json +45 -0
  55. package/main/playground.sesi +3 -1
  56. package/main/predictive_typing.sesi +127 -0
  57. package/main/query_brain.sesi +45 -0
  58. package/main/response_classifier_weights.json +45 -0
  59. package/main/retro_chat.html +239 -0
  60. package/main/retro_chat_generator.sesi +745 -0
  61. package/main/sesi_ai.sesi +158 -0
  62. package/main/sesi_db_chatbot.sesi +261 -0
  63. package/main/terminal_chat.py +385 -0
  64. package/main/tests/temp_math_mod.sesi +3 -0
  65. package/main/tests/test_image_input.sesi +40 -0
  66. package/main/tests/test_v2_features.sesi +48 -0
  67. package/main/unified_sesi_ai.sesi +334 -0
  68. package/main/varied_responses.json +304 -0
  69. package/package.json +11 -5
  70. package/main/atm_deposit.sesi +0 -37
  71. package/main/atm_withdraw.sesi +0 -37
  72. package/main/data.txt +0 -1
  73. package/main/math_aggregator.sesi +0 -15
  74. package/main/math_generator.sesi +0 -7
  75. package/main/math_processor.sesi +0 -23
  76. package/main/tax_calculator.sesi +0 -15
  77. package/main/vault.sesi +0 -15
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -12552,6 +12553,7 @@ var require_parser = __commonJS({
12552
12553
  modelName,
12553
12554
  config,
12554
12555
  prompt,
12556
+ images: config?.images,
12555
12557
  line
12556
12558
  };
12557
12559
  }
@@ -12633,6 +12635,7 @@ var require_parser = __commonJS({
12633
12635
  modelName,
12634
12636
  config,
12635
12637
  prompt,
12638
+ images: config?.images,
12636
12639
  line
12637
12640
  };
12638
12641
  }
@@ -12910,7 +12913,7 @@ var require_builtins = __commonJS({
12910
12913
  var fs3 = __importStar(require("fs"));
12911
12914
  var path2 = __importStar(require("path"));
12912
12915
  var child_process_1 = require("child_process");
12913
- function getBuiltins() {
12916
+ function getBuiltins(interpreter) {
12914
12917
  const builtins = /* @__PURE__ */ new Map();
12915
12918
  builtins.set("print", {
12916
12919
  type: "function",
@@ -12990,6 +12993,36 @@ var require_builtins = __commonJS({
12990
12993
  }
12991
12994
  }
12992
12995
  });
12996
+ builtins.set("from_json", {
12997
+ type: "function",
12998
+ name: "from_json",
12999
+ params: [{ name: "string" }],
13000
+ body: {},
13001
+ closure: {},
13002
+ isBuiltin: true,
13003
+ builtin: (str) => {
13004
+ if (typeof str !== "string")
13005
+ return null;
13006
+ try {
13007
+ return JSON.parse(str);
13008
+ } catch (e2) {
13009
+ return null;
13010
+ }
13011
+ }
13012
+ });
13013
+ builtins.set("exp", {
13014
+ type: "function",
13015
+ name: "exp",
13016
+ params: [{ name: "x" }],
13017
+ body: {},
13018
+ closure: {},
13019
+ isBuiltin: true,
13020
+ builtin: (x2) => {
13021
+ if (typeof x2 !== "number")
13022
+ return null;
13023
+ return Math.exp(x2);
13024
+ }
13025
+ });
12993
13026
  builtins.set("num", {
12994
13027
  type: "function",
12995
13028
  name: "num",
@@ -13121,14 +13154,14 @@ var require_builtins = __commonJS({
13121
13154
  body: {},
13122
13155
  closure: {},
13123
13156
  isBuiltin: true,
13124
- builtin: (filePath2) => {
13125
- if (typeof filePath2 !== "string")
13157
+ builtin: (filePath) => {
13158
+ if (typeof filePath !== "string")
13126
13159
  return null;
13127
13160
  try {
13128
- const absolutePath = path2.resolve(process.cwd(), filePath2);
13161
+ const absolutePath = path2.resolve(process.cwd(), filePath);
13129
13162
  return fs3.readFileSync(absolutePath, "utf-8");
13130
13163
  } catch (e2) {
13131
- throw new Error(`Failed to read file: ${filePath2}`);
13164
+ throw new Error(`Failed to read file: ${filePath}`);
13132
13165
  }
13133
13166
  }
13134
13167
  });
@@ -13139,15 +13172,15 @@ var require_builtins = __commonJS({
13139
13172
  body: {},
13140
13173
  closure: {},
13141
13174
  isBuiltin: true,
13142
- builtin: (filePath2, content) => {
13143
- if (typeof filePath2 !== "string" || typeof content !== "string")
13175
+ builtin: (filePath, content) => {
13176
+ if (typeof filePath !== "string" || typeof content !== "string")
13144
13177
  return null;
13145
13178
  try {
13146
- const absolutePath = path2.resolve(process.cwd(), filePath2);
13179
+ const absolutePath = path2.resolve(process.cwd(), filePath);
13147
13180
  fs3.writeFileSync(absolutePath, content, "utf-8");
13148
13181
  return true;
13149
13182
  } catch (e2) {
13150
- throw new Error(`Failed to write file: ${filePath2}`);
13183
+ throw new Error(`Failed to write file: ${filePath}`);
13151
13184
  }
13152
13185
  }
13153
13186
  });
@@ -13158,16 +13191,16 @@ var require_builtins = __commonJS({
13158
13191
  body: {},
13159
13192
  closure: {},
13160
13193
  isBuiltin: true,
13161
- builtin: (filePath2, content) => {
13162
- if (typeof filePath2 !== "string" || typeof content !== "string")
13194
+ builtin: (filePath, content) => {
13195
+ if (typeof filePath !== "string" || typeof content !== "string")
13163
13196
  return null;
13164
13197
  try {
13165
- const absolutePath = path2.resolve(process.cwd(), filePath2);
13198
+ const absolutePath = path2.resolve(process.cwd(), filePath);
13166
13199
  const buffer = Buffer.from(content, "base64");
13167
13200
  fs3.writeFileSync(absolutePath, buffer);
13168
13201
  return true;
13169
13202
  } catch (e2) {
13170
- throw new Error(`Failed to write image: ${filePath2}`);
13203
+ throw new Error(`Failed to write image: ${filePath}`);
13171
13204
  }
13172
13205
  }
13173
13206
  });
@@ -13220,11 +13253,11 @@ var require_builtins = __commonJS({
13220
13253
  body: {},
13221
13254
  closure: {},
13222
13255
  isBuiltin: true,
13223
- builtin: (filePath2) => {
13224
- if (typeof filePath2 !== "string")
13256
+ builtin: (filePath) => {
13257
+ if (typeof filePath !== "string")
13225
13258
  return null;
13226
13259
  try {
13227
- const absolutePath = path2.resolve(process.cwd(), filePath2);
13260
+ const absolutePath = path2.resolve(process.cwd(), filePath);
13228
13261
  const sesiBin = path2.resolve(__dirname, "../bin/sesi.js");
13229
13262
  const child = (0, child_process_1.spawn)("node", [sesiBin, absolutePath], {
13230
13263
  detached: true,
@@ -13234,7 +13267,7 @@ var require_builtins = __commonJS({
13234
13267
  child.unref();
13235
13268
  return child.pid || true;
13236
13269
  } catch (e2) {
13237
- throw new Error(`Failed to spawn process: ${filePath2}`);
13270
+ throw new Error(`Failed to spawn process: ${filePath}`);
13238
13271
  }
13239
13272
  }
13240
13273
  });
@@ -13273,6 +13306,86 @@ var require_builtins = __commonJS({
13273
13306
  isBuiltin: true,
13274
13307
  builtin: () => Math.random()
13275
13308
  });
13309
+ builtins.set("web_get", {
13310
+ type: "function",
13311
+ name: "web_get",
13312
+ params: [{ name: "url" }, { name: "headers", defaultValue: {} }],
13313
+ body: {},
13314
+ closure: {},
13315
+ isBuiltin: true,
13316
+ builtin: async (...args2) => {
13317
+ const [urlVal, headersVal] = args2;
13318
+ const url = typeof urlVal === "string" ? urlVal : "";
13319
+ const headersObj = {};
13320
+ if (headersVal && typeof headersVal === "object" && !Array.isArray(headersVal)) {
13321
+ for (const [k, v] of Object.entries(headersVal)) {
13322
+ headersObj[k] = String(v);
13323
+ }
13324
+ }
13325
+ try {
13326
+ const response = await fetch(url, {
13327
+ method: "GET",
13328
+ headers: headersObj
13329
+ });
13330
+ return await response.text();
13331
+ } catch (e2) {
13332
+ throw new Error(`web_get failed: ${e2.message}`);
13333
+ }
13334
+ }
13335
+ });
13336
+ builtins.set("web_send", {
13337
+ type: "function",
13338
+ name: "web_send",
13339
+ params: [{ name: "url" }, { name: "body" }, { name: "headers", defaultValue: {} }],
13340
+ body: {},
13341
+ closure: {},
13342
+ isBuiltin: true,
13343
+ builtin: async (...args2) => {
13344
+ const [urlVal, bodyVal, headersVal] = args2;
13345
+ const url = typeof urlVal === "string" ? urlVal : "";
13346
+ const body = typeof bodyVal === "string" ? bodyVal : JSON.stringify(bodyVal);
13347
+ const headersObj = { "Content-Type": "application/json" };
13348
+ if (headersVal && typeof headersVal === "object" && !Array.isArray(headersVal)) {
13349
+ for (const [k, v] of Object.entries(headersVal)) {
13350
+ headersObj[k] = String(v);
13351
+ }
13352
+ }
13353
+ try {
13354
+ const response = await fetch(url, {
13355
+ method: "POST",
13356
+ headers: headersObj,
13357
+ body
13358
+ });
13359
+ return await response.text();
13360
+ } catch (e2) {
13361
+ throw new Error(`web_send failed: ${e2.message}`);
13362
+ }
13363
+ }
13364
+ });
13365
+ builtins.set("multi_req", {
13366
+ type: "function",
13367
+ name: "multi_req",
13368
+ params: [{ name: "fns" }],
13369
+ body: {},
13370
+ closure: {},
13371
+ isBuiltin: true,
13372
+ builtin: async (...args2) => {
13373
+ const [fnsVal] = args2;
13374
+ if (!Array.isArray(fnsVal)) {
13375
+ throw new Error("multi_req expects an array of functions");
13376
+ }
13377
+ if (!interpreter) {
13378
+ throw new Error("multi_req interpreter reference is missing");
13379
+ }
13380
+ const promises = fnsVal.map(async (fn) => {
13381
+ if (typeof fn !== "object" || fn === null || fn.type !== "function") {
13382
+ throw new Error("multi_req elements must be functions");
13383
+ }
13384
+ return await interpreter.callSesiFunction(fn, []);
13385
+ });
13386
+ return await Promise.all(promises);
13387
+ }
13388
+ });
13276
13389
  return builtins;
13277
13390
  }
13278
13391
  function isTruthy(value) {
@@ -25413,9 +25526,9 @@ var require_util2 = __commonJS({
25413
25526
  });
25414
25527
  return object;
25415
25528
  }
25416
- async function isValidFile(filePath2) {
25529
+ async function isValidFile(filePath) {
25417
25530
  try {
25418
- const stats = await fs3.promises.lstat(filePath2);
25531
+ const stats = await fs3.promises.lstat(filePath);
25419
25532
  return stats.isFile();
25420
25533
  } catch (e2) {
25421
25534
  return false;
@@ -30105,16 +30218,16 @@ var require_pluggable_auth_handler = __commonJS({
30105
30218
  if (!this.outputFile || this.outputFile.length === 0) {
30106
30219
  return void 0;
30107
30220
  }
30108
- let filePath2;
30221
+ let filePath;
30109
30222
  try {
30110
- filePath2 = await fs3.promises.realpath(this.outputFile);
30223
+ filePath = await fs3.promises.realpath(this.outputFile);
30111
30224
  } catch {
30112
30225
  return void 0;
30113
30226
  }
30114
- if (!(await fs3.promises.lstat(filePath2)).isFile()) {
30227
+ if (!(await fs3.promises.lstat(filePath)).isFile()) {
30115
30228
  return void 0;
30116
30229
  }
30117
- const responseString = await fs3.promises.readFile(filePath2, {
30230
+ const responseString = await fs3.promises.readFile(filePath, {
30118
30231
  encoding: "utf8"
30119
30232
  });
30120
30233
  if (responseString === "") {
@@ -30836,22 +30949,22 @@ var require_googleauth = __commonJS({
30836
30949
  * @returns Promise that resolves with the OAuth2Client
30837
30950
  * @api private
30838
30951
  */
30839
- async _getApplicationCredentialsFromFilePath(filePath2, options = {}) {
30840
- if (!filePath2 || filePath2.length === 0) {
30952
+ async _getApplicationCredentialsFromFilePath(filePath, options = {}) {
30953
+ if (!filePath || filePath.length === 0) {
30841
30954
  throw new Error("The file path is invalid.");
30842
30955
  }
30843
30956
  try {
30844
- filePath2 = fs3.realpathSync(filePath2);
30845
- if (!fs3.lstatSync(filePath2).isFile()) {
30957
+ filePath = fs3.realpathSync(filePath);
30958
+ if (!fs3.lstatSync(filePath).isFile()) {
30846
30959
  throw new Error();
30847
30960
  }
30848
30961
  } catch (err) {
30849
30962
  if (err instanceof Error) {
30850
- err.message = `The file at ${filePath2} does not exist, or it is not a file. ${err.message}`;
30963
+ err.message = `The file at ${filePath} does not exist, or it is not a file. ${err.message}`;
30851
30964
  }
30852
30965
  throw err;
30853
30966
  }
30854
- const readStream = fs3.createReadStream(filePath2);
30967
+ const readStream = fs3.createReadStream(filePath);
30855
30968
  return this.fromStream(readStream, options);
30856
30969
  }
30857
30970
  /**
@@ -31163,8 +31276,8 @@ var require_googleauth = __commonJS({
31163
31276
  if (this.jsonContent) {
31164
31277
  return this._cacheClientFromJSON(this.jsonContent, this.clientOptions);
31165
31278
  } else if (this.keyFilename) {
31166
- const filePath2 = path2.resolve(this.keyFilename);
31167
- const stream = fs3.createReadStream(filePath2);
31279
+ const filePath = path2.resolve(this.keyFilename);
31280
+ const stream = fs3.createReadStream(filePath);
31168
31281
  return await this.fromStreamAsync(stream, this.clientOptions);
31169
31282
  } else if (this.apiKey) {
31170
31283
  const client = await this.fromAPIKey(this.apiKey, this.clientOptions);
@@ -53289,8 +53402,8 @@ ${underline}`);
53289
53402
  * @param filePath The path to the file.
53290
53403
  * @returns The MIME type of the file, or undefined if it cannot be inferred.
53291
53404
  */
53292
- inferMimeType(filePath2) {
53293
- const fileExtension = filePath2.slice(filePath2.lastIndexOf(".") + 1);
53405
+ inferMimeType(filePath) {
53406
+ const fileExtension = filePath.slice(filePath.lastIndexOf(".") + 1);
53294
53407
  const mimeTypes = {
53295
53408
  "aac": "audio/aac",
53296
53409
  "abw": "application/x-abiword",
@@ -53723,8 +53836,47 @@ ${underline}`);
53723
53836
  var require_ai_runtime = __commonJS({
53724
53837
  "dist/ai-runtime.js"(exports2) {
53725
53838
  "use strict";
53839
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m2, k, k2) {
53840
+ if (k2 === void 0) k2 = k;
53841
+ var desc = Object.getOwnPropertyDescriptor(m2, k);
53842
+ if (!desc || ("get" in desc ? !m2.__esModule : desc.writable || desc.configurable)) {
53843
+ desc = { enumerable: true, get: function() {
53844
+ return m2[k];
53845
+ } };
53846
+ }
53847
+ Object.defineProperty(o, k2, desc);
53848
+ }) : (function(o, m2, k, k2) {
53849
+ if (k2 === void 0) k2 = k;
53850
+ o[k2] = m2[k];
53851
+ }));
53852
+ var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o, v) {
53853
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
53854
+ }) : function(o, v) {
53855
+ o["default"] = v;
53856
+ });
53857
+ var __importStar = exports2 && exports2.__importStar || /* @__PURE__ */ (function() {
53858
+ var ownKeys = function(o) {
53859
+ ownKeys = Object.getOwnPropertyNames || function(o2) {
53860
+ var ar = [];
53861
+ for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
53862
+ return ar;
53863
+ };
53864
+ return ownKeys(o);
53865
+ };
53866
+ return function(mod) {
53867
+ if (mod && mod.__esModule) return mod;
53868
+ var result = {};
53869
+ if (mod != null) {
53870
+ for (var k = ownKeys(mod), i2 = 0; i2 < k.length; i2++) if (k[i2] !== "default") __createBinding(result, mod, k[i2]);
53871
+ }
53872
+ __setModuleDefault(result, mod);
53873
+ return result;
53874
+ };
53875
+ })();
53726
53876
  Object.defineProperty(exports2, "__esModule", { value: true });
53727
53877
  exports2.aiRuntime = exports2.AIRuntime = void 0;
53878
+ var fs3 = __importStar(require("fs"));
53879
+ var path2 = __importStar(require("path"));
53728
53880
  var AIRuntime = class {
53729
53881
  constructor() {
53730
53882
  this._client = null;
@@ -53741,13 +53893,97 @@ var require_ai_runtime = __commonJS({
53741
53893
  }
53742
53894
  return this._client;
53743
53895
  }
53896
+ getCacheFile() {
53897
+ return path2.resolve(process.cwd(), ".sesi_cache.json");
53898
+ }
53899
+ readCache() {
53900
+ const file = this.getCacheFile();
53901
+ if (fs3.existsSync(file)) {
53902
+ try {
53903
+ return JSON.parse(fs3.readFileSync(file, "utf-8"));
53904
+ } catch (e2) {
53905
+ return {};
53906
+ }
53907
+ }
53908
+ return {};
53909
+ }
53910
+ writeCache(cache) {
53911
+ const file = this.getCacheFile();
53912
+ try {
53913
+ fs3.writeFileSync(file, JSON.stringify(cache, null, 2), "utf-8");
53914
+ } catch (e2) {
53915
+ }
53916
+ }
53917
+ computeCacheHash(request) {
53918
+ const crypto2 = require("crypto");
53919
+ const hash = crypto2.createHash("sha256");
53920
+ const input = {
53921
+ model: request.model,
53922
+ prompt: request.prompt,
53923
+ temperature: request.temperature,
53924
+ maxTokens: request.maxTokens,
53925
+ topK: request.topK,
53926
+ topP: request.topP,
53927
+ ratio: request.ratio,
53928
+ size: request.size,
53929
+ images: request.images,
53930
+ thinkingLevel: request.thinkingLevel
53931
+ };
53932
+ hash.update(JSON.stringify(input));
53933
+ return hash.digest("hex");
53934
+ }
53935
+ resolveImageParts(imagePaths) {
53936
+ const mimeMap = {
53937
+ ".jpg": "image/jpeg",
53938
+ ".jpeg": "image/jpeg",
53939
+ ".png": "image/png",
53940
+ ".gif": "image/gif",
53941
+ ".webp": "image/webp",
53942
+ ".bmp": "image/bmp"
53943
+ };
53944
+ const parts = [];
53945
+ for (const imgPath of imagePaths) {
53946
+ const abs = path2.isAbsolute(imgPath) ? imgPath : path2.resolve(process.cwd(), imgPath);
53947
+ const ext = path2.extname(abs).toLowerCase();
53948
+ const mimeType = mimeMap[ext] ?? "image/jpeg";
53949
+ const data = fs3.readFileSync(abs).toString("base64");
53950
+ parts.push({ inlineData: { mimeType, data } });
53951
+ }
53952
+ return parts;
53953
+ }
53744
53954
  async callModel(request) {
53955
+ const useCache = request.cache !== false;
53956
+ let cacheHash = "";
53957
+ if (useCache) {
53958
+ cacheHash = this.computeCacheHash(request);
53959
+ const cache = this.readCache();
53960
+ if (cache[cacheHash]) {
53961
+ console.log("\u26A1 [Sesi Logic Cache] Served from local cache");
53962
+ return cache[cacheHash];
53963
+ }
53964
+ }
53745
53965
  try {
53746
53966
  const client = this.client;
53747
53967
  const timeContext = `[System context: Current date and time is ${(/* @__PURE__ */ new Date()).toUTCString()}]
53748
53968
 
53749
53969
  `;
53750
53970
  const fullPrompt = timeContext + request.prompt;
53971
+ let thinkingConfig = void 0;
53972
+ if (request.thinkingLevel) {
53973
+ const thinking = request.thinkingLevel.thinking !== "no";
53974
+ const level = request.thinkingLevel.level || "low";
53975
+ const isGemini3 = request.model.includes("gemini-3");
53976
+ if (isGemini3) {
53977
+ const isPro = request.model.includes("pro");
53978
+ thinkingConfig = {
53979
+ thinkingLevel: thinking ? level : isPro ? "low" : "minimal"
53980
+ };
53981
+ } else {
53982
+ thinkingConfig = {
53983
+ thinkingBudget: thinking ? level === "low" ? 1024 : level === "medium" ? 2048 : 4096 : 0
53984
+ };
53985
+ }
53986
+ }
53751
53987
  if (request.model.includes("image")) {
53752
53988
  const imageConfig = {};
53753
53989
  if (request.ratio)
@@ -53768,9 +54004,11 @@ var require_ai_runtime = __commonJS({
53768
54004
  configObj.topK = request.topK;
53769
54005
  if (request.topP !== void 0)
53770
54006
  configObj.topP = request.topP;
54007
+ if (thinkingConfig)
54008
+ configObj.thinkingConfig = thinkingConfig;
53771
54009
  const response = await client.models.generateContent({
53772
54010
  model: request.model,
53773
- contents: request.prompt,
54011
+ contents: request.images && request.images.length > 0 ? [{ role: "user", parts: [...this.resolveImageParts(request.images), { text: request.prompt }] }] : request.prompt,
53774
54012
  config: configObj
53775
54013
  });
53776
54014
  let base64String = null;
@@ -53785,7 +54023,7 @@ var require_ai_runtime = __commonJS({
53785
54023
  if (!base64String) {
53786
54024
  throw new Error("Image generation failed or returned no image output.");
53787
54025
  }
53788
- return {
54026
+ const resObj2 = {
53789
54027
  text: base64String,
53790
54028
  // Return the base64 string directly
53791
54029
  finishReason: "STOP",
@@ -53794,6 +54032,12 @@ var require_ai_runtime = __commonJS({
53794
54032
  outputTokens: 0
53795
54033
  }
53796
54034
  };
54035
+ if (useCache) {
54036
+ const cache = this.readCache();
54037
+ cache[cacheHash] = resObj2;
54038
+ this.writeCache(cache);
54039
+ }
54040
+ return resObj2;
53797
54041
  }
53798
54042
  let accumulatedText = "";
53799
54043
  let currentFinishReason = "";
@@ -53802,9 +54046,12 @@ var require_ai_runtime = __commonJS({
53802
54046
  let totalOutputTokens = 0;
53803
54047
  let maxPolls = 10;
53804
54048
  let currentPoll = 0;
53805
- const contents = [
53806
- { role: "user", parts: [{ text: fullPrompt }] }
53807
- ];
54049
+ const contents = [];
54050
+ const imageParts = request.images && request.images.length > 0 ? this.resolveImageParts(request.images) : [];
54051
+ contents.push({
54052
+ role: "user",
54053
+ parts: [...imageParts, { text: fullPrompt }]
54054
+ });
53808
54055
  while (!isComplete && currentPoll < maxPolls) {
53809
54056
  const genConfig = {
53810
54057
  temperature: request.temperature ?? 0.3,
@@ -53815,6 +54062,9 @@ var require_ai_runtime = __commonJS({
53815
54062
  if (request.tools) {
53816
54063
  genConfig.tools = request.tools;
53817
54064
  }
54065
+ if (thinkingConfig) {
54066
+ genConfig.thinkingConfig = thinkingConfig;
54067
+ }
53818
54068
  const response = await client.models.generateContent({
53819
54069
  model: request.model,
53820
54070
  contents,
@@ -53826,7 +54076,7 @@ var require_ai_runtime = __commonJS({
53826
54076
  if (candidate?.content?.parts) {
53827
54077
  for (const part of candidate.content.parts) {
53828
54078
  if (part.call) {
53829
- return {
54079
+ const toolRes = {
53830
54080
  text: JSON.stringify(part.call),
53831
54081
  finishReason: "TOOL_CALL",
53832
54082
  usage: {
@@ -53834,6 +54084,7 @@ var require_ai_runtime = __commonJS({
53834
54084
  outputTokens: response.usageMetadata?.candidatesTokenCount ?? 0
53835
54085
  }
53836
54086
  };
54087
+ return toolRes;
53837
54088
  }
53838
54089
  }
53839
54090
  }
@@ -53865,7 +54116,7 @@ var require_ai_runtime = __commonJS({
53865
54116
  if (currentFinishReason !== "STOP" && currentFinishReason !== "MAX_TOKENS") {
53866
54117
  throw new Error(`Generation did not complete successfully (finish reason: ${currentFinishReason})`);
53867
54118
  }
53868
- return {
54119
+ const resObj = {
53869
54120
  text: accumulatedText,
53870
54121
  finishReason: currentFinishReason,
53871
54122
  usage: {
@@ -53873,6 +54124,12 @@ var require_ai_runtime = __commonJS({
53873
54124
  outputTokens: totalOutputTokens
53874
54125
  }
53875
54126
  };
54127
+ if (useCache) {
54128
+ const cache = this.readCache();
54129
+ cache[cacheHash] = resObj;
54130
+ this.writeCache(cache);
54131
+ }
54132
+ return resObj;
53876
54133
  } catch (error) {
53877
54134
  throw new Error(`Sesi: ${error.message}`);
53878
54135
  }
@@ -53940,13 +54197,14 @@ var require_interpreter = __commonJS({
53940
54197
  var types_1 = require_types2();
53941
54198
  var builtins_1 = require_builtins();
53942
54199
  var ai_runtime_1 = require_ai_runtime();
53943
- var Interpreter = class {
54200
+ var Interpreter = class _Interpreter {
53944
54201
  constructor() {
53945
54202
  this.prompts = /* @__PURE__ */ new Map();
53946
54203
  this.memory = /* @__PURE__ */ new Map();
54204
+ this.exports = /* @__PURE__ */ new Map();
53947
54205
  this.globalEnv = new types_1.Environment();
53948
54206
  this.currentEnv = this.globalEnv;
53949
- const builtins = (0, builtins_1.getBuiltins)();
54207
+ const builtins = (0, builtins_1.getBuiltins)(this);
53950
54208
  for (const [name, fn] of builtins) {
53951
54209
  this.globalEnv.define(name, fn);
53952
54210
  }
@@ -53995,10 +54253,10 @@ var require_interpreter = __commonJS({
53995
54253
  await this.executeMemory(statement);
53996
54254
  break;
53997
54255
  case "ImportStatement":
53998
- console.log("Import not yet implemented");
54256
+ await this.executeImport(statement);
53999
54257
  break;
54000
54258
  case "ExportStatement":
54001
- console.log("Export not yet implemented");
54259
+ await this.executeExport(statement);
54002
54260
  break;
54003
54261
  }
54004
54262
  }
@@ -54264,28 +54522,7 @@ var require_interpreter = __commonJS({
54264
54522
  for (const arg of expr.arguments) {
54265
54523
  args2.push(await this.evaluateExpression(arg));
54266
54524
  }
54267
- if (fn.isBuiltin && fn.builtin) {
54268
- return fn.builtin(...args2);
54269
- }
54270
- const callEnv = new types_1.Environment(fn.closure);
54271
- for (let i2 = 0; i2 < fn.params.length; i2++) {
54272
- const param = fn.params[i2];
54273
- const value = i2 < args2.length ? args2[i2] : param.defaultValue ? await this.evaluateExpression(param.defaultValue) : null;
54274
- callEnv.define(param.name, value);
54275
- }
54276
- const previous = this.currentEnv;
54277
- this.currentEnv = callEnv;
54278
- try {
54279
- await this.executeBlock(fn.body, callEnv);
54280
- return null;
54281
- } catch (e2) {
54282
- if (e2 instanceof types_1.ReturnValue) {
54283
- return e2.value;
54284
- }
54285
- throw e2;
54286
- } finally {
54287
- this.currentEnv = previous;
54288
- }
54525
+ return await this.callSesiFunction(fn, args2);
54289
54526
  }
54290
54527
  async evaluateMember(expr) {
54291
54528
  const obj = await this.evaluateExpression(expr.object);
@@ -54335,6 +54572,29 @@ var require_interpreter = __commonJS({
54335
54572
  if (typeof promptText !== "string") {
54336
54573
  promptText = (0, builtins_1.stringify)(promptText);
54337
54574
  }
54575
+ let imagePaths;
54576
+ if (expr.images) {
54577
+ const raw = await this.evaluateExpression(expr.images);
54578
+ if (Array.isArray(raw)) {
54579
+ imagePaths = raw.map((v) => (0, builtins_1.stringify)(v));
54580
+ } else if (typeof raw === "string" && raw.trim() !== "") {
54581
+ imagePaths = [raw];
54582
+ }
54583
+ }
54584
+ let thinkingLevel;
54585
+ if (expr.config?.thinkingLevel) {
54586
+ const raw = await this.evaluateExpression(expr.config.thinkingLevel);
54587
+ if (typeof raw === "object" && raw !== null) {
54588
+ thinkingLevel = raw;
54589
+ }
54590
+ }
54591
+ let cache;
54592
+ if (expr.config?.cache) {
54593
+ const raw = await this.evaluateExpression(expr.config.cache);
54594
+ if (typeof raw === "boolean") {
54595
+ cache = raw;
54596
+ }
54597
+ }
54338
54598
  const response = await ai_runtime_1.aiRuntime.callModel({
54339
54599
  model: expr.modelName,
54340
54600
  prompt: promptText,
@@ -54343,7 +54603,10 @@ var require_interpreter = __commonJS({
54343
54603
  topK: expr.config?.top_k ? await this.evaluateExpression(expr.config.top_k) : void 0,
54344
54604
  topP: expr.config?.top_p ? await this.evaluateExpression(expr.config.top_p) : void 0,
54345
54605
  ratio: expr.config?.ratio ? await this.evaluateExpression(expr.config.ratio) : void 0,
54346
- size: expr.config?.size ? await this.evaluateExpression(expr.config.size) : void 0
54606
+ size: expr.config?.size ? await this.evaluateExpression(expr.config.size) : void 0,
54607
+ images: imagePaths,
54608
+ thinkingLevel,
54609
+ cache
54347
54610
  });
54348
54611
  return response.text;
54349
54612
  }
@@ -54352,11 +54615,37 @@ var require_interpreter = __commonJS({
54352
54615
  if (typeof promptText !== "string") {
54353
54616
  promptText = (0, builtins_1.stringify)(promptText);
54354
54617
  }
54618
+ let imagePaths;
54619
+ if (expr.images) {
54620
+ const raw = await this.evaluateExpression(expr.images);
54621
+ if (Array.isArray(raw)) {
54622
+ imagePaths = raw.map((v) => (0, builtins_1.stringify)(v));
54623
+ } else if (typeof raw === "string" && raw.trim() !== "") {
54624
+ imagePaths = [raw];
54625
+ }
54626
+ }
54627
+ let thinkingLevel;
54628
+ if (expr.config?.thinkingLevel) {
54629
+ const raw = await this.evaluateExpression(expr.config.thinkingLevel);
54630
+ if (typeof raw === "object" && raw !== null) {
54631
+ thinkingLevel = raw;
54632
+ }
54633
+ }
54634
+ let cache;
54635
+ if (expr.config?.cache) {
54636
+ const raw = await this.evaluateExpression(expr.config.cache);
54637
+ if (typeof raw === "boolean") {
54638
+ cache = raw;
54639
+ }
54640
+ }
54355
54641
  const response = await ai_runtime_1.aiRuntime.callModel({
54356
54642
  model: expr.modelName,
54357
54643
  prompt: promptText,
54358
54644
  temperature: expr.config?.temperature ? await this.evaluateExpression(expr.config.temperature) : void 0,
54359
- maxTokens: expr.config?.max_tokens ? await this.evaluateExpression(expr.config.max_tokens) : void 0
54645
+ maxTokens: expr.config?.max_tokens ? await this.evaluateExpression(expr.config.max_tokens) : void 0,
54646
+ images: imagePaths,
54647
+ thinkingLevel,
54648
+ cache
54360
54649
  });
54361
54650
  return response.text;
54362
54651
  }
@@ -54378,20 +54667,22 @@ var require_interpreter = __commonJS({
54378
54667
  for (const arg of expr.arguments) {
54379
54668
  args2.push(await this.evaluateExpression(arg));
54380
54669
  }
54381
- const runtimeFn = fn;
54382
- if (runtimeFn.isBuiltin && runtimeFn.builtin) {
54383
- return runtimeFn.builtin(...args2);
54670
+ return await this.callSesiFunction(fn, args2);
54671
+ }
54672
+ async callSesiFunction(fn, args2) {
54673
+ if (fn.isBuiltin && fn.builtin) {
54674
+ return await fn.builtin(...args2);
54384
54675
  }
54385
- const callEnv = new types_1.Environment(runtimeFn.closure);
54386
- for (let i2 = 0; i2 < runtimeFn.params.length; i2++) {
54387
- const param = runtimeFn.params[i2];
54676
+ const callEnv = new types_1.Environment(fn.closure);
54677
+ for (let i2 = 0; i2 < fn.params.length; i2++) {
54678
+ const param = fn.params[i2];
54388
54679
  const value = i2 < args2.length ? args2[i2] : param.defaultValue ? await this.evaluateExpression(param.defaultValue) : null;
54389
54680
  callEnv.define(param.name, value);
54390
54681
  }
54391
54682
  const previous = this.currentEnv;
54392
54683
  this.currentEnv = callEnv;
54393
54684
  try {
54394
- await this.executeBlock(runtimeFn.body, callEnv);
54685
+ await this.executeBlock(fn.body, callEnv);
54395
54686
  return null;
54396
54687
  } catch (e2) {
54397
54688
  if (e2 instanceof types_1.ReturnValue) {
@@ -54402,6 +54693,141 @@ var require_interpreter = __commonJS({
54402
54693
  this.currentEnv = previous;
54403
54694
  }
54404
54695
  }
54696
+ async executeExport(stmt) {
54697
+ await this.executeStatement(stmt.statement);
54698
+ const name = stmt.statement.name;
54699
+ const val = this.currentEnv.get(name);
54700
+ this.exports.set(name, val);
54701
+ }
54702
+ async executeImport(stmt) {
54703
+ const source = stmt.source;
54704
+ let moduleExports = null;
54705
+ if (source.startsWith("std/")) {
54706
+ moduleExports = this.loadStdModule(source);
54707
+ } else {
54708
+ const fs3 = require("fs");
54709
+ const path2 = require("path");
54710
+ let filePath = source;
54711
+ if (!filePath.endsWith(".sesi")) {
54712
+ filePath += ".sesi";
54713
+ }
54714
+ const resolvedPath = path2.resolve(process.cwd(), filePath);
54715
+ if (!fs3.existsSync(resolvedPath)) {
54716
+ throw new Error(`Module not found: ${source}`);
54717
+ }
54718
+ const content = fs3.readFileSync(resolvedPath, "utf-8");
54719
+ const { Lexer } = require_lexer();
54720
+ const { Parser } = require_parser();
54721
+ const lexer = new Lexer(content);
54722
+ const parser = new Parser(lexer.scanTokens());
54723
+ const program = parser.parse();
54724
+ const subInterpreter = new _Interpreter();
54725
+ await subInterpreter.interpret(program);
54726
+ moduleExports = subInterpreter.exports;
54727
+ }
54728
+ if (!moduleExports) {
54729
+ throw new Error(`Failed to load module: ${source}`);
54730
+ }
54731
+ if (stmt.names.length === 1 && stmt.names[0] === stmt.names[0].toLowerCase() && !moduleExports.has(stmt.names[0])) {
54732
+ const nsObj = {};
54733
+ for (const [key, val] of moduleExports.entries()) {
54734
+ nsObj[key] = val;
54735
+ }
54736
+ this.currentEnv.define(stmt.names[0], nsObj);
54737
+ } else {
54738
+ for (const name of stmt.names) {
54739
+ if (!moduleExports.has(name)) {
54740
+ throw new Error(`Module "${source}" does not export "${name}"`);
54741
+ }
54742
+ this.currentEnv.define(name, moduleExports.get(name));
54743
+ }
54744
+ }
54745
+ }
54746
+ loadStdModule(source) {
54747
+ const exports3 = /* @__PURE__ */ new Map();
54748
+ if (source === "std/math") {
54749
+ exports3.set("PI", Math.PI);
54750
+ exports3.set("E", Math.E);
54751
+ const mathFns = ["sin", "cos", "tan", "sqrt", "floor", "ceil", "abs", "pow", "log", "exp"];
54752
+ for (const name of mathFns) {
54753
+ exports3.set(name, {
54754
+ type: "function",
54755
+ name,
54756
+ params: name === "pow" ? [{ name: "x" }, { name: "y" }] : [{ name: "x" }],
54757
+ body: {},
54758
+ closure: {},
54759
+ isBuiltin: true,
54760
+ builtin: (...args2) => {
54761
+ const x2 = typeof args2[0] === "number" ? args2[0] : 0;
54762
+ if (name === "pow") {
54763
+ const y = typeof args2[1] === "number" ? args2[1] : 0;
54764
+ return Math.pow(x2, y);
54765
+ }
54766
+ return Math[name](x2);
54767
+ }
54768
+ });
54769
+ }
54770
+ return exports3;
54771
+ } else if (source === "std/time") {
54772
+ exports3.set("now", {
54773
+ type: "function",
54774
+ name: "now",
54775
+ params: [],
54776
+ body: {},
54777
+ closure: {},
54778
+ isBuiltin: true,
54779
+ builtin: (...args2) => Date.now()
54780
+ });
54781
+ exports3.set("sleep", {
54782
+ type: "function",
54783
+ name: "sleep",
54784
+ params: [{ name: "ms" }],
54785
+ body: {},
54786
+ closure: {},
54787
+ isBuiltin: true,
54788
+ builtin: async (...args2) => {
54789
+ const [ms] = args2;
54790
+ const duration = typeof ms === "number" ? ms : 0;
54791
+ await new Promise((resolve) => setTimeout(resolve, duration));
54792
+ return null;
54793
+ }
54794
+ });
54795
+ return exports3;
54796
+ } else if (source === "std/json") {
54797
+ exports3.set("stringify", {
54798
+ type: "function",
54799
+ name: "stringify",
54800
+ params: [{ name: "val" }],
54801
+ body: {},
54802
+ closure: {},
54803
+ isBuiltin: true,
54804
+ builtin: (...args2) => {
54805
+ const [val] = args2;
54806
+ return JSON.stringify(val);
54807
+ }
54808
+ });
54809
+ exports3.set("parse", {
54810
+ type: "function",
54811
+ name: "parse",
54812
+ params: [{ name: "str" }],
54813
+ body: {},
54814
+ closure: {},
54815
+ isBuiltin: true,
54816
+ builtin: (...args2) => {
54817
+ const [str] = args2;
54818
+ if (typeof str !== "string")
54819
+ return null;
54820
+ try {
54821
+ return JSON.parse(str);
54822
+ } catch (e2) {
54823
+ return null;
54824
+ }
54825
+ }
54826
+ });
54827
+ return exports3;
54828
+ }
54829
+ return null;
54830
+ }
54405
54831
  };
54406
54832
  exports2.Interpreter = Interpreter;
54407
54833
  }
@@ -54469,13 +54895,13 @@ var require_dist5 = __commonJS({
54469
54895
  process.exit(1);
54470
54896
  }
54471
54897
  }
54472
- async function runSesiFile2(filePath2) {
54898
+ async function runSesiFile2(filePath) {
54473
54899
  try {
54474
- const filepath = path2.resolve(filePath2);
54900
+ const filepath = path2.resolve(filePath);
54475
54901
  const source = fs3.readFileSync(filepath, "utf-8");
54476
54902
  await runSesi(source);
54477
54903
  } catch (error) {
54478
- console.error(`Error reading file ${filePath2}:`, error.message);
54904
+ console.error(`Error reading file ${filePath}:`, error.message);
54479
54905
  process.exit(1);
54480
54906
  }
54481
54907
  }
@@ -54490,48 +54916,49 @@ var path = require("path");
54490
54916
  var args = process.argv.slice(2);
54491
54917
  if (args.length === 0) {
54492
54918
  console.log(`
54493
- Sesi Programming Language v1.1.1
54919
+ Sesi Programming Language v1.2.0
54494
54920
 
54495
54921
  Usage:
54496
54922
  sesi <file> Run a Sesi program
54497
- sesi --help Show this help
54498
-
54499
- Examples:
54500
- sesi main/start.sesi
54501
- sesi examples/01_hello.sesi
54502
- `);
54503
- process.exit(0);
54504
- }
54505
- if (args[0] === "--help" || args[0] === "-h") {
54506
- console.log(`
54507
- Sesi Programming Language v1.1.1
54923
+ sesi -help <query> Ask for help from our Sesi Co-Pilot
54924
+ sesi --help <query>
54925
+ sesi -h <query>
54508
54926
 
54509
- Usage:
54510
- sesi <file> Run a Sesi program
54511
- sesi --help Show this help
54512
-
54513
- Options:
54927
+ Options:
54514
54928
  --version Show version
54515
-
54929
+
54516
54930
  Examples:
54517
54931
  sesi main/start.sesi
54518
54932
  sesi examples/01_hello.sesi
54933
+ sesi -help "how do I parse a json string?"
54519
54934
  `);
54520
54935
  process.exit(0);
54521
54936
  }
54522
- if (args[0] === "--version") {
54523
- console.log("Sesi v1.1.1");
54937
+ if (args[0] === "--help" || args[0] === "-help" || args[0] === "-h") {
54938
+ let queryText = args.slice(1).join(" ").trim();
54939
+ if (!queryText) {
54940
+ queryText = "how do I parse a json string?";
54941
+ }
54942
+ fs2.writeFileSync("query.txt", queryText, "utf-8");
54943
+ const copilotPath = path.join(__dirname, "../main/sesi_db_chatbot.sesi");
54944
+ runSesiFile(copilotPath).catch((error) => {
54945
+ console.error("Fatal error in RAG Co-Pilot:", error.message);
54946
+ process.exit(1);
54947
+ });
54948
+ } else if (args[0] === "--version") {
54949
+ console.log("Sesi v1.2.0");
54524
54950
  process.exit(0);
54951
+ } else {
54952
+ const filePath = args[0];
54953
+ if (!fs2.existsSync(filePath)) {
54954
+ console.error(`Error: File not found: ${filePath}`);
54955
+ process.exit(1);
54956
+ }
54957
+ runSesiFile(filePath).catch((error) => {
54958
+ console.error("Fatal error:", error.message);
54959
+ process.exit(1);
54960
+ });
54525
54961
  }
54526
- var filePath = args[0];
54527
- if (!fs2.existsSync(filePath)) {
54528
- console.error(`Error: File not found: ${filePath}`);
54529
- process.exit(1);
54530
- }
54531
- runSesiFile(filePath).catch((error) => {
54532
- console.error("Fatal error:", error.message);
54533
- process.exit(1);
54534
- });
54535
54962
  /*! Bundled license information:
54536
54963
 
54537
54964
  @noble/ciphers/utils.js: