@agentage/extension 0.6.1 → 0.8.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/dist/agcid/current.d.ts +2 -0
- package/dist/agcid/current.js +1 -0
- package/dist/agcid/fetch.d.ts +1 -0
- package/dist/agcid/fetch.js +11 -0
- package/dist/agcid/scope.js +4 -2
- package/dist/api/openapi-doc.js +55 -19
- package/dist/api/page.d.ts +14 -0
- package/dist/api/page.js +33 -0
- package/dist/api/routes.d.ts +18 -8
- package/dist/api/routes.js +4 -2
- package/dist/api/well-known.d.ts +13 -0
- package/dist/api/well-known.js +13 -0
- package/dist/auth/revoked.js +2 -1
- package/dist/auth/token-check.d.ts +1 -1
- package/dist/auth/token-check.js +8 -4
- package/dist/auth/verify-token.d.ts +2 -1
- package/dist/auth/verify-token.js +3 -2
- package/dist/command/check-cli.js +3 -2
- package/dist/command/cli-context.d.ts +15 -0
- package/dist/command/cli-context.js +34 -0
- package/dist/command/command.types.d.ts +11 -0
- package/dist/command/command.types.js +3 -0
- package/dist/command/run-command.d.ts +4 -1
- package/dist/command/run-command.js +12 -8
- package/dist/context/context.js +1 -1
- package/dist/context/recording-log.d.ts +7 -0
- package/dist/context/recording-log.js +10 -0
- package/dist/context/test-command-context.d.ts +34 -0
- package/dist/context/test-command-context.js +51 -0
- package/dist/context/test-context.d.ts +6 -23
- package/dist/context/test-context.js +7 -35
- package/dist/envelope/envelope.d.ts +12 -0
- package/dist/envelope/envelope.js +8 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -1
- package/dist/log/log.d.ts +3 -0
- package/dist/log/log.js +24 -7
- package/dist/mcp/snapshot.js +2 -1
- package/dist/mcp/tools.d.ts +1 -1
- package/dist/runtime/part-runners.js +2 -2
- package/dist/runtime/run-part.js +1 -1
- package/dist/server/api-routes.d.ts +2 -0
- package/dist/server/api-routes.js +14 -7
- package/dist/server/app.d.ts +2 -0
- package/dist/server/app.js +15 -0
- package/dist/server/request-line.d.ts +4 -0
- package/dist/server/request-line.js +25 -0
- package/dist/store/kit-migrations.d.ts +7 -0
- package/dist/store/kit-migrations.js +18 -0
- package/dist/store/migrate.js +1 -1
- package/dist/store/migrations.js +14 -6
- package/dist/testing/test-caller.d.ts +2 -0
- package/dist/testing/test-caller.js +13 -0
- package/dist/testing/test-server.d.ts +2 -0
- package/dist/testing/test-server.js +15 -4
- package/dist/tool/record-extras.js +2 -1
- package/dist/worker/runs.d.ts +1 -1
- package/dist/worker/runs.js +7 -12
- package/dist/worker/scheduler.js +8 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {} from 'node:net';
|
|
2
2
|
import {} from 'express';
|
|
3
|
+
import { generatedOpenapi } from '../api/openapi-doc.js';
|
|
3
4
|
import {} from '../api/routes.js';
|
|
5
|
+
import { callerOf } from '../auth/token-check.js';
|
|
4
6
|
import {} from '../context/context.js';
|
|
5
7
|
import { createTestContext } from '../context/test-context.js';
|
|
6
8
|
import {} from '../manifest/manifest.schema.js';
|
|
@@ -11,11 +13,13 @@ import { mountApi } from '../server/api-routes.js';
|
|
|
11
13
|
import { createApiApp } from '../server/app.js';
|
|
12
14
|
import {} from '../server/part.types.js';
|
|
13
15
|
import { listen } from '../server/serve.js';
|
|
16
|
+
import { KIT_VERSION } from '../tool/kit-version.js';
|
|
17
|
+
import { callerCheck } from './test-caller.js';
|
|
14
18
|
const TEST_BUILD = { commit: '0'.repeat(40), buildTime: '2026-01-01T00:00:00Z' };
|
|
15
19
|
const testPackage = (ctx, parts) => ({
|
|
16
20
|
name: `@agentage/extension-${ctx.extension.id}`,
|
|
17
21
|
version: ctx.extension.version,
|
|
18
|
-
engines: { agentage:
|
|
22
|
+
engines: { agentage: KIT_VERSION },
|
|
19
23
|
agentage: { id: ctx.extension.id, parts },
|
|
20
24
|
});
|
|
21
25
|
const startOn = async (app) => {
|
|
@@ -29,10 +33,17 @@ const startOn = async (app) => {
|
|
|
29
33
|
};
|
|
30
34
|
// Runs an api part's create(ctx) inside the kit's real app on 127.0.0.1, port chosen by the OS.
|
|
31
35
|
export const startTestServer = async (options) => {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
36
|
+
const given = options.ctx ?? createTestContext();
|
|
37
|
+
const checked = options.caller !== undefined;
|
|
38
|
+
const ctx = checked ? { ...given, auth: { caller: callerOf } } : given;
|
|
39
|
+
const mounted = await mountApi(ctx, (api) => options.create({ ...ctx, ...api }));
|
|
34
40
|
const pkg = testPackage(ctx, { api: true });
|
|
35
|
-
|
|
41
|
+
const guard = checked && {
|
|
42
|
+
tokenCheck: callerCheck(ctx.extension.id, options.caller ?? null),
|
|
43
|
+
openapi: generatedOpenapi(pkg, mounted.routes),
|
|
44
|
+
};
|
|
45
|
+
const base = { pkg, build: TEST_BUILD, log: ctx.log, wellKnown: mounted.documents };
|
|
46
|
+
return startOn(createApiApp({ ...base, router: mounted.router, ...guard }));
|
|
36
47
|
};
|
|
37
48
|
// Runs an mcp part's create(ctx) inside the kit's real /mcp app: tools named {id}__{name}.
|
|
38
49
|
export const startTestMcp = async (options) => {
|
|
@@ -38,7 +38,8 @@ export const registeredTools = async (create, pkg) => {
|
|
|
38
38
|
// What an api part's create(ctx) registers with ctx.route, and what it returns.
|
|
39
39
|
export const registeredRoutes = async (create, pkg) => {
|
|
40
40
|
const registry = createRouteRegistry();
|
|
41
|
-
const
|
|
41
|
+
const { route, wellKnown } = registry;
|
|
42
|
+
const returned = await create({ ...recordingContext(pkg, 'api'), route, wellKnown });
|
|
42
43
|
return { routes: registry.routes, returned };
|
|
43
44
|
};
|
|
44
45
|
export const toolsOf = async (dir, pkg) => {
|
package/dist/worker/runs.d.ts
CHANGED
|
@@ -7,13 +7,13 @@ export interface JobRun {
|
|
|
7
7
|
status: RunStatus;
|
|
8
8
|
log: string;
|
|
9
9
|
timeoutMs?: number;
|
|
10
|
+
agcid?: string;
|
|
10
11
|
}
|
|
11
12
|
export interface RunStore {
|
|
12
13
|
save(run: JobRun): Promise<void>;
|
|
13
14
|
last(job: string): Promise<JobRun | undefined>;
|
|
14
15
|
}
|
|
15
16
|
export declare const KEEP_RUNS = 50;
|
|
16
|
-
export declare const RUNS_TABLE = "create table if not exists agentage_job_runs (\n id bigint generated always as identity primary key,\n job text not null,\n started_at timestamptz not null,\n ended_at timestamptz not null,\n status text not null,\n log text not null,\n timeout_ms integer\n)";
|
|
17
17
|
export declare const storeRuns: (store: Store) => RunStore;
|
|
18
18
|
export declare const memoryRuns: () => RunStore & {
|
|
19
19
|
all(job: string): JobRun[];
|
package/dist/worker/runs.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
+
import { JOB_RUNS_SQL } from '../store/kit-migrations.js';
|
|
1
2
|
import {} from '../store/store.types.js';
|
|
2
3
|
export const KEEP_RUNS = 50;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
job text not null,
|
|
6
|
-
started_at timestamptz not null,
|
|
7
|
-
ended_at timestamptz not null,
|
|
8
|
-
status text not null,
|
|
9
|
-
log text not null,
|
|
10
|
-
timeout_ms integer
|
|
11
|
-
)`;
|
|
12
|
-
const INSERT = `insert into agentage_job_runs (job, started_at, ended_at, status, log, timeout_ms)
|
|
13
|
-
values ($1, $2, $3, $4, $5, $6)`;
|
|
4
|
+
const INSERT = `insert into agentage_job_runs
|
|
5
|
+
(job, started_at, ended_at, status, log, timeout_ms, agcid) values ($1, $2, $3, $4, $5, $6, $7)`;
|
|
14
6
|
const PRUNE = `delete from agentage_job_runs where job = $1 and id not in
|
|
15
7
|
(select id from agentage_job_runs where job = $1 order by id desc limit ${KEEP_RUNS})`;
|
|
16
8
|
const fromRow = (row) => ({
|
|
@@ -20,6 +12,7 @@ const fromRow = (row) => ({
|
|
|
20
12
|
status: row.status,
|
|
21
13
|
log: row.log,
|
|
22
14
|
...(row.timeout_ms === null ? {} : { timeoutMs: row.timeout_ms }),
|
|
15
|
+
...(row.agcid ? { agcid: row.agcid } : {}),
|
|
23
16
|
});
|
|
24
17
|
const LAST = 'select * from agentage_job_runs where job = $1 order by id desc limit 1';
|
|
25
18
|
const valuesOf = (run) => [
|
|
@@ -29,11 +22,13 @@ const valuesOf = (run) => [
|
|
|
29
22
|
run.status,
|
|
30
23
|
run.log,
|
|
31
24
|
run.timeoutMs ?? null,
|
|
25
|
+
run.agcid ?? null,
|
|
32
26
|
];
|
|
33
27
|
// Runs live in the extension's own store, in a table the kit owns; the last 50 per job are kept.
|
|
34
28
|
export const storeRuns = (store) => {
|
|
35
29
|
let table;
|
|
36
|
-
|
|
30
|
+
// Also here: a worker-only extension has no migrate job (only the api image runs it).
|
|
31
|
+
const ready = () => (table ??= store.query(JOB_RUNS_SQL));
|
|
37
32
|
return {
|
|
38
33
|
save: async (run) => {
|
|
39
34
|
await ready();
|
package/dist/worker/scheduler.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { uuidv7 } from '../agcid/agcid.js';
|
|
2
|
+
import { requestScope } from '../agcid/current.js';
|
|
1
3
|
import {} from '../health/health.js';
|
|
2
4
|
import {} from '../log/log.js';
|
|
3
5
|
import { nextRun, parseCron } from './cron.js';
|
|
@@ -45,14 +47,19 @@ const runJob = async (entry, log, buffer) => {
|
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
// Never twice at once; every run saved with its log, a failed save is logged and the job goes on.
|
|
48
|
-
const execute =
|
|
50
|
+
const execute = (s, entry) => requestScope.run({ agcid: uuidv7() }, () => executeScoped(s, entry));
|
|
51
|
+
// Inside the run's scope: every log line of the job, its failure and its save share one agcid.
|
|
52
|
+
const executeScoped = async (s, entry) => {
|
|
49
53
|
const startedAt = s.now();
|
|
50
54
|
Object.assign(entry, { running: true, runningSince: startedAt, overran: false });
|
|
51
55
|
const buffer = { text: '', truncated: false };
|
|
52
56
|
const status = await runJob(entry, s.deps.log, buffer);
|
|
53
57
|
entry.running = false;
|
|
54
58
|
entry.last = status;
|
|
59
|
+
const agcid = requestScope.getStore()?.agcid;
|
|
55
60
|
const run = { job: entry.name, startedAt, endedAt: s.now(), status, log: buffer.text };
|
|
61
|
+
if (agcid)
|
|
62
|
+
run.agcid = agcid;
|
|
56
63
|
if (entry.timeoutMs !== undefined)
|
|
57
64
|
run.timeoutMs = entry.timeoutMs;
|
|
58
65
|
await s.deps.runs.save(run).catch((err) => s.deps.log.error(err, { job: entry.name }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/extension",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
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",
|