@agentage/extension 0.1.1 → 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/README.md +6 -5
- package/dist/agcid/agcid.d.ts +1 -0
- package/dist/agcid/agcid.js +2 -2
- package/dist/agcid/current.d.ts +7 -0
- package/dist/agcid/current.js +4 -0
- package/dist/agcid/scope.d.ts +1 -1
- package/dist/agcid/scope.js +3 -4
- package/dist/command/args.d.ts +14 -0
- package/dist/command/args.js +60 -0
- package/dist/command/check-cli.d.ts +1 -0
- package/dist/command/check-cli.js +24 -0
- package/dist/command/command.types.d.ts +14 -0
- package/dist/command/command.types.js +2 -0
- package/dist/command/out.d.ts +19 -0
- package/dist/command/out.js +32 -0
- package/dist/command/run-command.d.ts +15 -0
- package/dist/command/run-command.js +53 -0
- package/dist/context/context.d.ts +8 -14
- package/dist/context/context.js +19 -21
- package/dist/context/settings.d.ts +5 -0
- package/dist/context/settings.js +32 -0
- package/dist/context/test-context.d.ts +44 -0
- package/dist/context/test-context.js +72 -0
- package/dist/discovery/discovery.d.ts +12 -1
- package/dist/discovery/discovery.js +21 -27
- package/dist/discovery/discovery.schema.d.ts +2 -26
- package/dist/discovery/discovery.schema.js +6 -4
- package/dist/discovery/openapi.d.ts +3 -0
- package/dist/discovery/openapi.js +19 -0
- package/dist/envelope/envelope.js +1 -0
- package/dist/envelope/envelope.schema.d.ts +0 -4
- package/dist/envelope/envelope.schema.js +3 -2
- package/dist/health/health.d.ts +5 -2
- package/dist/health/health.js +23 -8
- package/dist/health/health.schema.d.ts +2 -9
- package/dist/health/health.schema.js +3 -3
- package/dist/index.d.ts +19 -12
- package/dist/index.js +19 -12
- package/dist/log/log.d.ts +1 -0
- package/dist/log/log.js +7 -8
- package/dist/manifest/manifest.schema.d.ts +5 -75
- package/dist/manifest/manifest.schema.js +8 -4
- package/dist/manifest/primitives.schema.d.ts +1 -0
- package/dist/manifest/primitives.schema.js +3 -1
- package/dist/manifest/read-manifest.d.ts +1 -0
- package/dist/manifest/read-manifest.js +26 -3
- package/dist/mcp/mcp-app.d.ts +8 -0
- package/dist/mcp/mcp-app.js +74 -0
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +36 -0
- package/dist/mcp/snapshot.d.ts +11 -0
- package/dist/mcp/snapshot.js +69 -0
- package/dist/mcp/tools.d.ts +24 -0
- package/dist/mcp/tools.js +17 -0
- package/dist/pages/pages-app.d.ts +8 -0
- package/dist/pages/pages-app.js +29 -0
- package/dist/pages/pages.d.ts +4 -0
- package/dist/pages/pages.js +16 -0
- package/dist/runtime/build-info.d.ts +1 -0
- package/dist/runtime/build-info.js +4 -4
- package/dist/runtime/main.js +5 -2
- package/dist/runtime/part-runners.d.ts +20 -0
- package/dist/runtime/part-runners.js +68 -0
- package/dist/runtime/run-part.d.ts +4 -2
- package/dist/runtime/run-part.js +47 -34
- package/dist/server/app.d.ts +16 -2
- package/dist/server/app.js +28 -12
- package/dist/server/errors.d.ts +0 -2
- package/dist/server/errors.js +1 -1
- package/dist/server/serve.d.ts +0 -1
- package/dist/server/serve.js +2 -1
- package/dist/store/migrate.d.ts +2 -0
- package/dist/store/migrate.js +18 -0
- package/dist/store/migrations.d.ts +10 -0
- package/dist/store/migrations.js +55 -0
- package/dist/store/store.d.ts +10 -0
- package/dist/store/store.js +25 -0
- package/dist/store/store.types.d.ts +7 -0
- package/dist/store/store.types.js +1 -0
- package/dist/store/test-store.d.ts +5 -0
- package/dist/store/test-store.js +39 -0
- package/dist/testing/test-server.d.ts +6 -0
- package/dist/testing/test-server.js +31 -9
- package/dist/tool/build-info.js +2 -3
- package/dist/tool/build.d.ts +5 -2
- package/dist/tool/build.js +16 -24
- package/dist/tool/docker.d.ts +0 -1
- package/dist/tool/docker.js +2 -1
- package/dist/tool/exec.d.ts +4 -1
- package/dist/tool/exec.js +13 -5
- package/dist/tool/index.d.ts +9 -10
- package/dist/tool/index.js +9 -10
- package/dist/tool/kit-version.d.ts +1 -0
- package/dist/tool/kit-version.js +3 -0
- package/dist/tool/main.d.ts +6 -1
- package/dist/tool/main.js +58 -30
- package/dist/tool/recipe.d.ts +0 -1
- package/dist/tool/recipe.js +7 -3
- package/dist/tool/record-extras.d.ts +4 -0
- package/dist/tool/record-extras.js +60 -0
- package/dist/tool/stage.d.ts +3 -0
- package/dist/tool/stage.js +45 -12
- package/dist/tool/up/compose-run.d.ts +14 -0
- package/dist/tool/up/compose-run.js +24 -0
- package/dist/tool/up/compose.d.ts +18 -0
- package/dist/tool/up/compose.js +77 -0
- package/dist/tool/up/dev-issuer-app.d.ts +22 -0
- package/dist/tool/up/dev-issuer-app.js +80 -0
- package/dist/tool/up/dev-issuer.d.ts +2 -0
- package/dist/tool/up/dev-issuer.js +5 -0
- package/dist/tool/up/down.d.ts +12 -0
- package/dist/tool/up/down.js +38 -0
- package/dist/tool/up/gateway.d.ts +27 -0
- package/dist/tool/up/gateway.js +66 -0
- package/dist/tool/up/lines.d.ts +2 -0
- package/dist/tool/up/lines.js +3 -0
- package/dist/tool/up/local-record.d.ts +44 -0
- package/dist/tool/up/local-record.js +28 -0
- package/dist/tool/up/token.d.ts +6 -0
- package/dist/tool/up/token.js +18 -0
- package/dist/tool/up/up.d.ts +19 -0
- package/dist/tool/up/up.js +81 -0
- package/dist/tool/up/wait.d.ts +8 -0
- package/dist/tool/up/wait.js +24 -0
- package/dist/ui/ui-app.d.ts +6 -0
- package/dist/ui/ui-app.js +26 -0
- package/dist/worker/cron.d.ts +11 -0
- package/dist/worker/cron.js +73 -0
- package/dist/worker/job-options.d.ts +9 -0
- package/dist/worker/job-options.js +17 -0
- package/dist/worker/run-log.d.ts +9 -0
- package/dist/worker/run-log.js +38 -0
- package/dist/worker/runs.d.ts +20 -0
- package/dist/worker/runs.js +59 -0
- package/dist/worker/scheduler.d.ts +20 -0
- package/dist/worker/scheduler.js +97 -0
- package/dist/worker/worker.types.d.ts +5 -0
- package/dist/worker/worker.types.js +2 -0
- package/package.json +11 -2
- package/schemas/extension-discovery.schema.json +5 -0
- package/schemas/extension-package.schema.json +3 -0
- package/schemas/extension-record.schema.json +5 -0
- package/schemas/health.schema.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {} from '../health/health.js';
|
|
2
|
+
import {} from '../log/log.js';
|
|
3
|
+
import { nextRun, parseCron } from './cron.js';
|
|
4
|
+
import { JobNameSchema, JobOptionsSchema, toMs } from './job-options.js';
|
|
5
|
+
import { withRunBuffer } from './run-log.js';
|
|
6
|
+
import {} from './runs.js';
|
|
7
|
+
// A timer overdue by this much means the process stalled: the job is late.
|
|
8
|
+
export const LATE_MS = 60_000;
|
|
9
|
+
const MAX_DELAY = 2 ** 31 - 1;
|
|
10
|
+
const arm = (s, entry) => {
|
|
11
|
+
const delay = Math.min(MAX_DELAY, Math.max(0, entry.nextAt.getTime() - s.now().getTime()));
|
|
12
|
+
entry.timer = setTimeout(() => void fire(s, entry), delay);
|
|
13
|
+
};
|
|
14
|
+
const fire = async (s, entry) => {
|
|
15
|
+
if (!s.started)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (entry.nextAt.getTime() > s.now().getTime())
|
|
18
|
+
return arm(s, entry);
|
|
19
|
+
entry.nextAt = nextRun(entry.cron, s.now());
|
|
20
|
+
arm(s, entry);
|
|
21
|
+
if (!entry.running)
|
|
22
|
+
return execute(s, entry);
|
|
23
|
+
s.deps.log.warn('job skipped: its previous run is still running', { job: entry.name });
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
26
|
+
const newEntry = (name, cron, job, options, at) => {
|
|
27
|
+
JobNameSchema.parse(name);
|
|
28
|
+
const parsed = parseCron(cron);
|
|
29
|
+
const timeout = JobOptionsSchema.parse(options)?.timeout;
|
|
30
|
+
const entry = { name, cron: parsed, job, nextAt: nextRun(parsed, at), running: false };
|
|
31
|
+
if (timeout !== undefined)
|
|
32
|
+
entry.timeoutMs = toMs(timeout);
|
|
33
|
+
return entry;
|
|
34
|
+
};
|
|
35
|
+
const runJob = async (entry, log, buffer) => {
|
|
36
|
+
try {
|
|
37
|
+
await withRunBuffer(buffer, async () => entry.job());
|
|
38
|
+
return 'ok';
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
await withRunBuffer(buffer, async () => log.error(err, { job: entry.name }));
|
|
42
|
+
return 'failed';
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
// Never twice at once; every run saved with its log, a failed save is logged and the job goes on.
|
|
46
|
+
const execute = async (s, entry) => {
|
|
47
|
+
entry.running = true;
|
|
48
|
+
const buffer = { text: '', truncated: false };
|
|
49
|
+
const startedAt = s.now();
|
|
50
|
+
const status = await runJob(entry, s.deps.log, buffer);
|
|
51
|
+
entry.running = false;
|
|
52
|
+
entry.last = status;
|
|
53
|
+
const run = { job: entry.name, startedAt, endedAt: s.now(), status, log: buffer.text };
|
|
54
|
+
if (entry.timeoutMs !== undefined)
|
|
55
|
+
run.timeoutMs = entry.timeoutMs;
|
|
56
|
+
await s.deps.runs.save(run).catch((err) => s.deps.log.error(err, { job: entry.name }));
|
|
57
|
+
return run;
|
|
58
|
+
};
|
|
59
|
+
// ok: the last run ok and the timer on time; a failed or late job is degraded, never a restart.
|
|
60
|
+
const check = (s, entry) => async () => {
|
|
61
|
+
const late = s.now().getTime() - entry.nextAt.getTime() > LATE_MS;
|
|
62
|
+
return entry.last === 'failed' || late ? 'degraded' : 'ok';
|
|
63
|
+
};
|
|
64
|
+
const scheduleOn = (s) => (name, cron, job, options) => {
|
|
65
|
+
const entry = newEntry(name, cron, job, options, s.now());
|
|
66
|
+
if (s.entries.has(entry.name))
|
|
67
|
+
throw new Error(`job ${name} is scheduled twice`);
|
|
68
|
+
s.entries.set(entry.name, entry);
|
|
69
|
+
if (s.started)
|
|
70
|
+
arm(s, entry);
|
|
71
|
+
};
|
|
72
|
+
const setStarted = (s, started) => {
|
|
73
|
+
s.started = started;
|
|
74
|
+
for (const entry of s.entries.values()) {
|
|
75
|
+
clearTimeout(entry.timer);
|
|
76
|
+
if (started)
|
|
77
|
+
arm(s, entry);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export const createScheduler = (deps) => {
|
|
81
|
+
const s = {
|
|
82
|
+
deps,
|
|
83
|
+
now: deps.now ?? (() => new Date()),
|
|
84
|
+
entries: new Map(),
|
|
85
|
+
started: false,
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
schedule: scheduleOn(s),
|
|
89
|
+
start: () => setStarted(s, true),
|
|
90
|
+
stop: () => setStarted(s, false),
|
|
91
|
+
run: async (name) => {
|
|
92
|
+
const entry = s.entries.get(name);
|
|
93
|
+
return entry && !entry.running ? execute(s, entry) : undefined;
|
|
94
|
+
},
|
|
95
|
+
checks: () => Object.fromEntries([...s.entries.values()].map((e) => [`job:${e.name}`, check(s, e)])),
|
|
96
|
+
};
|
|
97
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/extension",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The agentage extension kit: create(ctx) per part, the
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The agentage extension kit: create(ctx) per part (pages, ui, api, mcp, worker, cli), the store, /health, discovery, the envelope, and the build tool with up and token",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"types": "./dist/tool/index.d.ts",
|
|
29
29
|
"default": "./dist/tool/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./migrate": {
|
|
32
|
+
"default": "./dist/store/migrate.js"
|
|
33
|
+
},
|
|
31
34
|
"./schemas/*": "./schemas/*",
|
|
32
35
|
"./package.json": "./package.json"
|
|
33
36
|
},
|
|
@@ -44,14 +47,20 @@
|
|
|
44
47
|
"prepublishOnly": "npm run verify"
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
50
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
47
51
|
"cors": "^2.8.5",
|
|
48
52
|
"helmet": "^8.1.0",
|
|
53
|
+
"pg": "^8.23.1",
|
|
49
54
|
"zod": "^4.2.0"
|
|
50
55
|
},
|
|
51
56
|
"peerDependencies": {
|
|
57
|
+
"@electric-sql/pglite": "^0.5.0",
|
|
52
58
|
"express": "^5.1.0"
|
|
53
59
|
},
|
|
54
60
|
"peerDependenciesMeta": {
|
|
61
|
+
"@electric-sql/pglite": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
55
64
|
"express": {
|
|
56
65
|
"optional": true
|
|
57
66
|
}
|