@11agents/cli 0.1.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.
- package/README.md +103 -0
- package/bin/11agents.js +135 -0
- package/bin/gtm-swarm.js +74 -0
- package/examples/voc-mcp-tool-call-batch.json +45 -0
- package/examples/x-agent-batch.json +54 -0
- package/examples/x-observation-job-result.json +24 -0
- package/package.json +37 -0
- package/specs/agent-json-contract.md +77 -0
- package/src/args.js +43 -0
- package/src/client.js +42 -0
- package/src/commands/node.js +54 -0
- package/src/commands/push.js +56 -0
- package/src/commands/runtime.js +353 -0
- package/src/daemon-process.js +92 -0
- package/src/info.js +62 -0
- package/src/runtime-scan.js +114 -0
- package/src/schema.js +59 -0
package/src/schema.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export const TELEMETRY_SCHEMA_VERSION = 'swarm.telemetry.v1'
|
|
2
|
+
|
|
3
|
+
function isObject(value) {
|
|
4
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isNonEmptyString(value) {
|
|
8
|
+
return typeof value === 'string' && value.trim().length > 0
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function isIsoTimestamp(value) {
|
|
12
|
+
return isNonEmptyString(value) && !Number.isNaN(Date.parse(value))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function fail(error) {
|
|
16
|
+
return { ok: false, error }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function validateTelemetryBatch(input) {
|
|
20
|
+
if (!isObject(input)) return fail('batch must be an object')
|
|
21
|
+
if (input.schema_version !== TELEMETRY_SCHEMA_VERSION) return fail(`schema_version must be ${TELEMETRY_SCHEMA_VERSION}`)
|
|
22
|
+
for (const field of ['workspace', 'agent_key', 'node_id']) {
|
|
23
|
+
if (!isNonEmptyString(input[field])) return fail(`${field} is required`)
|
|
24
|
+
}
|
|
25
|
+
const artifacts = Array.isArray(input.artifacts) ? input.artifacts : []
|
|
26
|
+
const observations = Array.isArray(input.observations) ? input.observations : []
|
|
27
|
+
if (!artifacts.length && !observations.length) return fail('artifacts or observations are required')
|
|
28
|
+
for (let i = 0; i < artifacts.length; i += 1) {
|
|
29
|
+
const item = artifacts[i]
|
|
30
|
+
for (const field of ['platform', 'artifact_type', 'external_id', 'created_at']) {
|
|
31
|
+
if (!isNonEmptyString(item?.[field])) return fail(`artifacts[${i}].${field} is required`)
|
|
32
|
+
}
|
|
33
|
+
if (!isIsoTimestamp(item.created_at)) return fail(`artifacts[${i}].created_at must be an ISO timestamp`)
|
|
34
|
+
}
|
|
35
|
+
for (let i = 0; i < observations.length; i += 1) {
|
|
36
|
+
const item = observations[i]
|
|
37
|
+
for (const field of ['platform', 'artifact_type', 'external_id', 'observed_at']) {
|
|
38
|
+
if (!isNonEmptyString(item?.[field])) return fail(`observations[${i}].${field} is required`)
|
|
39
|
+
}
|
|
40
|
+
if (!isIsoTimestamp(item.observed_at)) return fail(`observations[${i}].observed_at must be an ISO timestamp`)
|
|
41
|
+
if (!isObject(item.metrics)) return fail(`observations[${i}].metrics must be an object`)
|
|
42
|
+
for (const [key, value] of Object.entries(item.metrics)) {
|
|
43
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) return fail(`observations[${i}].metrics.${key} must be a finite number`)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { ok: true, batch: input }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function buildTelemetryBatch({ workspace, agent_key, node_id, artifacts = [], observations = [] }) {
|
|
50
|
+
return {
|
|
51
|
+
schema_version: TELEMETRY_SCHEMA_VERSION,
|
|
52
|
+
workspace,
|
|
53
|
+
agent_key,
|
|
54
|
+
node_id,
|
|
55
|
+
sent_at: new Date().toISOString(),
|
|
56
|
+
artifacts,
|
|
57
|
+
observations,
|
|
58
|
+
}
|
|
59
|
+
}
|