@gencode/server 0.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.
- package/CHANGELOG.md +17 -0
- package/README.md +7 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +11 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +1 -0
- package/dist/server-DdorBHmR.js +1 -0
- package/package.json +38 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @gencode/server
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5773651: Add the `aimax-server` one-shot prestart entry for container deployments. It starts a local HTTP server, warms system-level AIMax runtime state before the user request arrives, accepts one `/run` request with the same run options used by `aimax run`, delegates execution through the CLI path, and exits after the agent loop finishes. The normal `aimax run` command remains available as the cold-path fallback.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5773651]
|
|
12
|
+
- @gencode/cli@0.12.0
|
|
13
|
+
- @gencode/agents@0.14.0
|
|
14
|
+
|
|
15
|
+
## 0.1.0
|
|
16
|
+
|
|
17
|
+
Initial one-shot container prestart server package.
|
package/README.md
ADDED
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{t as e}from"./server-DdorBHmR.js";function t(e){let t={};for(let a=0;a<e.length;a+=1){let o=e[a];if(o===`--host`){t.host=e[++a];continue}if(o===`--port`){t.port=n(e[++a],`--port`);continue}if(o===`--request-timeout-ms`){t.requestTimeoutMs=r(e[++a],`--request-timeout-ms`);continue}throw(o===`--help`||o===`-h`)&&(i(),process.exit(0)),Error(`Unknown option: ${o}`)}return t}function n(e,t){let n=r(e,t);if(n>65535)throw Error(`Invalid ${t}: ${e}. Must be between 0 and 65535.`);return n}function r(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 i(){process.stdout.write(`AIMax one-shot prestart server
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
aimax-server [--host 127.0.0.1] [--port 0] [--request-timeout-ms 60000]
|
|
6
|
+
|
|
7
|
+
Environment:
|
|
8
|
+
AIMAX_SERVER_HOST
|
|
9
|
+
AIMAX_SERVER_PORT
|
|
10
|
+
AIMAX_SERVER_REQUEST_TIMEOUT_MS
|
|
11
|
+
`)}async function a(){let i=t(process.argv.slice(2)),a=e({host:i.host??process.env.AIMAX_SERVER_HOST,port:i.port??(process.env.AIMAX_SERVER_PORT?n(process.env.AIMAX_SERVER_PORT,`AIMAX_SERVER_PORT`):void 0),requestTimeoutMs:i.requestTimeoutMs??(process.env.AIMAX_SERVER_REQUEST_TIMEOUT_MS?r(process.env.AIMAX_SERVER_REQUEST_TIMEOUT_MS,`AIMAX_SERVER_REQUEST_TIMEOUT_MS`):void 0),onLog:(e,t)=>{process.stderr.write(`${JSON.stringify({level:`info`,message:e,...t})}\n`)}}),o=()=>{a.stop().finally(()=>{process.exit(0)})};process.once(`SIGTERM`,o),process.once(`SIGINT`,o),await a.start(),process.stdout.write(`${JSON.stringify({type:`aimax_server_ready`,url:a.getUrl(),status:a.getStatus()})}\n`);let s=await a.done;process.exit(s.exitCode)}a().catch(e=>{process.stderr.write(`${JSON.stringify({level:`error`,message:e.message})}\n`),process.exit(1)});export{};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/server.d.ts
|
|
2
|
+
type AimaxServerStatus = "starting" | "warming" | "ready" | "ready_degraded" | "running" | "draining" | "exiting";
|
|
3
|
+
type ServerRunRequest = {
|
|
4
|
+
run: ServerRunOptions;
|
|
5
|
+
};
|
|
6
|
+
type ServerRunOptions = Record<string, unknown>;
|
|
7
|
+
type SystemWarmState = {
|
|
8
|
+
runtimeInitialized: true;
|
|
9
|
+
pluginSystem: unknown;
|
|
10
|
+
loadedAt: string;
|
|
11
|
+
version: number;
|
|
12
|
+
};
|
|
13
|
+
type AimaxServerOptions = {
|
|
14
|
+
host?: string;
|
|
15
|
+
port?: number;
|
|
16
|
+
maxBodyBytes?: number;
|
|
17
|
+
requestTimeoutMs?: number;
|
|
18
|
+
executeRun?: (options: ServerRunOptions) => Promise<void>;
|
|
19
|
+
prepareSystemRuntime?: () => SystemWarmState | Promise<SystemWarmState>;
|
|
20
|
+
onLog?: (message: string, details?: Record<string, unknown>) => void;
|
|
21
|
+
};
|
|
22
|
+
type AimaxServerHandle = {
|
|
23
|
+
start: () => Promise<void>;
|
|
24
|
+
stop: () => Promise<void>;
|
|
25
|
+
done: Promise<{
|
|
26
|
+
exitCode: number;
|
|
27
|
+
}>;
|
|
28
|
+
getStatus: () => AimaxServerStatus;
|
|
29
|
+
getUrl: () => string;
|
|
30
|
+
};
|
|
31
|
+
declare function createAimaxServer(options?: AimaxServerOptions): AimaxServerHandle;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { type AimaxServerHandle, type AimaxServerOptions, type AimaxServerStatus, type ServerRunRequest, createAimaxServer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./server-DdorBHmR.js";export{e as createAimaxServer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:http";function t(t={}){let a=t.host??`127.0.0.1`,c=t.port??0,l=t.maxBodyBytes??1048576,u=t.executeRun??r,d=t.prepareSystemRuntime??i,f=t.onLog??(()=>void 0),p=`starting`,m,h=null,g=!1,_=()=>void 0,v=new Promise(e=>{_=e});function y(e){g||(g=!0,_(e))}function b(e){p=e,f(`server status changed`,{status:e})}async function x(){let e=h;h=null,!(!e||!e.listening)&&await new Promise((t,n)=>{e.close(e=>{e?n(e):t()})})}async function S(e,t){if(p===`starting`||p===`warming`){s(t,503,{status:p,error:`server is not ready`});return}if(p!==`ready`&&p!==`ready_degraded`){s(t,409,{status:p,error:`server already accepted a run`});return}let r;try{r=n(await o(e,l))}catch(e){s(t,400,{status:p,error:e.message});return}b(`running`),x().catch(e=>{f(`failed to close listener after accepting run`,{error:String(e)})}),s(t,202,{status:p,accepted:!0}),C(r)}async function C(e){let t=0;try{await u(e.run),typeof process.exitCode==`number`&&process.exitCode!==0&&(t=process.exitCode),b(`draining`)}catch(e){t=1,f(`run failed`,{error:String(e)}),b(`draining`)}finally{await x().catch(e=>{f(`failed to stop server during drain`,{error:String(e)})}),b(`exiting`),y({exitCode:t})}}async function w(e,t){let n=new URL(e.url??`/`,`http://${a}`);if(e.method===`GET`&&n.pathname===`/healthz`){s(t,200,{status:p});return}if(e.method===`GET`&&n.pathname===`/readyz`){let e=p===`ready`||p===`ready_degraded`;s(t,e?200:503,{status:p,ready:e,degraded:p===`ready_degraded`,warmupError:m});return}if(e.method===`POST`&&n.pathname===`/run`){await S(e,t);return}s(t,404,{status:p,error:`not found`})}async function T(){if(!h){b(`warming`),h=e.createServer((e,t)=>{w(e,t).catch(e=>{s(t,500,{status:p,error:String(e)})})}),await new Promise((e,t)=>{h.once(`error`,t),h.listen(c,a,()=>{h.off(`error`,t),e()})});try{await d(),p===`warming`&&b(`ready`)}catch(e){m=String(e),f(`system warmup failed; continuing with cold run path`,{error:m}),p===`warming`&&b(`ready_degraded`)}t.requestTimeoutMs&&t.requestTimeoutMs>0&&setTimeout(()=>{(p===`ready`||p===`ready_degraded`)&&x().finally(()=>{b(`exiting`),y({exitCode:1})})},t.requestTimeoutMs).unref()}}function E(){if(!h?.listening)return``;let e=h.address();return`http://${e.address}:${e.port}`}return{start:T,stop:x,done:v,getStatus:()=>p,getUrl:E}}function n(e){if(!e||typeof e!=`object`)throw Error(`request body must be an object`);let t=e.run;if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`request body must include run options`);return{run:t}}async function r(e){await(await a(`@gencode/cli`)).executeRun(e)}async function i(){return(await a(`@gencode/agents/system-runtime`)).prepareSystemRuntime()}const a=Function(`specifier`,`return import(specifier)`);async function o(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 s(e,t,n){e.headersSent||(e.writeHead(t,{"content-type":`application/json; charset=utf-8`}),e.end(`${JSON.stringify(n)}\n`))}export{t};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gencode/server",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"aimax-server": "./dist/bin.js"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"CHANGELOG.md"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@gencode/agents": "0.14.0",
|
|
23
|
+
"@gencode/cli": "0.12.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.0.0",
|
|
27
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
28
|
+
"tsdown": "0.21.0-beta.2",
|
|
29
|
+
"typescript": "^5.9.3",
|
|
30
|
+
"vitest": "^4.0.18"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsdown",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
36
|
+
"typecheck": "tsc --noEmit"
|
|
37
|
+
}
|
|
38
|
+
}
|