@agentage/extension 0.1.2 → 0.2.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.
Files changed (137) hide show
  1. package/README.md +6 -5
  2. package/dist/agcid/current.d.ts +7 -0
  3. package/dist/agcid/current.js +4 -0
  4. package/dist/agcid/scope.d.ts +0 -1
  5. package/dist/agcid/scope.js +2 -4
  6. package/dist/auth/route-access.d.ts +2 -0
  7. package/dist/auth/route-access.js +21 -0
  8. package/dist/auth/token-check.d.ts +10 -0
  9. package/dist/auth/token-check.js +18 -0
  10. package/dist/command/args.d.ts +14 -0
  11. package/dist/command/args.js +60 -0
  12. package/dist/command/check-cli.d.ts +1 -0
  13. package/dist/command/check-cli.js +19 -0
  14. package/dist/command/command.types.d.ts +14 -0
  15. package/dist/command/command.types.js +2 -0
  16. package/dist/command/out.d.ts +19 -0
  17. package/dist/command/out.js +32 -0
  18. package/dist/command/run-command.d.ts +16 -0
  19. package/dist/command/run-command.js +43 -0
  20. package/dist/context/context.d.ts +8 -14
  21. package/dist/context/context.js +20 -26
  22. package/dist/context/settings.d.ts +5 -0
  23. package/dist/context/settings.js +32 -0
  24. package/dist/context/test-context.d.ts +44 -0
  25. package/dist/context/test-context.js +75 -0
  26. package/dist/discovery/discovery.d.ts +12 -1
  27. package/dist/discovery/discovery.js +15 -6
  28. package/dist/discovery/discovery.schema.d.ts +7 -0
  29. package/dist/discovery/discovery.schema.js +4 -2
  30. package/dist/discovery/openapi.d.ts +3 -0
  31. package/dist/discovery/openapi.js +19 -0
  32. package/dist/health/health.schema.js +1 -1
  33. package/dist/index.d.ts +16 -3
  34. package/dist/index.js +16 -3
  35. package/dist/log/log.js +1 -1
  36. package/dist/manifest/entry.d.ts +5 -0
  37. package/dist/manifest/entry.js +29 -0
  38. package/dist/manifest/manifest.schema.d.ts +18 -0
  39. package/dist/manifest/manifest.schema.js +1 -0
  40. package/dist/manifest/parts.d.ts +1 -0
  41. package/dist/manifest/parts.js +1 -0
  42. package/dist/mcp/mcp-app.d.ts +8 -0
  43. package/dist/mcp/mcp-app.js +94 -0
  44. package/dist/mcp/server.d.ts +8 -0
  45. package/dist/mcp/server.js +38 -0
  46. package/dist/mcp/snapshot.d.ts +11 -0
  47. package/dist/mcp/snapshot.js +69 -0
  48. package/dist/mcp/tools.d.ts +26 -0
  49. package/dist/mcp/tools.js +21 -0
  50. package/dist/pages/pages-app.d.ts +8 -0
  51. package/dist/pages/pages-app.js +29 -0
  52. package/dist/pages/pages.d.ts +4 -0
  53. package/dist/pages/pages.js +16 -0
  54. package/dist/runtime/part-runners.d.ts +20 -0
  55. package/dist/runtime/part-runners.js +63 -0
  56. package/dist/runtime/run-part.d.ts +7 -3
  57. package/dist/runtime/run-part.js +67 -29
  58. package/dist/server/app.d.ts +20 -2
  59. package/dist/server/app.js +39 -11
  60. package/dist/store/migrate.d.ts +2 -0
  61. package/dist/store/migrate.js +22 -0
  62. package/dist/store/migrations.d.ts +12 -0
  63. package/dist/store/migrations.js +81 -0
  64. package/dist/store/store.d.ts +16 -0
  65. package/dist/store/store.js +55 -0
  66. package/dist/store/store.types.d.ts +7 -0
  67. package/dist/store/store.types.js +1 -0
  68. package/dist/store/test-store.d.ts +5 -0
  69. package/dist/store/test-store.js +39 -0
  70. package/dist/testing/test-server.d.ts +6 -0
  71. package/dist/testing/test-server.js +31 -9
  72. package/dist/tool/build.d.ts +4 -0
  73. package/dist/tool/build.js +21 -26
  74. package/dist/tool/check.d.ts +16 -0
  75. package/dist/tool/check.js +30 -0
  76. package/dist/tool/docker.js +3 -2
  77. package/dist/tool/exec.d.ts +5 -0
  78. package/dist/tool/exec.js +48 -9
  79. package/dist/tool/index.d.ts +8 -0
  80. package/dist/tool/index.js +8 -0
  81. package/dist/tool/kit-version.d.ts +1 -0
  82. package/dist/tool/kit-version.js +3 -0
  83. package/dist/tool/main.d.ts +6 -0
  84. package/dist/tool/main.js +60 -35
  85. package/dist/tool/record-extras.d.ts +4 -0
  86. package/dist/tool/record-extras.js +56 -0
  87. package/dist/tool/stage.d.ts +4 -0
  88. package/dist/tool/stage.js +39 -21
  89. package/dist/tool/timeouts.d.ts +10 -0
  90. package/dist/tool/timeouts.js +19 -0
  91. package/dist/tool/up/compose-run.d.ts +15 -0
  92. package/dist/tool/up/compose-run.js +25 -0
  93. package/dist/tool/up/compose.d.ts +19 -0
  94. package/dist/tool/up/compose.js +80 -0
  95. package/dist/tool/up/dev-issuer-app.d.ts +22 -0
  96. package/dist/tool/up/dev-issuer-app.js +80 -0
  97. package/dist/tool/up/dev-issuer.d.ts +2 -0
  98. package/dist/tool/up/dev-issuer.js +6 -0
  99. package/dist/tool/up/down.d.ts +13 -0
  100. package/dist/tool/up/down.js +47 -0
  101. package/dist/tool/up/gateway.d.ts +36 -0
  102. package/dist/tool/up/gateway.js +60 -0
  103. package/dist/tool/up/lines.d.ts +2 -0
  104. package/dist/tool/up/lines.js +3 -0
  105. package/dist/tool/up/local-record.d.ts +44 -0
  106. package/dist/tool/up/local-record.js +28 -0
  107. package/dist/tool/up/ports.d.ts +2 -0
  108. package/dist/tool/up/ports.js +22 -0
  109. package/dist/tool/up/project.d.ts +4 -0
  110. package/dist/tool/up/project.js +20 -0
  111. package/dist/tool/up/store-line.d.ts +11 -0
  112. package/dist/tool/up/store-line.js +36 -0
  113. package/dist/tool/up/token.d.ts +6 -0
  114. package/dist/tool/up/token.js +25 -0
  115. package/dist/tool/up/up.d.ts +16 -0
  116. package/dist/tool/up/up.js +84 -0
  117. package/dist/tool/up/wait.d.ts +8 -0
  118. package/dist/tool/up/wait.js +26 -0
  119. package/dist/ui/ui-app.d.ts +8 -0
  120. package/dist/ui/ui-app.js +39 -0
  121. package/dist/worker/cron.d.ts +11 -0
  122. package/dist/worker/cron.js +73 -0
  123. package/dist/worker/job-options.d.ts +9 -0
  124. package/dist/worker/job-options.js +17 -0
  125. package/dist/worker/run-log.d.ts +9 -0
  126. package/dist/worker/run-log.js +38 -0
  127. package/dist/worker/runs.d.ts +20 -0
  128. package/dist/worker/runs.js +59 -0
  129. package/dist/worker/scheduler.d.ts +20 -0
  130. package/dist/worker/scheduler.js +106 -0
  131. package/dist/worker/worker.types.d.ts +5 -0
  132. package/dist/worker/worker.types.js +2 -0
  133. package/package.json +11 -2
  134. package/schemas/extension-discovery.schema.json +5 -0
  135. package/schemas/extension-package.schema.json +3 -0
  136. package/schemas/extension-record.schema.json +5 -0
  137. package/schemas/health.schema.json +1 -1
