aimyapi 0.1.13 → 0.1.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/dist/index.mjs ADDED
@@ -0,0 +1,468 @@
1
+ import { createRequire } from 'module';
2
+ import fs from 'fs';
3
+ import { OpenAI } from 'openai';
4
+ import path from 'path';
5
+ import { getQuickJS } from 'quickjs-emscripten';
6
+ import * as ts from 'typescript';
7
+
8
+ var require$1 = (
9
+ true
10
+ ? /* @__PURE__ */ createRequire(import.meta.url)
11
+ : require
12
+ );
13
+
14
+ let promiseId = 0;
15
+ let openPromises = {};
16
+ function wrapPromise(vm, promise, beginAsyncProcess, endAsyncProcess) {
17
+ promiseId += 1;
18
+ const vmPromise = vm.newPromise();
19
+ vmPromise._promiseId = promiseId;
20
+ beginAsyncProcess();
21
+ promise.then((...args) => {
22
+ endAsyncProcess();
23
+ const wrappedArgs = args.map((arg) => wrap(vm, arg, void 0, beginAsyncProcess, endAsyncProcess));
24
+ openPromises[vmPromise._promiseId] = null;
25
+ vmPromise.resolve(...wrappedArgs);
26
+ wrappedArgs.forEach((arg) => arg.dispose());
27
+ }).catch((...args) => {
28
+ const wrappedArgs = args.map((arg) => wrap(vm, arg, void 0, beginAsyncProcess, endAsyncProcess));
29
+ vmPromise.reject(...wrappedArgs);
30
+ wrappedArgs.forEach((arg) => arg.dispose());
31
+ openPromises[vmPromise._promiseId] = null;
32
+ });
33
+ vmPromise.settled.then(() => {
34
+ endAsyncProcess();
35
+ vm.runtime.executePendingJobs();
36
+ });
37
+ openPromises[promiseId] = vmPromise;
38
+ return vmPromise.handle;
39
+ }
40
+ function rejectOpenPromises(vm) {
41
+ for (const [id, promise] of Object.entries(openPromises)) {
42
+ if (promise !== null) {
43
+ promise.reject(vm.newError("Shutting down"));
44
+ openPromises[id] = null;
45
+ }
46
+ }
47
+ vm.runtime.executePendingJobs();
48
+ }
49
+ function wrap(vm, value, context, beginAsyncProcess, endAsyncProcess) {
50
+ if (value === null) {
51
+ return null;
52
+ } else if (typeof value === "object" && typeof value.then === "function") {
53
+ return wrapPromise(vm, value, beginAsyncProcess, endAsyncProcess);
54
+ } else if (typeof value === "function") {
55
+ return wrapGenericFunction(vm, value, context, beginAsyncProcess, endAsyncProcess);
56
+ } else if (Array.isArray(value)) {
57
+ return wrapArray(vm, value, beginAsyncProcess, endAsyncProcess);
58
+ } else if (value === null) {
59
+ return vm.null;
60
+ } else if (typeof value === "object") {
61
+ return wrapObject(vm, value, beginAsyncProcess, endAsyncProcess);
62
+ } else if (typeof value === "string") {
63
+ return vm.newString(value);
64
+ } else if (typeof value === "number") {
65
+ return vm.newNumber(value);
66
+ } else if (typeof value === "bigint") {
67
+ return vm.newBigInt(value);
68
+ } else if (typeof value === "boolean") {
69
+ return vm.evalCode(value ? "true" : "false").value;
70
+ } else if (typeof value === "undefined") {
71
+ return vm.undefined;
72
+ } else {
73
+ return null;
74
+ }
75
+ }
76
+ function wrapObject(vm, obj, beginAsyncProcess, endAsyncProcess) {
77
+ const vmObject = vm.newObject();
78
+ for (const [key, value] of Object.entries(obj)) {
79
+ let wrappedValue = wrap(vm, value, obj, beginAsyncProcess, endAsyncProcess);
80
+ if (wrappedValue !== null) {
81
+ vm.setProp(vmObject, key, wrappedValue);
82
+ if (wrappedValue != vm.undefined && wrappedValue != vm.null && wrappedValue.dispose) {
83
+ wrappedValue.dispose();
84
+ }
85
+ }
86
+ }
87
+ return vmObject;
88
+ }
89
+ function wrapObjectWhitelist(vm, obj, whitelist, beginAsyncProcess, endAsyncProcess) {
90
+ const vmObject = vm.newObject();
91
+ whitelist.forEach((key) => {
92
+ const value = obj[key];
93
+ const wrappedValue = wrap(vm, value, obj, beginAsyncProcess, endAsyncProcess);
94
+ if (wrappedValue !== null) {
95
+ vm.setProp(vmObject, key, wrappedValue);
96
+ if (wrappedValue != vm.undefined && wrappedValue != vm.null && wrappedValue.dispose) {
97
+ wrappedValue.dispose();
98
+ }
99
+ }
100
+ });
101
+ return vmObject;
102
+ }
103
+ function wrapArray(vm, arr, beginAsyncProcess, endAsyncProcess) {
104
+ const vmArray = vm.newArray();
105
+ for (let i = 0; i < arr.length; i++) {
106
+ let wrappedValue = wrap(vm, arr[i], arr, beginAsyncProcess, endAsyncProcess);
107
+ vm.setProp(vmArray, i, wrappedValue);
108
+ if (wrappedValue != vm.undefined && wrappedValue != vm.null) {
109
+ wrappedValue.dispose();
110
+ }
111
+ }
112
+ return vmArray;
113
+ }
114
+ function wrapGenericFunction(vm, fn, context = void 0, beginAsyncProcess, endAsyncProcess) {
115
+ const vmFn = vm.newFunction(fn.name, (...args) => {
116
+ const unwrappedArgs = args.map(vm.dump);
117
+ try {
118
+ const result = fn.call(context, ...unwrappedArgs);
119
+ const wrappedResult = wrap(vm, result, void 0, beginAsyncProcess, endAsyncProcess);
120
+ return wrappedResult;
121
+ } catch (e) {
122
+ console.log("Error", e);
123
+ }
124
+ });
125
+ return vmFn;
126
+ }
127
+ function injectTimingFunctions(vm, cbAddedTimer, cbRemovedTimer, maxTimeout = 6e5) {
128
+ const timeoutFunctionHandles = {};
129
+ const _setTimeout = vm.newFunction("setTimeout", (vmFnHandle, timeoutHandle) => {
130
+ const vmFnHandleCopy = vmFnHandle.dup();
131
+ let timeout = vm.dump(timeoutHandle);
132
+ if (timeout > maxTimeout) {
133
+ timeout = maxTimeout;
134
+ }
135
+ cbAddedTimer();
136
+ const timeoutID = setTimeout(() => {
137
+ timeoutFunctionHandles[timeoutID.toString()] = null;
138
+ cbRemovedTimer();
139
+ vm.callFunction(vmFnHandleCopy, vm.undefined);
140
+ vmFnHandleCopy.dispose();
141
+ vm.runtime.executePendingJobs();
142
+ }, timeout);
143
+ timeoutFunctionHandles[timeoutID.toString()] = vmFnHandleCopy;
144
+ return vm.newNumber(timeoutID);
145
+ });
146
+ vm.setProp(vm.global, "setTimeout", _setTimeout);
147
+ _setTimeout.dispose();
148
+ const intervalFunctionHandles = {};
149
+ const _setInterval = vm.newFunction("setInterval", (vmFnHandle, timeoutHandle) => {
150
+ const vmFnHandleCopy = vmFnHandle.dup();
151
+ let timeout = vm.dump(timeoutHandle);
152
+ if (timeout > maxTimeout) {
153
+ timeout = maxTimeout;
154
+ }
155
+ const maxRepetitions = 99;
156
+ let repetitions = 0;
157
+ cbAddedTimer();
158
+ const intervalId = setInterval(() => {
159
+ repetitions += 1;
160
+ intervalFunctionHandles[intervalId.toString()] = null;
161
+ vm.callFunction(vmFnHandleCopy, vm.undefined);
162
+ vm.runtime.executePendingJobs();
163
+ if (repetitions > maxRepetitions) {
164
+ console.log("Sandbox interval exceeded max repetitions");
165
+ clearInterval(intervalId);
166
+ cbRemovedTimer();
167
+ return;
168
+ }
169
+ }, timeout);
170
+ intervalFunctionHandles[intervalId.toString()] = vmFnHandleCopy;
171
+ return vm.newNumber(intervalId);
172
+ });
173
+ vm.setProp(vm.global, "setInterval", _setInterval);
174
+ _setInterval.dispose();
175
+ const _clearTimeout = vm.newFunction("clearTimeout", (timeoutIdHandle) => {
176
+ const timeoutId = vm.dump(timeoutIdHandle);
177
+ const timeoutHandle = timeoutFunctionHandles[timeoutId.toString()];
178
+ if (timeoutHandle) {
179
+ cbRemovedTimer();
180
+ timeoutHandle.dispose();
181
+ clearTimeout(timeoutId);
182
+ }
183
+ });
184
+ vm.setProp(vm.global, "clearTimeout", _clearTimeout);
185
+ _clearTimeout.dispose();
186
+ const _clearInterval = vm.newFunction("clearInterval", (intervalIdHandle) => {
187
+ const intervalId = vm.dump(intervalIdHandle);
188
+ const intervalHandle = intervalFunctionHandles[intervalId.toString()];
189
+ if (intervalId) {
190
+ cbRemovedTimer();
191
+ intervalHandle.dispose();
192
+ clearInterval(intervalId);
193
+ }
194
+ });
195
+ vm.setProp(vm.global, "clearInterval", _clearInterval);
196
+ _clearInterval.dispose();
197
+ }
198
+
199
+ function tsCompile(source, options = null) {
200
+ if (null === options) {
201
+ options = {
202
+ compilerOptions: {
203
+ target: ts.ScriptTarget.ES2020,
204
+ module: ts.ModuleKind.None
205
+ }
206
+ };
207
+ }
208
+ return ts.transpileModule(source, options).outputText;
209
+ }
210
+ async function createSandbox(QuickJS, requireLookup = {}, globals = {}, debug = false) {
211
+ const vm = QuickJS.newContext();
212
+ let errorState = false;
213
+ let lastError = "";
214
+ let asyncProcessesRunning = 0;
215
+ let beginAsyncProcess = () => {
216
+ asyncProcessesRunning++;
217
+ };
218
+ let endAsyncProcess = () => {
219
+ if (asyncProcessesRunning > 0) {
220
+ asyncProcessesRunning--;
221
+ }
222
+ };
223
+ let isAsyncProcessRunning = () => {
224
+ return asyncProcessesRunning > 0;
225
+ };
226
+ const logHandle = vm.newFunction("log", (...args) => {
227
+ const nativeArgs = args.map(vm.dump);
228
+ console.log("QuickJS Log:", ...nativeArgs);
229
+ });
230
+ const consoleHandle = vm.newObject();
231
+ const exportsHandle = vm.newObject();
232
+ const errorHandle = vm.newFunction("error", (...args) => {
233
+ try {
234
+ const nativeArgs = args.map(vm.dump);
235
+ console.log("QuickJS console.error:", ...nativeArgs);
236
+ lastError = JSON.stringify(nativeArgs);
237
+ errorState = true;
238
+ } catch (e) {
239
+ console.log("Error in error:", e);
240
+ }
241
+ });
242
+ const globalNames = Object.getOwnPropertyNames(globals);
243
+ for (let i = 0; i < globalNames.length; i++) {
244
+ const globalOption = globals[globalNames[i]];
245
+ const globalObj = globalOption.whitelist ? wrapObjectWhitelist(
246
+ vm,
247
+ globalOption.value,
248
+ globalOption.whitelist,
249
+ beginAsyncProcess,
250
+ endAsyncProcess
251
+ ) : wrap(vm, globalOption.value, globalOption, beginAsyncProcess, endAsyncProcess);
252
+ vm.setProp(vm.global, globalNames[i], globalObj);
253
+ globalObj.dispose();
254
+ }
255
+ injectTimingFunctions(vm, beginAsyncProcess, endAsyncProcess);
256
+ const requireHandle = vm.newFunction("require", (...args) => {
257
+ const nativeArgs = args.map(vm.dump);
258
+ if (requireLookup[nativeArgs[0]]) {
259
+ const returnObj = wrapObject(vm, requireLookup[nativeArgs[0]], beginAsyncProcess, endAsyncProcess);
260
+ return returnObj;
261
+ } else {
262
+ return vm.undefined;
263
+ }
264
+ });
265
+ vm.setProp(consoleHandle, "log", logHandle);
266
+ vm.setProp(consoleHandle, "error", errorHandle);
267
+ vm.setProp(vm.global, "require", requireHandle);
268
+ vm.setProp(vm.global, "console", consoleHandle);
269
+ vm.setProp(vm.global, "exports", exportsHandle);
270
+ consoleHandle.dispose();
271
+ logHandle.dispose();
272
+ exportsHandle.dispose();
273
+ errorHandle.dispose();
274
+ requireHandle.dispose();
275
+ return {
276
+ vm,
277
+ getLastError: () => {
278
+ return lastError;
279
+ },
280
+ isAsyncProcessRunning,
281
+ runTask: (task) => {
282
+ try {
283
+ const compiled = tsCompile(task);
284
+ if (!compiled || compiled.length === 0) {
285
+ console.error("Could not compile", task);
286
+ return false;
287
+ }
288
+ errorState = false;
289
+ const result = vm.evalCode(compiled);
290
+ if (result.error) {
291
+ const lines = compiled.split("\n");
292
+ for (let i = 0; i < lines.length; i++) {
293
+ console.log(`${i + 1}: ${lines[i]}`);
294
+ }
295
+ console.log("Execution failed:", vm.dump(result.error));
296
+ result.error.dispose();
297
+ return false;
298
+ } else {
299
+ result.value.dispose();
300
+ if (errorState) {
301
+ const lines = compiled.split("\n");
302
+ for (let i = 0; i < lines.length; i++) {
303
+ console.log(`${i + 1}: ${lines[i]}`);
304
+ }
305
+ }
306
+ return !errorState;
307
+ }
308
+ } catch (e) {
309
+ console.log(e);
310
+ }
311
+ return false;
312
+ }
313
+ };
314
+ }
315
+
316
+ require$1("dotenv").config();
317
+ const openai = new OpenAI({
318
+ apiKey: process.env.OPENAI_API_KEY
319
+ // This is also the default, can be omitted
320
+ });
321
+ function createBasePrompt(apiFilePath, documentationPath) {
322
+ const apiText = fs.readFileSync(apiFilePath, "utf8");
323
+ const documentationText = documentationPath ? fs.readFileSync(documentationPath, "utf8") : "";
324
+ const createTaskPrompt = fs.readFileSync(path.join(__dirname, "../prompts/create-task-prompt.md"), "utf8").replace("{{DOCUMENTATION}}", documentationText).replace("{{API}}", apiText);
325
+ return createTaskPrompt;
326
+ }
327
+ const generateCode = async function(queryText, userChatHistory, createTaskPrompt, apiPath, debug = false, model = "gpt-4o") {
328
+ if (!queryText)
329
+ return { code: "", loggableCode: "" };
330
+ let generatedCode = "";
331
+ const prompt = createTaskPrompt.replace("{{QUERY_TEXT}}", queryText);
332
+ const messages = [
333
+ {
334
+ role: "system",
335
+ content: prompt
336
+ },
337
+ ...userChatHistory,
338
+ {
339
+ role: "user",
340
+ content: `${queryText}.
341
+ Respond only with code enclosed in \`\`\`.`,
342
+ name: "user"
343
+ }
344
+ ];
345
+ try {
346
+ const results = await openai.chat.completions.create(
347
+ {
348
+ model,
349
+ messages,
350
+ temperature: 0,
351
+ max_tokens: 700
352
+ }
353
+ );
354
+ if (debug)
355
+ console.log(results.usage);
356
+ const response = results.choices[0].message.content;
357
+ if (debug)
358
+ console.log(response);
359
+ const codeStart = response.indexOf("```");
360
+ const codeEnd = response.lastIndexOf("```");
361
+ if (codeStart === -1 || codeEnd === -1 || codeStart === codeEnd) {
362
+ return { code: "", loggableCode: "", rawResponse: response };
363
+ }
364
+ generatedCode = response.substring(codeStart + 3, codeEnd).replace("typescript", "");
365
+ const codeHeader = `import * as ApiDefs from '${apiPath}'
366
+ (async() {
367
+ try {`;
368
+ const codeFooter = `
369
+ } catch(err) {
370
+ console.error(err);
371
+ }
372
+ })();`;
373
+ return { code: codeHeader + generatedCode + codeFooter, loggableCode: generatedCode };
374
+ } catch (err) {
375
+ console.error(err);
376
+ return { code: "", loggableCode: "" };
377
+ }
378
+ };
379
+ let QuickJS = null;
380
+ async function createWithAPI(options) {
381
+ options = {
382
+ apiGlobalName: "api",
383
+ apiGlobals: {},
384
+ apiWhitelist: Object.getOwnPropertyNames(Object.getPrototypeOf(options.apiObject)).filter((f) => f !== "constructor" && !f.startsWith("_")),
385
+ debug: false,
386
+ model: "gpt-4o",
387
+ ...options
388
+ };
389
+ if (!options.apiObject || !options.apiDefFilePath) {
390
+ throw new Error("apiObject and apiFilePath are required");
391
+ }
392
+ const { apiObject, apiWhitelist, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug, model } = options;
393
+ const createTaskPrompt = createBasePrompt(apiDefFilePath, apiDocsPath);
394
+ return {
395
+ options,
396
+ generateCode: async function(queryText, userChatHistory, currentContext = void 0) {
397
+ if (!queryText)
398
+ return { code: "", loggableCode: "" };
399
+ return await generateCode(queryText, userChatHistory, createTaskPrompt.replace("{{CONTEXT}}", currentContext ? "```" + JSON.stringify(currentContext, null, 2) + "```" : ""), apiDefFilePath, debug, model);
400
+ },
401
+ runCode: async function(generatedCode) {
402
+ if (!QuickJS) {
403
+ if (debug)
404
+ console.log("Creating quick.js");
405
+ QuickJS = await getQuickJS();
406
+ }
407
+ let apiGlobals = {};
408
+ for (const key in options.apiGlobals) {
409
+ apiGlobals[key] = {
410
+ value: options.apiGlobals[key]
411
+ };
412
+ }
413
+ const { vm, runTask, isAsyncProcessRunning } = await createSandbox(QuickJS, {
414
+ [apiDefFilePath.replaceAll("\\", "")]: apiExports
415
+ }, {
416
+ ...apiGlobals,
417
+ [apiGlobalName]: {
418
+ value: apiObject,
419
+ whitelist: apiWhitelist
420
+ }
421
+ }, options.debug);
422
+ try {
423
+ if (debug) {
424
+ console.log("Running Code:\n", generatedCode);
425
+ }
426
+ const res = await runTask(generatedCode);
427
+ if (!res) {
428
+ console.error("Task unsuccessful");
429
+ }
430
+ while (isAsyncProcessRunning()) {
431
+ await new Promise((resolve) => setTimeout(resolve, 100));
432
+ }
433
+ if (debug) {
434
+ console.log("Completed");
435
+ }
436
+ } catch (err) {
437
+ if (debug) {
438
+ console.error("Error running task:", err);
439
+ }
440
+ }
441
+ await new Promise((resolve) => setTimeout(resolve, 100));
442
+ rejectOpenPromises(vm);
443
+ vm.dispose();
444
+ },
445
+ processRequest: async function(userQuery, currentContext = void 0) {
446
+ if (debug) {
447
+ console.log("Query:", userQuery);
448
+ }
449
+ console.time("Generate Task");
450
+ const generatedCode = await generateCode(userQuery, [], createTaskPrompt.replace("{{CONTEXT}}", currentContext ? "```" + JSON.stringify(currentContext, null, 2) + "```" : ""), apiDefFilePath);
451
+ console.timeEnd("Generate Task");
452
+ console.time("Run Code");
453
+ await this.runCode(generatedCode.code);
454
+ console.timeEnd("Run Code");
455
+ return generatedCode;
456
+ }
457
+ };
458
+ }
459
+ const AIMyAPI = {
460
+ // Standard way of using the library
461
+ createWithAPI,
462
+ // functions for customized usage
463
+ createBasePrompt,
464
+ generateCode,
465
+ createSandbox
466
+ };
467
+
468
+ export { AIMyAPI, createBasePrompt, generateCode };
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import AIMyAPI from "../lib";
2
+ import { AIMyAPI } from "../src";
3
3
  import * as APIExports from "./sales_api";
