@gencode/server 0.3.17 → 0.4.1
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/CHANGELOG.md +27 -0
- package/README.md +64 -5
- package/dist/bin.js +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +1 -1
- package/dist/server-CqLVjhiC.js +1 -0
- package/package.json +4 -3
- package/dist/server-DPKs0UO_.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @gencode/server
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [2ab7f63]
|
|
8
|
+
- Updated dependencies [2ab7f63]
|
|
9
|
+
- Updated dependencies [eb5c06b]
|
|
10
|
+
- @gencode/agents@0.20.0
|
|
11
|
+
- @gencode/cli@0.17.2
|
|
12
|
+
|
|
13
|
+
## 0.4.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- f40c79a: `POST /run` now accepts an optional `engine` object with `runtimeAgent` and `runtimeConfig`. When `engine` is present, the server executes via `@gencode/uni` instead of the legacy CLI run path. Requests without `engine` keep the existing behavior unchanged. Supported `runtimeAgent` values are `claude-code`, `codex`, `opencode`, `pi`, and `acp` (no aliases).
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [cc36dad]
|
|
22
|
+
- Updated dependencies [18fd7a1]
|
|
23
|
+
- Updated dependencies [8170e03]
|
|
24
|
+
- Updated dependencies [f40c79a]
|
|
25
|
+
- Updated dependencies [0d0e504]
|
|
26
|
+
- @gencode/agents@0.19.1
|
|
27
|
+
- @gencode/cli@0.17.1
|
|
28
|
+
- @gencode/uni@0.3.0
|
|
29
|
+
|
|
3
30
|
## 0.3.17
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
One-shot AIMax container prestart server.
|
|
4
4
|
|
|
5
5
|
This package starts a local HTTP process that warms system-level runtime state,
|
|
6
|
-
accepts exactly one `/run` request,
|
|
7
|
-
|
|
6
|
+
accepts exactly one `/run` request, executes the task, and exits when the run
|
|
7
|
+
finishes.
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
@@ -14,9 +14,38 @@ aimax-server --host 127.0.0.1 --port 0 --plugins-config /image/aimax/plugins.jso
|
|
|
14
14
|
|
|
15
15
|
`--plugins-config` can also be supplied as `AIMAX_SERVER_PLUGINS_CONFIG`. The
|
|
16
16
|
server reads that file during warmup and preloads the configured system plugins.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
|
|
18
|
+
## Execution paths
|
|
19
|
+
|
|
20
|
+
`POST /run` supports two execution branches:
|
|
21
|
+
|
|
22
|
+
- **Without `engine` (default):** delegates to `@gencode/cli/run.executeRun()`.
|
|
23
|
+
If the accepted request does not provide `run.pluginsConfig` and does not
|
|
24
|
+
override `AIMAX_PLUGINS_CONFIG` in request `env`, the run inherits the
|
|
25
|
+
startup plugins config path so the CLI execution uses the preloaded plugin
|
|
26
|
+
registry.
|
|
27
|
+
- **With `engine`:** delegates to `@gencode/uni.executeUniRun()`. The server
|
|
28
|
+
merges `run` with `engine.runtimeAgent` and optional `engine.runtimeConfig`,
|
|
29
|
+
removes uni-unsupported fields via `omitUnsupportedUniRunOptions()`, and does
|
|
30
|
+
**not** inherit startup `pluginsConfig` or call the CLI run path.
|
|
31
|
+
|
|
32
|
+
Request shape:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
type ServerRunRequest = {
|
|
36
|
+
env?: Record<string, string | number | boolean | null>;
|
|
37
|
+
run: RunOptions;
|
|
38
|
+
engine?: {
|
|
39
|
+
runtimeAgent: "claude-code" | "codex" | "opencode" | "pi" | "acp";
|
|
40
|
+
runtimeConfig?: UniRuntimeConfig;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`engine.runtimeAgent` uses `UniRuntimeAgent` values directly; aliases such as
|
|
46
|
+
`claudecode` are not supported.
|
|
47
|
+
|
|
48
|
+
## `/run` without `engine`
|
|
20
49
|
|
|
21
50
|
`POST /run` accepts the same run options as `aimax run` under `run`, using the
|
|
22
51
|
CLI `RunOptions` camelCase field names. For example, `--session-id` becomes
|
|
@@ -77,3 +106,33 @@ Resume-related run options are also forwarded through the same CLI path:
|
|
|
77
106
|
}
|
|
78
107
|
}
|
|
79
108
|
```
|
|
109
|
+
|
|
110
|
+
## `/run` with `engine`
|
|
111
|
+
|
|
112
|
+
Use `engine` when the container should run via `@gencode/uni` instead of the
|
|
113
|
+
legacy agents/CLI path:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"env": {
|
|
118
|
+
"AIMAX_DATA_DIR": "/data/user1",
|
|
119
|
+
"OPENAI_API_KEY": "sk-xxx"
|
|
120
|
+
},
|
|
121
|
+
"run": {
|
|
122
|
+
"projectDir": "/data/user1/workspace/repo",
|
|
123
|
+
"message": "hello",
|
|
124
|
+
"output": "json"
|
|
125
|
+
},
|
|
126
|
+
"engine": {
|
|
127
|
+
"runtimeAgent": "codex",
|
|
128
|
+
"runtimeConfig": {
|
|
129
|
+
"command": "codex",
|
|
130
|
+
"args": ["exec"]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Top-level `env` still applies during execution. Unsupported uni fields present in
|
|
137
|
+
`run` (for example `pluginsConfig`, `agent`, resume fields) are removed before
|
|
138
|
+
`executeUniRun()`; they do not cause a 400 response.
|
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{t as e}from"./server-
|
|
2
|
+
import{t as e}from"./server-CqLVjhiC.js";function t(e){let t=!1;return()=>{t||(t=!0,n(e))}}async function n(e){let t=e.exit??(e=>process.exit(e)),n=e.onLog??(()=>void 0),a=e.graceMs??3e4,o=e.server.getStatus();if(!r(o)){await e.server.stop().catch(e=>{n(`server shutdown stop failed`,{error:String(e),status:o})}),t(0);return}n(`server shutdown signal received; waiting for active run`,{status:o,graceMs:a}),await e.server.stop().catch(e=>{n(`server shutdown stop failed`,{error:String(e),status:o})});let s=await i(e.server.done,a);if(s.timedOut){n(`server shutdown grace period elapsed before run finished`,{status:o,graceMs:a}),t(1);return}n(`server shutdown completed after active run finished`,{status:o,exitCode:s.exitCode}),t(s.exitCode)}function r(e){return e===`running`||e===`draining`}async function i(e,t){let n,r=new Promise(e=>{n=setTimeout(()=>e({timedOut:!0}),t),n.unref?.()});try{return await Promise.race([e.then(e=>({timedOut:!1,exitCode:e.exitCode})),r])}finally{n&&clearTimeout(n)}}function a(e){let t={};for(let n=0;n<e.length;n+=1){let r=e[n];if(r===`--host`){t.host=e[++n];continue}if(r===`--port`){t.port=o(e[++n],`--port`);continue}if(r===`--plugins-config`){t.pluginsConfig=s(e[++n],`--plugins-config`);continue}if(r===`--request-timeout-ms`){t.requestTimeoutMs=c(e[++n],`--request-timeout-ms`);continue}if(r===`--shutdown-grace-ms`){t.shutdownGraceMs=c(e[++n],`--shutdown-grace-ms`);continue}throw(r===`--help`||r===`-h`)&&(l(),process.exit(0)),Error(`Unknown option: ${r}`)}return t}function o(e,t){let n=c(e,t);if(n>65535)throw Error(`Invalid ${t}: ${e}. Must be between 0 and 65535.`);return n}function s(e,t){if(e===void 0||e.trim()===``)throw Error(`Missing value for ${t}`);return e}function c(e,t){if(e===void 0||e.trim()===``)throw Error(`Missing value for ${t}`);let n=Number(e);if(!Number.isInteger(n)||n<0)throw Error(`Invalid ${t}: ${e}. Must be a non-negative integer.`);return n}function l(){process.stdout.write(`AIMax one-shot prestart server
|
|
3
3
|
|
|
4
4
|
Usage:
|
|
5
5
|
aimax-server [--host 127.0.0.1] [--port 0] [--plugins-config /image/plugins.json] [--request-timeout-ms 60000] [--shutdown-grace-ms 30000]
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { RunOptions } from "@gencode/cli/run";
|
|
2
|
+
import { UniRunOptions, UniRuntimeAgent, UniRuntimeConfig } from "@gencode/uni";
|
|
2
3
|
|
|
3
4
|
//#region src/server.d.ts
|
|
4
5
|
type AimaxServerStatus = "starting" | "warming" | "ready" | "ready_degraded" | "running" | "draining" | "exiting";
|
|
6
|
+
type ServerRunEngineOptions = {
|
|
7
|
+
runtimeAgent: UniRuntimeAgent;
|
|
8
|
+
runtimeConfig?: UniRuntimeConfig;
|
|
9
|
+
};
|
|
5
10
|
type ServerRunRequest = {
|
|
6
11
|
env?: ServerRequestEnv;
|
|
7
12
|
run: ServerRunOptions;
|
|
13
|
+
engine?: ServerRunEngineOptions;
|
|
8
14
|
};
|
|
9
15
|
type ServerRunOptions = RunOptions;
|
|
10
16
|
type ServerRequestEnv = Record<string, string | number | boolean | null>;
|
|
@@ -21,6 +27,7 @@ type AimaxServerOptions = {
|
|
|
21
27
|
maxBodyBytes?: number;
|
|
22
28
|
requestTimeoutMs?: number;
|
|
23
29
|
executeRun?: (options: ServerRunOptions) => Promise<void>;
|
|
30
|
+
executeUniRun?: (options: UniRunOptions) => Promise<void>;
|
|
24
31
|
prepareSystemRuntime?: (options?: ServerWarmupOptions) => SystemWarmState | Promise<SystemWarmState>;
|
|
25
32
|
onLog?: (message: string, details?: Record<string, unknown>) => void;
|
|
26
33
|
};
|
|
@@ -38,4 +45,4 @@ type AimaxServerHandle = {
|
|
|
38
45
|
};
|
|
39
46
|
declare function createAimaxServer(options?: AimaxServerOptions): AimaxServerHandle;
|
|
40
47
|
//#endregion
|
|
41
|
-
export { type AimaxServerHandle, type AimaxServerOptions, type AimaxServerStatus, type ServerRequestEnv, type ServerRunOptions, type ServerRunRequest, createAimaxServer };
|
|
48
|
+
export { type AimaxServerHandle, type AimaxServerOptions, type AimaxServerStatus, type ServerRequestEnv, type ServerRunEngineOptions, type ServerRunOptions, type ServerRunRequest, createAimaxServer };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./server-
|
|
1
|
+
import{t as e}from"./server-CqLVjhiC.js";export{e as createAimaxServer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:http";import t from"node:fs/promises";import{executeRun as n}from"@gencode/cli/run";import{executeUniRun as r,omitUnsupportedUniRunOptions as i}from"@gencode/uni";import{prepareSystemRuntime as a}from"@gencode/agents/system-runtime";function o(t={}){let n=t.host??`127.0.0.1`,a=t.port??0,o=t.maxBodyBytes??1048576,u=t.executeRun??p,d=t.executeUniRun??r,v=t.prepareSystemRuntime??m,y=t.onLog??(()=>void 0),b=t.pluginsConfig,x=`starting`,S,C,w=null,T=!1,E=()=>void 0,D=new Promise(e=>{E=e});function O(e){T||(T=!0,E(e))}function k(e){x=e,y(`server status changed`,{status:e})}async function A(){let e=w;w=null,!(!e||!e.listening)&&await new Promise((t,n)=>{e.close(e=>{e?n(e):t()})})}async function j(e,t){let n=s();if(x===`starting`||x===`warming`){_(t,503,{status:x,error:`server is not ready`});return}if(x!==`ready`&&x!==`ready_degraded`){_(t,409,{status:x,error:`server already accepted a run`});return}let r;try{r=l(await g(e,o))}catch(e){_(t,400,{status:x,error:e.message});return}k(`running`),A().catch(e=>{y(`failed to close listener after accepting run`,{error:String(e)})});let i=s();_(t,202,{status:x,accepted:!0,receivedAt:n,respondedAt:i}),M(r,{receivedAt:n,respondedAt:i,acceptedAtMs:Date.now()})}async function M(e,t){let n=0;try{let r=Date.now();if(y(`accepted run execution starting`,{receivedAt:t.receivedAt,respondedAt:t.respondedAt,delayAfterAcceptedMs:r-t.acceptedAtMs}),e.engine){let{options:n,omittedKeys:a}=i({...e.run,runtimeAgent:e.engine.runtimeAgent,runtimeConfig:e.engine.runtimeConfig});a.length>0&&y(`server.run.uni.omittedUnsupportedOptions`,{omittedKeys:a}),y(`invoking uni run`,{runtimeAgent:e.engine.runtimeAgent,dataDir:n.dataDir,sessionId:n.sessionId,messageId:n.messageId,delayAfterAcceptedMs:Date.now()-t.acceptedAtMs}),await f(e.env,()=>d(n)),y(`uni run completed`,{durationMs:Date.now()-r})}else{let n=c(e.run,e.env,C);y(`invoking CLI run`,{dataDir:n.dataDir,sessionId:n.sessionId,messageId:n.messageId,delayAfterAcceptedMs:Date.now()-t.acceptedAtMs}),await f(e.env,()=>u(n)),y(`CLI run completed`,{durationMs:Date.now()-r})}typeof process.exitCode==`number`&&process.exitCode!==0&&(n=process.exitCode),k(`draining`)}catch(e){n=1,y(`run failed`,{error:String(e)}),k(`draining`)}finally{await A().catch(e=>{y(`failed to stop server during drain`,{error:String(e)})}),k(`exiting`),O({exitCode:n})}}async function N(e,t){let r=new URL(e.url??`/`,`http://${n}`);if(e.method===`GET`&&r.pathname===`/healthz`){_(t,200,{status:x});return}if(e.method===`GET`&&r.pathname===`/readyz`){let e=x===`ready`||x===`ready_degraded`;_(t,e?200:503,{status:x,ready:e,degraded:x===`ready_degraded`,warmupError:S});return}if(e.method===`POST`&&r.pathname===`/run`){await j(e,t);return}_(t,404,{status:x,error:`not found`})}async function P(){if(!w){k(`warming`),w=e.createServer((e,t)=>{N(e,t).catch(e=>{_(t,500,{status:x,error:String(e)})})}),await new Promise((e,t)=>{w.once(`error`,t),w.listen(a,n,()=>{w.off(`error`,t),e()})});try{let e=b?await h(b):void 0;e!==void 0&&(C=b),await v({pluginsConfig:e}),x===`warming`&&k(`ready`)}catch(e){S=String(e),y(`system warmup failed; continuing with cold run path`,{error:S}),x===`warming`&&k(`ready_degraded`)}t.requestTimeoutMs&&t.requestTimeoutMs>0&&setTimeout(()=>{(x===`ready`||x===`ready_degraded`)&&A().finally(()=>{k(`exiting`),O({exitCode:1})})},t.requestTimeoutMs).unref()}}function F(){if(!w?.listening)return``;let e=w.address();return`http://${e.address}:${e.port}`}return{start:P,stop:A,done:D,getStatus:()=>x,getUrl:F}}function s(e=new Date){let t=new Intl.DateTimeFormat(`en-CA`,{timeZone:`Asia/Shanghai`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}),n=Object.fromEntries(t.formatToParts(e).map(e=>[e.type,e.value])),r=String(e.getMilliseconds()).padStart(3,`0`);return`${n.year}-${n.month}-${n.day} ${n.hour}:${n.minute}:${n.second}.${r}`}function c(e,t,n){return!n||Object.prototype.hasOwnProperty.call(e,`pluginsConfig`)||t&&Object.prototype.hasOwnProperty.call(t,`AIMAX_PLUGINS_CONFIG`)?e:{...e,pluginsConfig:n}}function l(e){if(!e||typeof e!=`object`)throw Error(`request body must be an object`);let t=e.env;t!==void 0&&d(t);let n=e.run;if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`request body must include run options`);let r=e.engine;return r!==void 0&&u(r),{env:t,run:n,engine:r}}function u(e){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`request engine must be an object when provided`);let t=e.runtimeAgent;if(typeof t!=`string`||!t.trim())throw Error(`request engine must include runtimeAgent`);let n=e.runtimeConfig;if(n!==void 0&&(typeof n!=`object`||!n||Array.isArray(n)))throw Error(`request engine runtimeConfig must be an object when provided`)}function d(e){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`request env must be an object when provided`);for(let[t,n]of Object.entries(e)){if(!t||t.includes(`=`))throw Error(`request env contains invalid key: ${t}`);if(n!==null&&typeof n!=`string`&&typeof n!=`number`&&typeof n!=`boolean`)throw Error(`request env value for ${t} must be string, number, boolean, or null`)}}async function f(e,t){if(!e||Object.keys(e).length===0)return t();let n=new Map;for(let[t,r]of Object.entries(e))n.set(t,process.env[t]),r===null?delete process.env[t]:process.env[t]=String(r);try{return await t()}finally{for(let[e,t]of n)t===void 0?delete process.env[e]:process.env[e]=t}}async function p(e){await n(e)}async function m(e={}){return a({config:e.pluginsConfig})}async function h(e){let n=await t.readFile(e,`utf-8`);return JSON.parse(n)}async function g(e,t){let n=[],r=0;for await(let i of e){let e=Buffer.isBuffer(i)?i:Buffer.from(i);if(r+=e.byteLength,r>t)throw Error(`request body is too large`);n.push(e)}let i=Buffer.concat(n).toString(`utf-8`);if(!i.trim())throw Error(`request body must not be empty`);try{return JSON.parse(i)}catch{throw Error(`request body must be valid JSON`)}}function _(e,t,n){e.headersSent||(e.writeHead(t,{"content-type":`application/json; charset=utf-8`}),e.end(`${JSON.stringify(n)}\n`))}export{o as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gencode/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"aimax-server": "./dist/bin.js"
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@gencode/agents": "0.
|
|
23
|
-
"@gencode/
|
|
22
|
+
"@gencode/agents": "0.20.0",
|
|
23
|
+
"@gencode/uni": "0.3.0",
|
|
24
|
+
"@gencode/cli": "0.17.2"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/node": "^22.0.0",
|
package/dist/server-DPKs0UO_.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"node:http";import t from"node:fs/promises";import{executeRun as n}from"@gencode/cli/run";import{prepareSystemRuntime as r}from"@gencode/agents/system-runtime";function i(t={}){let n=t.host??`127.0.0.1`,r=t.port??0,i=t.maxBodyBytes??1048576,c=t.executeRun??u,h=t.prepareSystemRuntime??d,g=t.onLog??(()=>void 0),_=t.pluginsConfig,v=`starting`,y,b,x=null,S=!1,C=()=>void 0,w=new Promise(e=>{C=e});function T(e){S||(S=!0,C(e))}function E(e){v=e,g(`server status changed`,{status:e})}async function D(){let e=x;x=null,!(!e||!e.listening)&&await new Promise((t,n)=>{e.close(e=>{e?n(e):t()})})}async function O(e,t){let n=a();if(v===`starting`||v===`warming`){m(t,503,{status:v,error:`server is not ready`});return}if(v!==`ready`&&v!==`ready_degraded`){m(t,409,{status:v,error:`server already accepted a run`});return}let r;try{r=s(await p(e,i))}catch(e){m(t,400,{status:v,error:e.message});return}E(`running`),D().catch(e=>{g(`failed to close listener after accepting run`,{error:String(e)})});let o=a();m(t,202,{status:v,accepted:!0,receivedAt:n,respondedAt:o}),k(r,{receivedAt:n,respondedAt:o,acceptedAtMs:Date.now()})}async function k(e,t){let n=0;try{let r=Date.now();g(`accepted run execution starting`,{receivedAt:t.receivedAt,respondedAt:t.respondedAt,delayAfterAcceptedMs:r-t.acceptedAtMs});let i=o(e.run,e.env,b);g(`invoking CLI run`,{dataDir:i.dataDir,sessionId:i.sessionId,messageId:i.messageId,delayAfterAcceptedMs:Date.now()-t.acceptedAtMs}),await l(e.env,()=>c(i)),g(`CLI run completed`,{durationMs:Date.now()-r}),typeof process.exitCode==`number`&&process.exitCode!==0&&(n=process.exitCode),E(`draining`)}catch(e){n=1,g(`run failed`,{error:String(e)}),E(`draining`)}finally{await D().catch(e=>{g(`failed to stop server during drain`,{error:String(e)})}),E(`exiting`),T({exitCode:n})}}async function A(e,t){let r=new URL(e.url??`/`,`http://${n}`);if(e.method===`GET`&&r.pathname===`/healthz`){m(t,200,{status:v});return}if(e.method===`GET`&&r.pathname===`/readyz`){let e=v===`ready`||v===`ready_degraded`;m(t,e?200:503,{status:v,ready:e,degraded:v===`ready_degraded`,warmupError:y});return}if(e.method===`POST`&&r.pathname===`/run`){await O(e,t);return}m(t,404,{status:v,error:`not found`})}async function j(){if(!x){E(`warming`),x=e.createServer((e,t)=>{A(e,t).catch(e=>{m(t,500,{status:v,error:String(e)})})}),await new Promise((e,t)=>{x.once(`error`,t),x.listen(r,n,()=>{x.off(`error`,t),e()})});try{let e=_?await f(_):void 0;e!==void 0&&(b=_),await h({pluginsConfig:e}),v===`warming`&&E(`ready`)}catch(e){y=String(e),g(`system warmup failed; continuing with cold run path`,{error:y}),v===`warming`&&E(`ready_degraded`)}t.requestTimeoutMs&&t.requestTimeoutMs>0&&setTimeout(()=>{(v===`ready`||v===`ready_degraded`)&&D().finally(()=>{E(`exiting`),T({exitCode:1})})},t.requestTimeoutMs).unref()}}function M(){if(!x?.listening)return``;let e=x.address();return`http://${e.address}:${e.port}`}return{start:j,stop:D,done:w,getStatus:()=>v,getUrl:M}}function a(e=new Date){let t=new Intl.DateTimeFormat(`en-CA`,{timeZone:`Asia/Shanghai`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}),n=Object.fromEntries(t.formatToParts(e).map(e=>[e.type,e.value])),r=String(e.getMilliseconds()).padStart(3,`0`);return`${n.year}-${n.month}-${n.day} ${n.hour}:${n.minute}:${n.second}.${r}`}function o(e,t,n){return!n||Object.prototype.hasOwnProperty.call(e,`pluginsConfig`)||t&&Object.prototype.hasOwnProperty.call(t,`AIMAX_PLUGINS_CONFIG`)?e:{...e,pluginsConfig:n}}function s(e){if(!e||typeof e!=`object`)throw Error(`request body must be an object`);let t=e.env;t!==void 0&&c(t);let n=e.run;if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`request body must include run options`);return{env:t,run:n}}function c(e){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`request env must be an object when provided`);for(let[t,n]of Object.entries(e)){if(!t||t.includes(`=`))throw Error(`request env contains invalid key: ${t}`);if(n!==null&&typeof n!=`string`&&typeof n!=`number`&&typeof n!=`boolean`)throw Error(`request env value for ${t} must be string, number, boolean, or null`)}}async function l(e,t){if(!e||Object.keys(e).length===0)return t();let n=new Map;for(let[t,r]of Object.entries(e))n.set(t,process.env[t]),r===null?delete process.env[t]:process.env[t]=String(r);try{return await t()}finally{for(let[e,t]of n)t===void 0?delete process.env[e]:process.env[e]=t}}async function u(e){await n(e)}async function d(e={}){return r({config:e.pluginsConfig})}async function f(e){let n=await t.readFile(e,`utf-8`);return JSON.parse(n)}async function p(e,t){let n=[],r=0;for await(let i of e){let e=Buffer.isBuffer(i)?i:Buffer.from(i);if(r+=e.byteLength,r>t)throw Error(`request body is too large`);n.push(e)}let i=Buffer.concat(n).toString(`utf-8`);if(!i.trim())throw Error(`request body must not be empty`);try{return JSON.parse(i)}catch{throw Error(`request body must be valid JSON`)}}function m(e,t,n){e.headersSent||(e.writeHead(t,{"content-type":`application/json; charset=utf-8`}),e.end(`${JSON.stringify(n)}\n`))}export{i as t};
|