aimyapi 1.0.2 → 1.0.3

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
@@ -8,16 +8,13 @@ AIMyAPI will handle async operations and timers in your API object.
8
8
 
9
9
  ## About version 1.0 rewrite and motivation
10
10
 
11
- AIMyAPI was originally written at a time (circa ChatGPT 3.5 / GPT-4) before tool calling existed, before Claude code and codex and just before OpenAI released their code interpreter. LLM models have also gotten drastically better since. Some of the problems it originally aimed to solve are better solved today with simple tool calling. However, there is still a need to safely run small programs in a sandboxed way, reliable way. Tools are good if you have a set interface but there may be times that an agent needs to do some sorting or filtering, or an algorithm or analysis, or some repeatable workflow which isn't implemented by the available tool functions. Writing code allows the agent to do things it might not otherwise be able to do with tools alone.
11
+ AIMyAPI was originally written at a time (circa ChatGPT 3.5 / GPT-4) before tool calling existed, before Claude code and codex and just before OpenAI released their code interpreter. LLM models have also gotten drastically better since. Some of the problems it originally aimed to solve are better solved today with simple tool calling. However, there is still a need to safely run small programs in a sandboxed way, reliable way. Tools are good if you have a set interface but there may be times that an agent needs to do some sorting or filtering, or an algorithm or analysis, or some repeatable workflow which isn't implemented by the available tool functions. Writing code allows the agent to do things it might not otherwise be able to do with tools alone. Having the ability to write code allows the tools API surface to be smaller; it could simply be a set of CRUD operations.
12
12
 
13
- Having the ability to write code allows the tools API surface to be smaller; it could simply be a set of CRUD operations.
14
-
15
- The other advantage of writing code is privacy and security. When an agent executes code in a sandbox, it doesn't see any of the results*, API keys or other things you may want to keep hidden. When an agent uses tools, it sees all the parameters and results of the tool calls. Code can be audited for security and correctness before running it. Finally, code can encompass a series of operations, whereas tool calls need to be approved one at a time or just trusted often without knowing what will come next.
16
-
17
- *You'll have the option to hide logs and errors from the agent - logging can allow the agent to fix it's own coding mistakes and test the code, but it also allows information to leave the sandbox which you may want to limit depending on the sensitivity the data your api is handling. Another approach would be to implement a mocked version of your API that the agent can use to write code and debug against while keeping your real data hidden and safe from potentially destructive operations.
13
+ The other advantage of writing code is privacy and security. When an agent executes code in a sandbox, it doesn't see any of the results*, API keys or other things you may want to keep hidden. When an agent uses tools, it sees all the parameters and results of the tool calls. Code can be audited for security and correctness before running it. Finally, code can encompass a series of operations, whereas tool calls need to be approved one at a time or just trusted, often without knowing what will come next.
18
14
 
19
15
  Version 1.0 updates AIMyAPI code generation to use the tool calling process for writing code. This allows the agent to check the code and run some tests or API calls before committing to a final version. This should result in better code since the previous model relied on the agent always being able to one-shot the code, which depended on it having a complete view of the problem before writing the code which wasn't always realistic. We could also update this process a bit to add "Plan" / "Build" / "Test" phases instead of just one code generation prompt.
20
16
 
17
+ *You'll have the option to hide logs and errors from the agent - logging can allow the agent to fix it's own coding mistakes and test the code, but it also allows information to leave the sandbox which you may want to limit depending on the sensitivity the data your api is handling. Another approach would be to implement a mocked version of your API that the agent can use to write code and debug against while keeping your real data hidden and safe from potentially destructive operations.
21
18
 
22
19
  ## Quickstart
23
20
 
@@ -1,6 +1,5 @@
1
1
  import path from "path";
2
2
  import { AIMyAPI } from "../src";
3
- import * as APIExports from "./sales_api";
4
3
  import { API } from "./sales_api_impl";
5
4
 
6
5
  // Simpler example using no support for chat history;