4
4
  import { API } from "./sales_api_impl";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import AIMyAPI, { GenerateCodeResult } from "../lib";
2
+ import { AIMyAPI, GenerateCodeResult } from "../src";
3
3
  import * as APIExports from "./ordering_api";
4
4
  import { OrderingAPI } from "./ordering_api_impl";
5
5
 
@@ -1,8 +1,8 @@
1
1
 
2
- import AIMyAPI from "../lib";
3
- import { OrderingAPI } from "./ordering_api_impl";
4
- import * as APIExports from "./ordering_api";
5
2
  import path from "path";
3
+ import { AIMyAPI } from "../src";
4
+ import * as APIExports from "./ordering_api";
5
+ import { OrderingAPI } from "./ordering_api_impl";
6
6
 
7
7
  import readline from 'readline';
8
8
 
@@ -38,7 +38,7 @@ function getInput(query): Promise<string> {
38
38
  console.log(`Query: ${query}`)
39
39
 
40
40
  // generate the code for this query
41
- const code = await aimyapi.generateCode(query, api._getHistory());
41
+ const result = await aimyapi.generateCode(query, api._getHistory());
42
42
 
43
43
  api._addMessageToHistory({
44
44
  content: query,
@@ -47,13 +47,13 @@ function getInput(query): Promise<string> {
47
47
  });
48
48
 
49
49
  api._addMessageToHistory({
50
- content: '```\n' + code.replace(options.apiDefFilePath, "./api.ts") + '\n```',
50
+ content: '```\n' + result.code.replace(options.apiDefFilePath, "./api.ts") + '\n```',
51
51
  role: "assistant",
52
52
  name: "assistant",
53
53
  });
54
54
 
55
55
  // run the code in the sandbox
56
- await aimyapi.runCode(code);
56
+ await aimyapi.runCode(result.code);
57
57
  }
58
58
 
59
59
  console.log("Welcome to the restaurant. You can ask to hear the menu or order something. What would you like to do?");
@@ -1,5 +1,5 @@
1
- import { ChatCompletionRequestMessage } from "openai";
2
- import { delay } from "../lib/utils";
1
+ import { ChatCompletionMessageParam } from "openai/resources/index.mjs";
2
+ import { delay } from "../src/utils";
3
3
  import {
4
4
  Customization,
5
5
  Menu,
@@ -14,7 +14,7 @@ export class OrderingAPI implements OrderingAPIInterface {
14
14
  private _lastOrderIdNumber: number = 0;
15
15
  public _isCompleted:boolean = false;
16
16
 
17
- private _history: ChatCompletionRequestMessage[] = [];
17
+ private _history: ChatCompletionMessageParam[] = [];
18
18
 
19
19
  // Mock implementation, doesn't actually send an email
20
20
  sendEmail(to: string, subject: string, body: string): Promise<void> {
@@ -194,11 +194,11 @@ export class OrderingAPI implements OrderingAPIInterface {
194
194
  this.respondToUser(`--\tTotal:\t\t$${this.getOrderTotal().toFixed(2)}`);
195
195
  }
196
196
 
197
- _addMessageToHistory(message: ChatCompletionRequestMessage) {
197
+ _addMessageToHistory(message: ChatCompletionMessageParam) {
198
198
  this._history.push(message);
199
199
  }
200
200
 
201
- _getHistory(): ChatCompletionRequestMessage[] {
201
+ _getHistory(): ChatCompletionMessageParam[] {
202
202
  return this._history;
203
203
  }
204
204
 
@@ -1,3 +1,5 @@
1
+ Use `api.getSalesData()` to get the sales data array.
2
+
1
3
  Examples of how you should respond:
2
4
 
3
5
  user: How are you today?
@@ -13,7 +13,7 @@ export interface APIInterface {
13
13
  sendEmail(to: string, subject: string, body: string): Promise<void>;
14
14
 
15
15
  getSalesData(): SalesData[];
16
- // Returns an array of sales data.
16
+ // Returns an array of sales data.
17
17
 
18
18
  print(text: string): void;
19
19
  // Prints the specified text to the user.
@@ -1,4 +1,4 @@
1
- import { delay } from "../lib/utils";
1
+ import { delay } from "../src/utils";
2
2
  import { APIInterface, SalesData } from "./sales_api";
3
3
 
4
4
  export class API implements APIInterface {
package/package.json CHANGED
@@ -1,17 +1,28 @@
1
1
  {
2
2
  "name": "aimyapi",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "AI My API! Use LLMs to create small programs that safely* run and make calls against your API. Similar to ChatGPT's Code Interpreter.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "module": "./dist/index.mjs",
8
+ "exports": {
9
+ "require": {
10
+ "types": "./dist/index.d.cts",
11
+ "default": "./dist/index.cjs"
12
+ },
13
+ "import": {
14
+ "types": "./dist/index.d.mts",
15
+ "default": "./dist/index.mjs"
16
+ }
17
+ },
7
18
  "directories": {
8
19
  "lib": "lib"
9
20
  },
10
21
  "scripts": {
11
- "example1": "ts-node ./example/example1.ts",
12
- "example2": "ts-node ./example/example2.ts",
13
- "example3": "ts-node ./example/example3.ts",
14
- "build": "tsc"
22
+ "example1": "tsx ./example/example1.ts",
23
+ "example2": "tsx ./example/example2.ts",
24
+ "example3": "tsx ./example/example3.ts",
25
+ "build": "pkgroll"
15
26
  },
16
27
  "repository": {
17
28
  "type": "git",
@@ -24,7 +35,7 @@
24
35
  ],
25
36
  "dependencies": {
26
37
  "dotenv": "^16.0.3",
27
- "openai": "^3.2.1",
38
+ "openai": "^4.61.0",
28
39
  "quickjs-emscripten": "^0.22.0",
29
40
  "typescript": "^5.0.3"
30
41
  },
@@ -36,6 +47,7 @@
36
47
  "homepage": "https://github.com/WhiteNoise/aimyapi#readme",
37
48
  "devDependencies": {
38
49
  "@types/node": "^18.16.2",
39
- "ts-node": "^10.9.1"
50
+ "pkgroll": "^2.5.0",
51
+ "tsx": "^4.19.1"
40
52
  }
41
53
  }
@@ -11,7 +11,7 @@ Here is the API that you will use:
11
11
 
12
12
  Documentation:
13
13
 
14
- Note: the api definitions are available as `ApiDefs`;
14
+ Note: the api definitions are available as `ApiDefs`.
15
15
 
16
16
  {{DOCUMENTATION}}
17
17