@@ -0,0 +1,106 @@
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
+ entry.overran = true;
24
+ s.deps.log.warn('job skipped: its previous run is still running', { job: entry.name });
25
+ return undefined;
26
+ };
27
+ const newEntry = (name, cron, job, options, at) => {
28
+ JobNameSchema.parse(name);
29
+ const parsed = parseCron(cron);
30
+ const timeout = JobOptionsSchema.parse(options)?.timeout;
31
+ const nextAt = nextRun(parsed, at);
32
+ const entry = { name, cron: parsed, job, nextAt, running: false, overran: false };
33
+ if (timeout !== undefined)
34
+ entry.timeoutMs = toMs(timeout);
35
+ return entry;
36
+ };
37
+ const runJob = async (entry, log, buffer) => {
38
+ try {
39
+ await withRunBuffer(buffer, async () => entry.job());
40
+ return 'ok';
41
+ }
42
+ catch (err) {
43
+ await withRunBuffer(buffer, async () => log.error(err, { job: entry.name }));
44
+ return 'failed';
45
+ }
46
+ };
47
+ // Never twice at once; every run saved with its log, a failed save is logged and the job goes on.
48
+ const execute = async (s, entry) => {
49
+ const startedAt = s.now();
50
+ Object.assign(entry, { running: true, runningSince: startedAt, overran: false });
51
+ const buffer = { text: '', truncated: false };
52
+ const status = await runJob(entry, s.deps.log, buffer);
53
+ entry.running = false;
54
+ entry.last = status;
55
+ const run = { job: entry.name, startedAt, endedAt: s.now(), status, log: buffer.text };
56
+ if (entry.timeoutMs !== undefined)
57
+ run.timeoutMs = entry.timeoutMs;
58
+ await s.deps.runs.save(run).catch((err) => s.deps.log.error(err, { job: entry.name }));
59
+ return run;
60
+ };
61
+ // A run still going past its declared timeout, or one that made the job skip a tick.
62
+ const overrunning = (s, entry) => {
63
+ if (!entry.running)
64
+ return false;
65
+ const ranMs = s.now().getTime() - (entry.runningSince?.getTime() ?? 0);
66
+ return entry.overran || (entry.timeoutMs !== undefined && ranMs > entry.timeoutMs);
67
+ };
68
+ // ok: the last run ok, the timer on time, no run overrunning; else degraded, never a restart.
69
+ const check = (s, entry) => async () => {
70
+ const late = s.now().getTime() - entry.nextAt.getTime() > LATE_MS;
71
+ return entry.last === 'failed' || late || overrunning(s, entry) ? 'degraded' : 'ok';
72
+ };
73
+ const scheduleOn = (s) => (name, cron, job, options) => {
74
+ const entry = newEntry(name, cron, job, options, s.now());
75
+ if (s.entries.has(entry.name))
76
+ throw new Error(`job ${name} is scheduled twice`);
77
+ s.entries.set(entry.name, entry);
78
+ if (s.started)
79
+ arm(s, entry);
80
+ };
81
+ const setStarted = (s, started) => {
82
+ s.started = started;
83
+ for (const entry of s.entries.values()) {
84
+ clearTimeout(entry.timer);
85
+ if (started)
86
+ arm(s, entry);
87
+ }
88
+ };
89
+ export const createScheduler = (deps) => {
90
+ const s = {
91
+ deps,
92
+ now: deps.now ?? (() => new Date()),
93
+ entries: new Map(),
94
+ started: false,
95
+ };
96
+ return {
97
+ schedule: scheduleOn(s),
98
+ start: () => setStarted(s, true),
99
+ stop: () => setStarted(s, false),
100
+ run: async (name) => {
101
+ const entry = s.entries.get(name);
102
+ return entry && !entry.running ? execute(s, entry) : undefined;
103
+ },
104
+ checks: () => Object.fromEntries([...s.entries.values()].map((e) => [`job:${e.name}`, check(s, e)])),
105
+ };
106
+ };
@@ -0,0 +1,5 @@
1
+ import { type PartContext } from '../context/context.js';
2
+ import { type Schedule } from './scheduler.js';
3
+ export interface WorkerContext extends PartContext {
4
+ readonly schedule: Schedule;
5
+ }
@@ -0,0 +1,2 @@
1
+ import {} from '../context/context.js';
2
+ import {} from './scheduler.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentage/extension",
3
- "version": "0.1.2",
4
- "description": "The agentage extension kit: create(ctx) per part, the server, /health, discovery, the envelope, and the build tool",
3
+ "version": "0.2.1",
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
  }