@@ -11,7 +10,6 @@ import { API } from "./sales_api_impl";
11
10
  const aimyapi = await AIMyAPI.createWithAPI({
12
11
  apiObject: api,
13
12
  apiGlobalName: "salesApi", // Should match whatever you declared as your global in your api.
14
- apiExports: APIExports,
15
13
  apiDefFilePath: path.join(__dirname, "./sales_api.ts"),
16
14
  apiDocsPath: path.join(__dirname, "./sales_api.md"),
17
15
  debug: false,
@@ -2,7 +2,7 @@
2
2
 
3
3
  import path from "path";
4
4
  import { AIMyAPI } from "../src";
5
- import * as APIExports from "./ordering_api";
5
+ import { Menu } from "./ordering_api";
6
6
  import { OrderingAPI } from "./ordering_api_impl";
7
7
 
8
8
  // More complex fast food ordering example that uses chat history.
@@ -15,9 +15,8 @@ import { OrderingAPI } from "./ordering_api_impl";
15
15
  apiObject: orderingApi,
16
16
  apiGlobalName: "orderingApi", // Should match whatever you declared as your global in your ordering api.
17
17
  apiGlobals: {
18
- Menu: APIExports.Menu,
18
+ Menu: Menu,
19
19
  },
20
- apiExports: APIExports,
21
20
  apiDefFilePath: path.join(__dirname, "./ordering_api.ts"),
22
21
  apiDocsPath: path.join(__dirname, "./ordering_api.md"),
23
22
  debug: false,
@@ -1,7 +1,7 @@
1
1
 
2
2
  import path from "path";
3
3
  import { AIMyAPI } from "../src";
4
- import * as APIExports from "./ordering_api";
4
+ import { Menu } from "./ordering_api";
5
5
  import { OrderingAPI } from "./ordering_api_impl";
6
6
 
7
7
  import readline from 'readline';
@@ -28,9 +28,8 @@ function getInput(query: string): Promise<string> {
28
28
  apiObject: orderingApi,
29
29
  apiGlobalName: "orderingApi", // Should match whatever you declared as your global in your ordering api.
30
30
  apiGlobals: {
31
- Menu: APIExports.Menu,
31
+ Menu: Menu,
32
32
  },
33
- apiExports: APIExports,
34
33
  apiDefFilePath: path.join(__dirname, "./ordering_api.ts"),
35
34
  apiDocsPath: path.join(__dirname, "./ordering_api.md"),
36
35
  debug: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aimyapi",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "AI My API! Typescript sandbox for AI agents to interact with your API in a safe way.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -13,13 +13,13 @@ import { AutoParseableTool } from 'openai/lib/parser.js';
13
13
  import { ZodSchema, z } from 'zod';
14
14
  import { zodToJsonSchema } from 'zod-to-json-schema';
15
15
 
16
- const openai = new OpenAI();
16
+ const openai = new OpenAI( { baseURL: process.env.OPENAI_API_BASE_URL || undefined, apiKey: process.env.OPENAI_API_KEY || undefined } );
17
17
 
18
18
  let QuickJS:QuickJSWASMModule | null = null;
19
19
 
20
20
  export interface AIMyAPIOptions {
21
21
  apiObject: object;
22
- apiExports: object;
22
+ apiExports?: object;
23
23
  apiWhitelist?: string[]; // List of functions to expose to the user. Necessary to pass this yourself if you are extending your api from another class.
24
24
  apiGlobals?: object;
25
25
  apiDefFilePath: string; // Full path to the api definition file so that it can be loaded into the prompt
@@ -222,7 +222,7 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<AIMyAPIInstance> {
222
222
  apiGlobals: {},
223
223
  apiWhitelist: Object.getOwnPropertyNames(Object.getPrototypeOf(options.apiObject)).filter((f) => f !== "constructor" && !f.startsWith("_")),
224
224
  debug: false,
225
- model: process.env.OPENAI_API_MODEL ||"gpt-5.4-mini",
225
+ model: process.env.OPENAI_API_MODEL || "gpt-5.4-mini",
226
226
  additionalModelOptions: {},
227
227
  hideLogsFromAgent: false,
228
228
  },
@@ -274,9 +274,9 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<AIMyAPIInstance> {
274
274
  }
275
275
 
276
276
  // Create sandbox
277
- const {vm, checkCode} = await createSandbox(QuickJS, {
277
+ const {vm, checkCode} = await createSandbox(QuickJS, apiExports ? {
278
278
  [apiDefFilePath]: apiExports,
279
- }, {
279
+ } : undefined, {
280
280
  ...apiGlobals,
281
281
  [apiGlobalName]: {
282
282
  value: apiObject,
@@ -348,9 +348,9 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<AIMyAPIInstance> {
348
348
 
349
349
  // Create sandbox
350
350
  // NOTE: not sure why I have to replace the backslash here
351
- const {vm, runCode: runTask, isAsyncProcessRunning} = await createSandbox(QuickJS, {
351
+ const {vm, runCode: runTask, isAsyncProcessRunning} = await createSandbox(QuickJS, apiExports ? {
352
352
  [apiDefFilePath]: apiExports,
353
- }, {
353
+ } : undefined, {
354
354
  ...apiGlobals,
355
355
  [apiGlobalName]: {
356
356
  value: apiObject,