@agentage/extension 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/agcid/agcid.d.ts +4 -0
- package/dist/agcid/agcid.js +15 -0
- package/dist/agcid/scope.d.ts +4 -0
- package/dist/agcid/scope.js +16 -0
- package/dist/context/context.d.ts +36 -0
- package/dist/context/context.js +25 -0
- package/dist/discovery/discovery.d.ts +47 -0
- package/dist/discovery/discovery.js +52 -0
- package/dist/discovery/discovery.schema.d.ts +106 -0
- package/dist/discovery/discovery.schema.js +56 -0
- package/dist/envelope/codes.d.ts +16 -0
- package/dist/envelope/codes.js +15 -0
- package/dist/envelope/envelope.d.ts +34 -0
- package/dist/envelope/envelope.js +23 -0
- package/dist/envelope/envelope.schema.d.ts +24 -0
- package/dist/envelope/envelope.schema.js +18 -0
- package/dist/envelope/parse.d.ts +17 -0
- package/dist/envelope/parse.js +12 -0
- package/dist/health/health.d.ts +18 -0
- package/dist/health/health.js +43 -0
- package/dist/health/health.schema.d.ts +46 -0
- package/dist/health/health.schema.js +20 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/log/log.d.ts +13 -0
- package/dist/log/log.js +21 -0
- package/dist/manifest/manifest.schema.d.ts +195 -0
- package/dist/manifest/manifest.schema.js +88 -0
- package/dist/manifest/parts.d.ts +11 -0
- package/dist/manifest/parts.js +24 -0
- package/dist/manifest/primitives.schema.d.ts +20 -0
- package/dist/manifest/primitives.schema.js +52 -0
- package/dist/manifest/read-manifest.d.ts +5 -0
- package/dist/manifest/read-manifest.js +19 -0
- package/dist/runtime/build-info.d.ts +4 -0
- package/dist/runtime/build-info.js +16 -0
- package/dist/runtime/main.d.ts +2 -0
- package/dist/runtime/main.js +10 -0
- package/dist/runtime/run-part.d.ts +13 -0
- package/dist/runtime/run-part.js +57 -0
- package/dist/schemas/json-schemas.d.ts +2 -0
- package/dist/schemas/json-schemas.js +29 -0
- package/dist/schemas/write-schemas.d.ts +1 -0
- package/dist/schemas/write-schemas.js +8 -0
- package/dist/server/app.d.ts +18 -0
- package/dist/server/app.js +47 -0
- package/dist/server/errors.d.ts +6 -0
- package/dist/server/errors.js +29 -0
- package/dist/server/part.types.d.ts +7 -0
- package/dist/server/part.types.js +2 -0
- package/dist/server/serve.d.ts +14 -0
- package/dist/server/serve.js +27 -0
- package/dist/testing/test-server.d.ts +12 -0
- package/dist/testing/test-server.js +26 -0
- package/dist/tool/build-info.d.ts +4 -0
- package/dist/tool/build-info.js +18 -0
- package/dist/tool/build.d.ts +35 -0
- package/dist/tool/build.js +83 -0
- package/dist/tool/cli.d.ts +2 -0
- package/dist/tool/cli.js +3 -0
- package/dist/tool/docker.d.ts +15 -0
- package/dist/tool/docker.js +26 -0
- package/dist/tool/exec.d.ts +12 -0
- package/dist/tool/exec.js +24 -0
- package/dist/tool/format.d.ts +2 -0
- package/dist/tool/format.js +14 -0
- package/dist/tool/index.d.ts +11 -0
- package/dist/tool/index.js +11 -0
- package/dist/tool/labels.d.ts +4 -0
- package/dist/tool/labels.js +25 -0
- package/dist/tool/main.d.ts +8 -0
- package/dist/tool/main.js +54 -0
- package/dist/tool/recipe.d.ts +3 -0
- package/dist/tool/recipe.js +32 -0
- package/dist/tool/stage.d.ts +5 -0
- package/dist/tool/stage.js +52 -0
- package/package.json +64 -4
- package/schemas/error-envelope.schema.json +70 -0
- package/schemas/extension-discovery.schema.json +182 -0
- package/schemas/extension-package.schema.json +309 -0
- package/schemas/extension-record.schema.json +176 -0
- package/schemas/health.schema.json +100 -0
- package/schemas/ok-envelope.schema.json +25 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const HealthStatusSchema: z.ZodEnum<{
|
|
3
|
+
ok: "ok";
|
|
4
|
+
degraded: "degraded";
|
|
5
|
+
unavailable: "unavailable";
|
|
6
|
+
}>;
|
|
7
|
+
export declare const DeployedPartKindSchema: z.ZodEnum<{
|
|
8
|
+
pages: "pages";
|
|
9
|
+
ui: "ui";
|
|
10
|
+
api: "api";
|
|
11
|
+
mcp: "mcp";
|
|
12
|
+
worker: "worker";
|
|
13
|
+
store: "store";
|
|
14
|
+
}>;
|
|
15
|
+
export declare const HealthSchema: z.ZodObject<{
|
|
16
|
+
success: z.ZodBoolean;
|
|
17
|
+
data: z.ZodObject<{
|
|
18
|
+
status: z.ZodEnum<{
|
|
19
|
+
ok: "ok";
|
|
20
|
+
degraded: "degraded";
|
|
21
|
+
unavailable: "unavailable";
|
|
22
|
+
}>;
|
|
23
|
+
extension: z.ZodString;
|
|
24
|
+
part: z.ZodEnum<{
|
|
25
|
+
pages: "pages";
|
|
26
|
+
ui: "ui";
|
|
27
|
+
api: "api";
|
|
28
|
+
mcp: "mcp";
|
|
29
|
+
worker: "worker";
|
|
30
|
+
store: "store";
|
|
31
|
+
}>;
|
|
32
|
+
version: z.ZodString;
|
|
33
|
+
commit: z.ZodString;
|
|
34
|
+
buildTime: z.ZodISODateTime;
|
|
35
|
+
instance: z.ZodString;
|
|
36
|
+
uptimeSeconds: z.ZodInt;
|
|
37
|
+
checkedAt: z.ZodISODateTime;
|
|
38
|
+
checks: z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
39
|
+
ok: "ok";
|
|
40
|
+
degraded: "degraded";
|
|
41
|
+
unavailable: "unavailable";
|
|
42
|
+
}>>;
|
|
43
|
+
}, z.core.$strict>;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
export type HealthStatus = z.infer<typeof HealthStatusSchema>;
|
|
46
|
+
export type HealthBody = z.infer<typeof HealthSchema>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ExtensionIdSchema, VersionSchema } from '../manifest/primitives.schema.js';
|
|
3
|
+
export const HealthStatusSchema = z.enum(['ok', 'degraded', 'unavailable']);
|
|
4
|
+
export const DeployedPartKindSchema = z.enum(['pages', 'ui', 'api', 'mcp', 'worker', 'store']);
|
|
5
|
+
// GET /health of every part container (api-standards section 7); never hostnames, IPs or env values.
|
|
6
|
+
export const HealthSchema = z.strictObject({
|
|
7
|
+
success: z.boolean(),
|
|
8
|
+
data: z.strictObject({
|
|
9
|
+
status: HealthStatusSchema,
|
|
10
|
+
extension: ExtensionIdSchema,
|
|
11
|
+
part: DeployedPartKindSchema,
|
|
12
|
+
version: VersionSchema,
|
|
13
|
+
commit: z.string().regex(/^[0-9a-f]{7,40}$/),
|
|
14
|
+
buildTime: z.iso.datetime(),
|
|
15
|
+
instance: z.string().regex(/^[0-9a-f]{8,32}$/),
|
|
16
|
+
uptimeSeconds: z.int().min(0),
|
|
17
|
+
checkedAt: z.iso.datetime(),
|
|
18
|
+
checks: z.record(z.string().regex(/^[a-z][a-z0-9-]*$/), HealthStatusSchema),
|
|
19
|
+
}),
|
|
20
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { AGCID_HEADER, agcidOf, isAgcid, uuidv7 } from './agcid/agcid.js';
|
|
2
|
+
export { currentAgcid } from './agcid/scope.js';
|
|
3
|
+
export { createContext, createTestContext, type ExtensionInfo, type LogEntry, type PartContext, type ServerPartKind, type SettingValue, type TestContext, type TestContextOptions, } from './context/context.js';
|
|
4
|
+
export { DEFAULT_RECORD_FILE, discoveryDocument, loadRecord, recordOf, validateRecord, type BuildInfo, type PartImages, } from './discovery/discovery.js';
|
|
5
|
+
export { DiscoveryDocumentSchema, ExtensionRecordSchema, type DiscoveryDocument, type ExtensionRecord, } from './discovery/discovery.schema.js';
|
|
6
|
+
export { ERROR_CODES, ERROR_STATUS, type ErrorCode } from './envelope/codes.js';
|
|
7
|
+
export { errorEnvelope, fail, isFailure, ok, type ErrorDetail, type ErrorEnvelope, type Failure, type FailOptions, type OkEnvelope, } from './envelope/envelope.js';
|
|
8
|
+
export { ErrorEnvelopeSchema, OkEnvelopeSchema } from './envelope/envelope.schema.js';
|
|
9
|
+
export { parse, type ParseSchema } from './envelope/parse.js';
|
|
10
|
+
export { createHealthHandler, type HealthCheck, type HealthOptions } from './health/health.js';
|
|
11
|
+
export { HealthSchema, type HealthBody, type HealthStatus } from './health/health.schema.js';
|
|
12
|
+
export { createLog, type Log, type LogFields } from './log/log.js';
|
|
13
|
+
export { PackageSchema, type ExtensionPackage } from './manifest/manifest.schema.js';
|
|
14
|
+
export { entryOf, imageParts, normalizeParts } from './manifest/parts.js';
|
|
15
|
+
export { readManifest, validateManifest } from './manifest/read-manifest.js';
|
|
16
|
+
export { createApiApp, PUBLIC_CORS, type ApiAppOptions } from './server/app.js';
|
|
17
|
+
export { serve, type ServeOptions } from './server/serve.js';
|
|
18
|
+
export { startTestServer, type TestServer, type TestServerOptions } from './testing/test-server.js';
|
|
19
|
+
export { type ApiCreate, type ApiHandler, type ApiPart } from './server/part.types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { AGCID_HEADER, agcidOf, isAgcid, uuidv7 } from './agcid/agcid.js';
|
|
2
|
+
export { currentAgcid } from './agcid/scope.js';
|
|
3
|
+
export { createContext, createTestContext, } from './context/context.js';
|
|
4
|
+
export { DEFAULT_RECORD_FILE, discoveryDocument, loadRecord, recordOf, validateRecord, } from './discovery/discovery.js';
|
|
5
|
+
export { DiscoveryDocumentSchema, ExtensionRecordSchema, } from './discovery/discovery.schema.js';
|
|
6
|
+
export { ERROR_CODES, ERROR_STATUS } from './envelope/codes.js';
|
|
7
|
+
export { errorEnvelope, fail, isFailure, ok, } from './envelope/envelope.js';
|
|
8
|
+
export { ErrorEnvelopeSchema, OkEnvelopeSchema } from './envelope/envelope.schema.js';
|
|
9
|
+
export { parse } from './envelope/parse.js';
|
|
10
|
+
export { createHealthHandler } from './health/health.js';
|
|
11
|
+
export { HealthSchema } from './health/health.schema.js';
|
|
12
|
+
export { createLog } from './log/log.js';
|
|
13
|
+
export { PackageSchema } from './manifest/manifest.schema.js';
|
|
14
|
+
export { entryOf, imageParts, normalizeParts } from './manifest/parts.js';
|
|
15
|
+
export { readManifest, validateManifest } from './manifest/read-manifest.js';
|
|
16
|
+
export { createApiApp, PUBLIC_CORS } from './server/app.js';
|
|
17
|
+
export { serve } from './server/serve.js';
|
|
18
|
+
export { startTestServer } from './testing/test-server.js';
|
|
19
|
+
export {} from './server/part.types.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type LogLevel = 'info' | 'warn' | 'error';
|
|
2
|
+
export type LogFields = Record<string, unknown>;
|
|
3
|
+
export interface Log {
|
|
4
|
+
info(message: string, fields?: LogFields): void;
|
|
5
|
+
warn(message: string, fields?: LogFields): void;
|
|
6
|
+
error(error: unknown, fields?: LogFields): void;
|
|
7
|
+
}
|
|
8
|
+
export interface LogTags {
|
|
9
|
+
extension: string;
|
|
10
|
+
part: string;
|
|
11
|
+
}
|
|
12
|
+
export type LogWrite = (line: string) => void;
|
|
13
|
+
export declare const createLog: (tags: LogTags, write?: LogWrite) => Log;
|
package/dist/log/log.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { currentAgcid } from '../agcid/scope.js';
|
|
2
|
+
const errorFields = (error) => {
|
|
3
|
+
if (!(error instanceof Error))
|
|
4
|
+
return { err: { message: String(error) } };
|
|
5
|
+
return { err: { type: error.name, message: error.message, stack: error.stack } };
|
|
6
|
+
};
|
|
7
|
+
const line = (level, message, tags, fields) => {
|
|
8
|
+
const agcid = currentAgcid();
|
|
9
|
+
const entry = { time: new Date().toISOString(), level, msg: message, ...tags, ...fields };
|
|
10
|
+
return `${JSON.stringify(agcid ? { ...entry, agcid } : entry)}\n`;
|
|
11
|
+
};
|
|
12
|
+
const stderrWrite = (text) => void process.stderr.write(text);
|
|
13
|
+
// JSON lines on stderr, tagged with extension, part and the request's agcid.
|
|
14
|
+
export const createLog = (tags, write = stderrWrite) => ({
|
|
15
|
+
info: (message, fields = {}) => write(line('info', message, tags, fields)),
|
|
16
|
+
warn: (message, fields = {}) => write(line('warn', message, tags, fields)),
|
|
17
|
+
error: (error, fields = {}) => {
|
|
18
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
+
write(line('error', message, tags, { ...errorFields(error), ...fields }));
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const CodePartSchema: z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
3
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
4
|
+
}, z.core.$strict>]>;
|
|
5
|
+
export declare const PartsSchema: z.ZodObject<{
|
|
6
|
+
pages: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
7
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, z.core.$strict>]>>;
|
|
9
|
+
ui: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
10
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.core.$strict>]>>;
|
|
12
|
+
api: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
13
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, z.core.$strict>]>>;
|
|
15
|
+
mcp: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
16
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strict>]>>;
|
|
18
|
+
worker: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
19
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.core.$strict>]>>;
|
|
21
|
+
cli: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
22
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strict>]>>;
|
|
24
|
+
store: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
25
|
+
postgres: "postgres";
|
|
26
|
+
git: "git";
|
|
27
|
+
signoz: "signoz";
|
|
28
|
+
}>, z.ZodObject<{
|
|
29
|
+
kind: z.ZodEnum<{
|
|
30
|
+
postgres: "postgres";
|
|
31
|
+
git: "git";
|
|
32
|
+
signoz: "signoz";
|
|
33
|
+
}>;
|
|
34
|
+
}, z.core.$strict>]>>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
export declare const CommandSchema: z.ZodObject<{
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
summary: z.ZodString;
|
|
39
|
+
args: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
40
|
+
name: z.ZodString;
|
|
41
|
+
type: z.ZodEnum<{
|
|
42
|
+
string: "string";
|
|
43
|
+
number: "number";
|
|
44
|
+
boolean: "boolean";
|
|
45
|
+
integer: "integer";
|
|
46
|
+
}>;
|
|
47
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
48
|
+
description: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, z.core.$strict>>>;
|
|
50
|
+
}, z.core.$strict>;
|
|
51
|
+
export declare const SettingSchema: z.ZodObject<{
|
|
52
|
+
type: z.ZodEnum<{
|
|
53
|
+
string: "string";
|
|
54
|
+
number: "number";
|
|
55
|
+
boolean: "boolean";
|
|
56
|
+
integer: "integer";
|
|
57
|
+
}>;
|
|
58
|
+
default: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
59
|
+
enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
60
|
+
description: z.ZodOptional<z.ZodString>;
|
|
61
|
+
}, z.core.$strict>;
|
|
62
|
+
export declare const AgentageSchema: z.ZodObject<{
|
|
63
|
+
id: z.ZodString;
|
|
64
|
+
parts: z.ZodObject<{
|
|
65
|
+
pages: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
66
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
67
|
+
}, z.core.$strict>]>>;
|
|
68
|
+
ui: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
69
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strict>]>>;
|
|
71
|
+
api: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
72
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
73
|
+
}, z.core.$strict>]>>;
|
|
74
|
+
mcp: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
75
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
76
|
+
}, z.core.$strict>]>>;
|
|
77
|
+
worker: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
78
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
79
|
+
}, z.core.$strict>]>>;
|
|
80
|
+
cli: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
81
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, z.core.$strict>]>>;
|
|
83
|
+
store: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
84
|
+
postgres: "postgres";
|
|
85
|
+
git: "git";
|
|
86
|
+
signoz: "signoz";
|
|
87
|
+
}>, z.ZodObject<{
|
|
88
|
+
kind: z.ZodEnum<{
|
|
89
|
+
postgres: "postgres";
|
|
90
|
+
git: "git";
|
|
91
|
+
signoz: "signoz";
|
|
92
|
+
}>;
|
|
93
|
+
}, z.core.$strict>]>>;
|
|
94
|
+
}, z.core.$strict>;
|
|
95
|
+
commands: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
96
|
+
name: z.ZodString;
|
|
97
|
+
summary: z.ZodString;
|
|
98
|
+
args: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
99
|
+
name: z.ZodString;
|
|
100
|
+
type: z.ZodEnum<{
|
|
101
|
+
string: "string";
|
|
102
|
+
number: "number";
|
|
103
|
+
boolean: "boolean";
|
|
104
|
+
integer: "integer";
|
|
105
|
+
}>;
|
|
106
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
107
|
+
description: z.ZodOptional<z.ZodString>;
|
|
108
|
+
}, z.core.$strict>>>;
|
|
109
|
+
}, z.core.$strict>>>;
|
|
110
|
+
settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
111
|
+
type: z.ZodEnum<{
|
|
112
|
+
string: "string";
|
|
113
|
+
number: "number";
|
|
114
|
+
boolean: "boolean";
|
|
115
|
+
integer: "integer";
|
|
116
|
+
}>;
|
|
117
|
+
default: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
118
|
+
enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
119
|
+
description: z.ZodOptional<z.ZodString>;
|
|
120
|
+
}, z.core.$strict>>>;
|
|
121
|
+
secrets: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
122
|
+
}, z.core.$strict>;
|
|
123
|
+
export declare const PackageSchema: z.ZodObject<{
|
|
124
|
+
name: z.ZodString;
|
|
125
|
+
version: z.ZodString;
|
|
126
|
+
engines: z.ZodObject<{
|
|
127
|
+
agentage: z.ZodString;
|
|
128
|
+
}, z.core.$loose>;
|
|
129
|
+
agentage: z.ZodObject<{
|
|
130
|
+
id: z.ZodString;
|
|
131
|
+
parts: z.ZodObject<{
|
|
132
|
+
pages: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
133
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
134
|
+
}, z.core.$strict>]>>;
|
|
135
|
+
ui: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
136
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
137
|
+
}, z.core.$strict>]>>;
|
|
138
|
+
api: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
139
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
140
|
+
}, z.core.$strict>]>>;
|
|
141
|
+
mcp: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
142
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
143
|
+
}, z.core.$strict>]>>;
|
|
144
|
+
worker: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
145
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
146
|
+
}, z.core.$strict>]>>;
|
|
147
|
+
cli: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
148
|
+
entry: z.ZodOptional<z.ZodString>;
|
|
149
|
+
}, z.core.$strict>]>>;
|
|
150
|
+
store: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
151
|
+
postgres: "postgres";
|
|
152
|
+
git: "git";
|
|
153
|
+
signoz: "signoz";
|
|
154
|
+
}>, z.ZodObject<{
|
|
155
|
+
kind: z.ZodEnum<{
|
|
156
|
+
postgres: "postgres";
|
|
157
|
+
git: "git";
|
|
158
|
+
signoz: "signoz";
|
|
159
|
+
}>;
|
|
160
|
+
}, z.core.$strict>]>>;
|
|
161
|
+
}, z.core.$strict>;
|
|
162
|
+
commands: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
163
|
+
name: z.ZodString;
|
|
164
|
+
summary: z.ZodString;
|
|
165
|
+
args: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
166
|
+
name: z.ZodString;
|
|
167
|
+
type: z.ZodEnum<{
|
|
168
|
+
string: "string";
|
|
169
|
+
number: "number";
|
|
170
|
+
boolean: "boolean";
|
|
171
|
+
integer: "integer";
|
|
172
|
+
}>;
|
|
173
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
174
|
+
description: z.ZodOptional<z.ZodString>;
|
|
175
|
+
}, z.core.$strict>>>;
|
|
176
|
+
}, z.core.$strict>>>;
|
|
177
|
+
settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
178
|
+
type: z.ZodEnum<{
|
|
179
|
+
string: "string";
|
|
180
|
+
number: "number";
|
|
181
|
+
boolean: "boolean";
|
|
182
|
+
integer: "integer";
|
|
183
|
+
}>;
|
|
184
|
+
default: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
185
|
+
enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
186
|
+
description: z.ZodOptional<z.ZodString>;
|
|
187
|
+
}, z.core.$strict>>>;
|
|
188
|
+
secrets: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
189
|
+
}, z.core.$strict>;
|
|
190
|
+
}, z.core.$loose>;
|
|
191
|
+
export type CodePart = z.infer<typeof CodePartSchema>;
|
|
192
|
+
export type Parts = z.infer<typeof PartsSchema>;
|
|
193
|
+
export type Agentage = z.infer<typeof AgentageSchema>;
|
|
194
|
+
export type ExtensionPackage = z.infer<typeof PackageSchema>;
|
|
195
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CommandNameSchema, ExtensionIdSchema, FIRST_PARTY_IDS, PackageNameSchema, PackagePathSchema, SecretNameSchema, SemverRangeSchema, SettingKeySchema, StoreKindSchema, VersionSchema, } from './primitives.schema.js';
|
|
3
|
+
const CodePartSchema = z.union([
|
|
4
|
+
z.boolean(),
|
|
5
|
+
z.strictObject({ entry: PackagePathSchema.optional() }),
|
|
6
|
+
]);
|
|
7
|
+
const StorePartSchema = z.union([StoreKindSchema, z.strictObject({ kind: StoreKindSchema })]);
|
|
8
|
+
const ROUTED = ['pages', 'ui', 'api', 'mcp'];
|
|
9
|
+
export const PartsSchema = z
|
|
10
|
+
.strictObject({
|
|
11
|
+
pages: CodePartSchema.optional(),
|
|
12
|
+
ui: CodePartSchema.optional(),
|
|
13
|
+
api: CodePartSchema.optional(),
|
|
14
|
+
mcp: CodePartSchema.optional(),
|
|
15
|
+
worker: CodePartSchema.optional(),
|
|
16
|
+
cli: CodePartSchema.optional(),
|
|
17
|
+
store: StorePartSchema.optional(),
|
|
18
|
+
})
|
|
19
|
+
.refine((parts) => ROUTED.some((kind) => isOn(parts[kind])), {
|
|
20
|
+
message: 'at least one routed part (pages, ui, api or mcp)',
|
|
21
|
+
});
|
|
22
|
+
const ArgTypeSchema = z.enum(['string', 'integer', 'number', 'boolean']);
|
|
23
|
+
export const CommandSchema = z.strictObject({
|
|
24
|
+
name: CommandNameSchema,
|
|
25
|
+
summary: z.string().min(1).max(120),
|
|
26
|
+
args: z
|
|
27
|
+
.array(z.strictObject({
|
|
28
|
+
name: CommandNameSchema,
|
|
29
|
+
type: ArgTypeSchema,
|
|
30
|
+
required: z.boolean().optional(),
|
|
31
|
+
description: z.string().min(1).max(200).optional(),
|
|
32
|
+
}))
|
|
33
|
+
.optional(),
|
|
34
|
+
});
|
|
35
|
+
export const SettingSchema = z
|
|
36
|
+
.strictObject({
|
|
37
|
+
type: ArgTypeSchema,
|
|
38
|
+
default: z.union([z.string(), z.number(), z.boolean()]),
|
|
39
|
+
enum: z.array(z.string()).min(1).optional(),
|
|
40
|
+
description: z.string().min(1).max(200).optional(),
|
|
41
|
+
})
|
|
42
|
+
.refine((setting) => defaultFits(setting.type, setting.default), {
|
|
43
|
+
message: 'default does not match type',
|
|
44
|
+
});
|
|
45
|
+
const AgentageBaseSchema = z.strictObject({
|
|
46
|
+
id: ExtensionIdSchema,
|
|
47
|
+
parts: PartsSchema,
|
|
48
|
+
commands: z.array(CommandSchema).min(1).optional(),
|
|
49
|
+
settings: z.record(SettingKeySchema, SettingSchema).optional(),
|
|
50
|
+
secrets: z.array(SecretNameSchema).optional(),
|
|
51
|
+
});
|
|
52
|
+
export const AgentageSchema = AgentageBaseSchema.superRefine(crossFieldRules);
|
|
53
|
+
export const PackageSchema = z
|
|
54
|
+
.looseObject({
|
|
55
|
+
name: PackageNameSchema,
|
|
56
|
+
version: VersionSchema,
|
|
57
|
+
engines: z.looseObject({ agentage: SemverRangeSchema }),
|
|
58
|
+
agentage: AgentageSchema,
|
|
59
|
+
})
|
|
60
|
+
.refine((pkg) => !isFirstParty(pkg.agentage.id) || pkg.name.startsWith('@agentage/'), {
|
|
61
|
+
message: 'a first-party id is claimed only by an @agentage/ package',
|
|
62
|
+
path: ['name'],
|
|
63
|
+
});
|
|
64
|
+
function isOn(part) {
|
|
65
|
+
return part !== undefined && part !== false;
|
|
66
|
+
}
|
|
67
|
+
function isFirstParty(id) {
|
|
68
|
+
return FIRST_PARTY_IDS.includes(id);
|
|
69
|
+
}
|
|
70
|
+
function defaultFits(type, value) {
|
|
71
|
+
if (type === 'integer')
|
|
72
|
+
return Number.isInteger(value);
|
|
73
|
+
return typeof value === type;
|
|
74
|
+
}
|
|
75
|
+
function crossFieldRules(manifest, ctx) {
|
|
76
|
+
const issue = (message, path) => ctx.addIssue({ code: 'custom', message, path });
|
|
77
|
+
const hasCli = isOn(manifest.parts.cli);
|
|
78
|
+
if (manifest.commands && !hasCli)
|
|
79
|
+
issue('commands need the cli part', ['commands']);
|
|
80
|
+
if (hasCli && !manifest.commands)
|
|
81
|
+
issue('the cli part needs commands', ['parts', 'cli']);
|
|
82
|
+
const names = (manifest.commands ?? []).map((command) => command.name);
|
|
83
|
+
if (new Set(names).size !== names.length)
|
|
84
|
+
issue('command names must be unique', ['commands']);
|
|
85
|
+
if (manifest.settings?.['mcp.listing'] && !isOn(manifest.parts.mcp)) {
|
|
86
|
+
issue('mcp.listing needs the mcp part', ['settings', 'mcp.listing']);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ExtensionPackage, type Parts } from './manifest.schema.js';
|
|
2
|
+
import { type ImagePartKind, type StoreKind } from './primitives.schema.js';
|
|
3
|
+
export interface NormalizedParts {
|
|
4
|
+
code: Partial<Record<ImagePartKind | 'cli', {
|
|
5
|
+
entry?: string;
|
|
6
|
+
}>>;
|
|
7
|
+
store?: StoreKind;
|
|
8
|
+
}
|
|
9
|
+
export declare const normalizeParts: (parts: Parts) => NormalizedParts;
|
|
10
|
+
export declare const imageParts: (pkg: ExtensionPackage) => ImagePartKind[];
|
|
11
|
+
export declare const entryOf: (pkg: ExtensionPackage, part: ImagePartKind | "cli") => string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {} from './manifest.schema.js';
|
|
2
|
+
import { IMAGE_PART_KINDS } from './primitives.schema.js';
|
|
3
|
+
const normalizeCode = (part) => {
|
|
4
|
+
if (part === undefined || part === false)
|
|
5
|
+
return undefined;
|
|
6
|
+
return part === true ? {} : part;
|
|
7
|
+
};
|
|
8
|
+
const storeKind = (store) => typeof store === 'object' ? store.kind : store;
|
|
9
|
+
// The manifest accepts `api: true` and `store: "postgres"`; the kit works on one shape.
|
|
10
|
+
export const normalizeParts = (parts) => {
|
|
11
|
+
const code = {};
|
|
12
|
+
for (const kind of [...IMAGE_PART_KINDS, 'cli']) {
|
|
13
|
+
const normalized = normalizeCode(parts[kind]);
|
|
14
|
+
if (normalized)
|
|
15
|
+
code[kind] = normalized;
|
|
16
|
+
}
|
|
17
|
+
const store = storeKind(parts.store);
|
|
18
|
+
return store ? { code, store } : { code };
|
|
19
|
+
};
|
|
20
|
+
export const imageParts = (pkg) => {
|
|
21
|
+
const { code } = normalizeParts(pkg.agentage.parts);
|
|
22
|
+
return IMAGE_PART_KINDS.filter((kind) => code[kind] !== undefined);
|
|
23
|
+
};
|
|
24
|
+
export const entryOf = (pkg, part) => normalizeParts(pkg.agentage.parts).code[part]?.entry ?? `./dist/${part}/index.js`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ExtensionIdSchema: z.ZodString;
|
|
3
|
+
export declare const FIRST_PARTY_IDS: readonly ["root", "cloud", "market", "logs", "memory", "catalog", "dashboard", "docs"];
|
|
4
|
+
export declare const PackageNameSchema: z.ZodString;
|
|
5
|
+
export declare const VersionSchema: z.ZodString;
|
|
6
|
+
export declare const SemverRangeSchema: z.ZodString;
|
|
7
|
+
export declare const CommandNameSchema: z.ZodString;
|
|
8
|
+
export declare const SettingKeySchema: z.ZodString;
|
|
9
|
+
export declare const SecretNameSchema: z.ZodString;
|
|
10
|
+
export declare const PackagePathSchema: z.ZodString;
|
|
11
|
+
export declare const StoreKindSchema: z.ZodEnum<{
|
|
12
|
+
postgres: "postgres";
|
|
13
|
+
git: "git";
|
|
14
|
+
signoz: "signoz";
|
|
15
|
+
}>;
|
|
16
|
+
export declare const CommitSchema: z.ZodString;
|
|
17
|
+
export declare const PrefixedToolNameSchema: z.ZodString;
|
|
18
|
+
export declare const IMAGE_PART_KINDS: readonly ["pages", "ui", "api", "mcp", "worker"];
|
|
19
|
+
export type ImagePartKind = (typeof IMAGE_PART_KINDS)[number];
|
|
20
|
+
export type StoreKind = z.infer<typeof StoreKindSchema>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const RESERVED_IDS = 'auth|www|api|sync|mail|mcp|ui|git|setup|status|update|extension|add|remove|help|con|prn|aux|nul|com[0-9]|lpt[0-9]';
|
|
3
|
+
export const ExtensionIdSchema = z
|
|
4
|
+
.string()
|
|
5
|
+
.max(32)
|
|
6
|
+
.regex(new RegExp(`^(?!(?:${RESERVED_IDS})$)[a-z][a-z0-9-]*$`), {
|
|
7
|
+
message: 'lowercase id, never a name the platform owns',
|
|
8
|
+
});
|
|
9
|
+
export const FIRST_PARTY_IDS = [
|
|
10
|
+
'root',
|
|
11
|
+
'cloud',
|
|
12
|
+
'market',
|
|
13
|
+
'logs',
|
|
14
|
+
'memory',
|
|
15
|
+
'catalog',
|
|
16
|
+
'dashboard',
|
|
17
|
+
'docs',
|
|
18
|
+
];
|
|
19
|
+
export const PackageNameSchema = z
|
|
20
|
+
.string()
|
|
21
|
+
.max(214)
|
|
22
|
+
.regex(/^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/);
|
|
23
|
+
export const VersionSchema = z
|
|
24
|
+
.string()
|
|
25
|
+
.regex(/^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/);
|
|
26
|
+
export const SemverRangeSchema = z
|
|
27
|
+
.string()
|
|
28
|
+
.max(64)
|
|
29
|
+
.regex(/^[0-9xX*^~<>=| .-]+[0-9A-Za-z.-]*$/);
|
|
30
|
+
export const CommandNameSchema = z
|
|
31
|
+
.string()
|
|
32
|
+
.max(32)
|
|
33
|
+
.regex(/^[a-z][a-z0-9-]*$/);
|
|
34
|
+
export const SettingKeySchema = z
|
|
35
|
+
.string()
|
|
36
|
+
.max(64)
|
|
37
|
+
.regex(/^[a-z][A-Za-z0-9]*(\.[a-z][A-Za-z0-9]*)*$/);
|
|
38
|
+
export const SecretNameSchema = z
|
|
39
|
+
.string()
|
|
40
|
+
.max(48)
|
|
41
|
+
.regex(/^[a-z][a-z0-9-]*$/);
|
|
42
|
+
export const PackagePathSchema = z
|
|
43
|
+
.string()
|
|
44
|
+
.max(256)
|
|
45
|
+
.regex(/^\.\/[A-Za-z0-9._/-]+$/);
|
|
46
|
+
export const StoreKindSchema = z.enum(['postgres', 'git', 'signoz']);
|
|
47
|
+
export const CommitSchema = z.string().regex(/^[0-9a-f]{40}$/, { message: 'full 40-hex git sha' });
|
|
48
|
+
export const PrefixedToolNameSchema = z
|
|
49
|
+
.string()
|
|
50
|
+
.max(64)
|
|
51
|
+
.regex(/^[a-z][a-z0-9-]*__[a-z][a-z0-9_-]*$/);
|
|
52
|
+
export const IMAGE_PART_KINDS = ['pages', 'ui', 'api', 'mcp', 'worker'];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type z } from 'zod';
|
|
2
|
+
import { type ExtensionPackage } from './manifest.schema.js';
|
|
3
|
+
export declare const formatIssues: (issues: readonly z.core.$ZodIssue[]) => string;
|
|
4
|
+
export declare const validateManifest: (value: unknown) => ExtensionPackage;
|
|
5
|
+
export declare const readManifest: (dir: string) => Promise<ExtensionPackage>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import {} from 'zod';
|
|
4
|
+
import { PackageSchema } from './manifest.schema.js';
|
|
5
|
+
export const formatIssues = (issues) => issues
|
|
6
|
+
.map((issue) => `${issue.path.map((segment) => String(segment)).join('.')}: ${issue.message}`)
|
|
7
|
+
.join('; ');
|
|
8
|
+
export const validateManifest = (value) => {
|
|
9
|
+
const result = PackageSchema.safeParse(value);
|
|
10
|
+
if (result.success)
|
|
11
|
+
return result.data;
|
|
12
|
+
throw new Error(`invalid agentage manifest in package.json: ${formatIssues(result.error.issues)}`);
|
|
13
|
+
};
|
|
14
|
+
// The manifest is the `agentage` block of package.json, read as data without running code.
|
|
15
|
+
export const readManifest = async (dir) => {
|
|
16
|
+
const file = join(dir, 'package.json');
|
|
17
|
+
const text = await readFile(file, 'utf8');
|
|
18
|
+
return validateManifest(JSON.parse(text));
|
|
19
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type BuildInfo } from '../discovery/discovery.js';
|
|
2
|
+
export type Env = Readonly<Record<string, string | undefined>>;
|
|
3
|
+
export declare const buildInfoFromEnv: (env: Env, now?: Date) => BuildInfo;
|
|
4
|
+
export declare const portFromEnv: (env: Env, fallback?: number) => number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {} from '../discovery/discovery.js';
|
|
2
|
+
const UNKNOWN_COMMIT = '0'.repeat(40);
|
|
3
|
+
const isoSeconds = (date) => `${date.toISOString().slice(0, 19)}Z`;
|
|
4
|
+
// COMMIT_SHA and BUILD_TIME are baked into every image by the recipe; a bare dev run shows zeros.
|
|
5
|
+
export const buildInfoFromEnv = (env, now = new Date()) => ({
|
|
6
|
+
commit: env['COMMIT_SHA'] && /^[0-9a-f]{40}$/.test(env['COMMIT_SHA'])
|
|
7
|
+
? env['COMMIT_SHA']
|
|
8
|
+
: UNKNOWN_COMMIT,
|
|
9
|
+
buildTime: env['BUILD_TIME'] || isoSeconds(now),
|
|
10
|
+
});
|
|
11
|
+
export const portFromEnv = (env, fallback = 3000) => {
|
|
12
|
+
const port = Number(env['PORT']);
|
|
13
|
+
return env['PORT'] !== undefined && Number.isInteger(port) && port >= 0 && port < 65536
|
|
14
|
+
? port
|
|
15
|
+
: fallback;
|
|
16
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runPart } from './run-part.js';
|
|
3
|
+
// Image entry: `node node_modules/@agentage/extension/dist/runtime/main.js api` in /app.
|
|
4
|
+
try {
|
|
5
|
+
await runPart({ dir: process.cwd(), part: process.argv[2] ?? 'api', env: process.env });
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
process.stderr.write(`${JSON.stringify({ level: 'error', msg: String(err) })}\n`);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Server } from 'node:http';
|
|
2
|
+
import { type ApiCreate } from '../server/part.types.js';
|
|
3
|
+
import { type ServeOptions } from '../server/serve.js';
|
|
4
|
+
import { type Env } from './build-info.js';
|
|
5
|
+
export interface RunPartOptions {
|
|
6
|
+
dir: string;
|
|
7
|
+
part: string;
|
|
8
|
+
env: Env;
|
|
9
|
+
importModule?: (file: string) => Promise<unknown>;
|
|
10
|
+
serve?: Pick<ServeOptions, 'signals' | 'exit'>;
|
|
11
|
+
}
|
|
12
|
+
export declare const createOf: (mod: unknown, file: string) => ApiCreate;
|
|
13
|
+
export declare const runPart: (options: RunPartOptions) => Promise<Server>;
|