@@ -105,6 +105,11 @@
105
105
  "git",
106
106
  "signoz"
107
107
  ]
108
+ },
109
+ "migrations": {
110
+ "type": "integer",
111
+ "minimum": 0,
112
+ "maximum": 9007199254740991
108
113
  }
109
114
  },
110
115
  "required": [
@@ -213,6 +213,9 @@
213
213
  "boolean"
214
214
  ]
215
215
  },
216
+ "optional": {
217
+ "type": "boolean"
218
+ },
216
219
  "required": {
217
220
  "type": "boolean"
218
221
  },
@@ -105,6 +105,11 @@
105
105
  "git",
106
106
  "signoz"
107
107
  ]
108
+ },
109
+ "migrations": {
110
+ "type": "integer",
111
+ "minimum": 0,
112
+ "maximum": 9007199254740991
108
113
  }
109
114
  },
110
115
  "required": [
@@ -65,7 +65,7 @@
65
65
  "type": "object",
66
66
  "propertyNames": {
67
67
  "type": "string",
68
- "pattern": "^[a-z][a-z0-9-]*$"
68
+ "pattern": "^[a-z][a-z0-9-]*(:[a-z][a-z0-9-]*)?$"
69
69
  },
70
70
  "additionalProperties": {
71
71
  "type": "string",