@dharta/cli 0.6.77 → 0.6.78
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 +1 -1
- package/README.md +215 -11
- package/dist/agent.js +3 -2
- package/dist/agent.js.map +1 -1
- package/dist/api-error.js +6 -6
- package/dist/api-error.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +860 -149
- package/dist/cli.js.map +1 -1
- package/dist/command-tree.d.ts +3 -0
- package/dist/command-tree.js +10 -0
- package/dist/command-tree.js.map +1 -0
- package/dist/commands/agents.d.ts +54 -17
- package/dist/commands/agents.js +246 -136
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/analytics.js +6 -5
- package/dist/commands/analytics.js.map +1 -1
- package/dist/commands/api.js +71 -86
- package/dist/commands/api.js.map +1 -1
- package/dist/commands/appearance.js +5 -6
- package/dist/commands/appearance.js.map +1 -1
- package/dist/commands/artifact.js +7 -6
- package/dist/commands/artifact.js.map +1 -1
- package/dist/commands/audit-log.js +2 -1
- package/dist/commands/audit-log.js.map +1 -1
- package/dist/commands/auth.js +26 -6
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/caps.js +11 -15
- package/dist/commands/caps.js.map +1 -1
- package/dist/commands/deploy.js +25 -10
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts +10 -1
- package/dist/commands/dev.js +56 -25
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +60 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/embed-keys.js +4 -13
- package/dist/commands/embed-keys.js.map +1 -1
- package/dist/commands/env.js +4 -7
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/files.js +3 -4
- package/dist/commands/files.js.map +1 -1
- package/dist/commands/fleet.d.ts +129 -0
- package/dist/commands/fleet.js +408 -0
- package/dist/commands/fleet.js.map +1 -0
- package/dist/commands/genui.d.ts +2 -0
- package/dist/commands/genui.js +53 -0
- package/dist/commands/genui.js.map +1 -0
- package/dist/commands/git-credential.js +2 -3
- package/dist/commands/git-credential.js.map +1 -1
- package/dist/commands/kartas.d.ts +9 -0
- package/dist/commands/kartas.js +33 -11
- package/dist/commands/kartas.js.map +1 -1
- package/dist/commands/keys.d.ts +17 -18
- package/dist/commands/keys.js +108 -19
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/login.js +2 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/members.d.ts +10 -0
- package/dist/commands/members.js +20 -6
- package/dist/commands/members.js.map +1 -1
- package/dist/commands/model-connections.d.ts +44 -0
- package/dist/commands/model-connections.js +435 -0
- package/dist/commands/model-connections.js.map +1 -0
- package/dist/commands/open.d.ts +2 -2
- package/dist/commands/open.js +4 -3
- package/dist/commands/open.js.map +1 -1
- package/dist/commands/org.d.ts +9 -0
- package/dist/commands/org.js +42 -0
- package/dist/commands/org.js.map +1 -0
- package/dist/commands/organization.d.ts +16 -0
- package/dist/commands/organization.js +118 -0
- package/dist/commands/organization.js.map +1 -0
- package/dist/commands/parity.js +1 -3
- package/dist/commands/parity.js.map +1 -1
- package/dist/commands/repos.d.ts +4 -0
- package/dist/commands/repos.js +17 -0
- package/dist/commands/repos.js.map +1 -0
- package/dist/commands/rollback.js +2 -3
- package/dist/commands/rollback.js.map +1 -1
- package/dist/commands/schedules.js +26 -21
- package/dist/commands/schedules.js.map +1 -1
- package/dist/commands/scopes.js +8 -1
- package/dist/commands/scopes.js.map +1 -1
- package/dist/commands/sessions.js +9 -3
- package/dist/commands/sessions.js.map +1 -1
- package/dist/commands/setup.js +5 -4
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/update.d.ts +1 -0
- package/dist/commands/update.js +24 -11
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/webhooks.d.ts +4 -1
- package/dist/commands/webhooks.js +21 -16
- package/dist/commands/webhooks.js.map +1 -1
- package/dist/completions.js +24 -13
- package/dist/completions.js.map +1 -1
- package/dist/config.d.ts +12 -0
- package/dist/config.js +121 -7
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +2 -0
- package/dist/context.js +23 -7
- package/dist/context.js.map +1 -1
- package/dist/docs/cli-reference.d.ts +2 -0
- package/dist/docs/cli-reference.js +191 -0
- package/dist/docs/cli-reference.js.map +1 -0
- package/dist/exit-codes.d.ts +25 -0
- package/dist/exit-codes.js +107 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/genui.d.ts +178 -0
- package/dist/genui.js +1130 -0
- package/dist/genui.js.map +1 -0
- package/dist/harnesses.js +2 -1
- package/dist/harnesses.js.map +1 -1
- package/dist/jq.d.ts +4 -0
- package/dist/jq.js +91 -0
- package/dist/jq.js.map +1 -0
- package/dist/login-offer.js +6 -2
- package/dist/login-offer.js.map +1 -1
- package/dist/manifest.d.ts +12 -0
- package/dist/manifest.js +126 -0
- package/dist/manifest.js.map +1 -1
- package/dist/model-auth.d.ts +29 -0
- package/dist/model-auth.js +117 -0
- package/dist/model-auth.js.map +1 -0
- package/dist/model-settings.d.ts +23 -0
- package/dist/model-settings.js +186 -0
- package/dist/model-settings.js.map +1 -0
- package/dist/money.js +2 -1
- package/dist/money.js.map +1 -1
- package/dist/output.d.ts +6 -0
- package/dist/output.js +54 -0
- package/dist/output.js.map +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +1 -1
- package/dist/scaffold.js +2 -1
- package/dist/scaffold.js.map +1 -1
- package/dist/validators.js +17 -11
- package/dist/validators.js.map +1 -1
- package/dist/version-check.d.ts +1 -1
- package/dist/version-check.js +1 -1
- package/dist/version-check.js.map +1 -1
- package/node_modules/@dharta/contracts/LICENSE +21 -0
- package/node_modules/@dharta/contracts/README.md +45 -0
- package/node_modules/@dharta/contracts/artifact-runtime.json +750 -0
- package/node_modules/@dharta/contracts/dist/activity.d.ts +62 -0
- package/node_modules/@dharta/contracts/dist/activity.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/activity.js +178 -0
- package/node_modules/@dharta/contracts/dist/activity.js.map +1 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime-formats.d.ts +20 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime-formats.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime-formats.js +53 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime-formats.js.map +1 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime-validators.generated.d.ts +37 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime-validators.generated.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime-validators.generated.js +5107 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime-validators.generated.js.map +1 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime.d.ts +154 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime.generated.d.ts +1670 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime.generated.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime.generated.js +1903 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime.generated.js.map +1 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime.js +377 -0
- package/node_modules/@dharta/contracts/dist/artifact-runtime.js.map +1 -0
- package/node_modules/@dharta/contracts/dist/index.d.ts +6 -0
- package/node_modules/@dharta/contracts/dist/index.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/index.js +6 -0
- package/node_modules/@dharta/contracts/dist/index.js.map +1 -0
- package/node_modules/@dharta/contracts/dist/model-auth.d.ts +31 -0
- package/node_modules/@dharta/contracts/dist/model-auth.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/model-auth.js +45 -0
- package/node_modules/@dharta/contracts/dist/model-auth.js.map +1 -0
- package/node_modules/@dharta/contracts/dist/tasks.d.ts +44 -0
- package/node_modules/@dharta/contracts/dist/tasks.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/tasks.js +127 -0
- package/node_modules/@dharta/contracts/dist/tasks.js.map +1 -0
- package/node_modules/@dharta/contracts/dist/wire-events.d.ts +71 -0
- package/node_modules/@dharta/contracts/dist/wire-events.d.ts.map +1 -0
- package/node_modules/@dharta/contracts/dist/wire-events.js +48 -0
- package/node_modules/@dharta/contracts/dist/wire-events.js.map +1 -0
- package/node_modules/@dharta/contracts/model-auth-capabilities-v1.json +168 -0
- package/node_modules/@dharta/contracts/model-auth-reasons-v1.json +38 -0
- package/node_modules/@dharta/contracts/package.json +44 -0
- package/node_modules/@dharta/contracts/src/activity.ts +215 -0
- package/node_modules/@dharta/contracts/src/artifact-runtime-formats.ts +54 -0
- package/node_modules/@dharta/contracts/src/artifact-runtime-validators.generated.ts +29 -0
- package/node_modules/@dharta/contracts/src/artifact-runtime.generated.ts +2093 -0
- package/node_modules/@dharta/contracts/src/artifact-runtime.ts +520 -0
- package/node_modules/@dharta/contracts/src/index.ts +5 -0
- package/node_modules/@dharta/contracts/src/model-auth.ts +82 -0
- package/node_modules/@dharta/contracts/src/tasks.ts +142 -0
- package/node_modules/@dharta/contracts/src/wire-events.ts +150 -0
- package/node_modules/@dharta/contracts/wire-events.json +29 -0
- package/node_modules/@dharta/sdk/LICENSE +1 -1
- package/node_modules/@dharta/sdk/README.md +22 -8
- package/node_modules/@dharta/sdk/dist/errors.d.ts +9 -7
- package/node_modules/@dharta/sdk/dist/errors.d.ts.map +1 -1
- package/node_modules/@dharta/sdk/dist/errors.js +36 -18
- package/node_modules/@dharta/sdk/dist/errors.js.map +1 -1
- package/node_modules/@dharta/sdk/dist/fleet.d.ts +69 -0
- package/node_modules/@dharta/sdk/dist/fleet.d.ts.map +1 -0
- package/node_modules/@dharta/sdk/dist/fleet.js +240 -0
- package/node_modules/@dharta/sdk/dist/fleet.js.map +1 -0
- package/node_modules/@dharta/sdk/dist/http.d.ts +6 -2
- package/node_modules/@dharta/sdk/dist/http.d.ts.map +1 -1
- package/node_modules/@dharta/sdk/dist/http.js +71 -12
- package/node_modules/@dharta/sdk/dist/http.js.map +1 -1
- package/node_modules/@dharta/sdk/dist/idempotency.d.ts +12 -0
- package/node_modules/@dharta/sdk/dist/idempotency.d.ts.map +1 -0
- package/node_modules/@dharta/sdk/dist/idempotency.js +72 -0
- package/node_modules/@dharta/sdk/dist/idempotency.js.map +1 -0
- package/node_modules/@dharta/sdk/dist/index.d.ts +20 -6
- package/node_modules/@dharta/sdk/dist/index.d.ts.map +1 -1
- package/node_modules/@dharta/sdk/dist/index.js +27 -4
- package/node_modules/@dharta/sdk/dist/index.js.map +1 -1
- package/node_modules/@dharta/sdk/dist/resources.d.ts +108 -13
- package/node_modules/@dharta/sdk/dist/resources.d.ts.map +1 -1
- package/node_modules/@dharta/sdk/dist/resources.js +403 -57
- package/node_modules/@dharta/sdk/dist/resources.js.map +1 -1
- package/node_modules/@dharta/sdk/dist/types.d.ts +436 -16
- package/node_modules/@dharta/sdk/dist/types.d.ts.map +1 -1
- package/node_modules/@dharta/sdk/dist/types.js +31 -2
- package/node_modules/@dharta/sdk/dist/types.js.map +1 -1
- package/node_modules/@dharta/sdk/package.json +9 -3
- package/node_modules/@dharta/sdk/src/errors.ts +41 -18
- package/node_modules/@dharta/sdk/src/fleet.ts +339 -0
- package/node_modules/@dharta/sdk/src/http.ts +110 -17
- package/node_modules/@dharta/sdk/src/idempotency.ts +101 -0
- package/node_modules/@dharta/sdk/src/index.ts +50 -11
- package/node_modules/@dharta/sdk/src/resources.ts +549 -68
- package/node_modules/@dharta/sdk/src/types.ts +629 -20
- package/package.json +16 -6
- package/src/agent.ts +3 -2
- package/src/api-error.ts +6 -5
- package/src/cli.ts +978 -163
- package/src/command-tree.ts +13 -0
- package/src/commands/agents.ts +365 -167
- package/src/commands/analytics.ts +6 -5
- package/src/commands/api.ts +73 -92
- package/src/commands/appearance.ts +5 -6
- package/src/commands/artifact.ts +7 -6
- package/src/commands/audit-log.ts +2 -1
- package/src/commands/auth.ts +25 -5
- package/src/commands/caps.ts +11 -15
- package/src/commands/deploy.ts +18 -4
- package/src/commands/dev.ts +86 -25
- package/src/commands/doctor.ts +69 -0
- package/src/commands/embed-keys.ts +4 -14
- package/src/commands/env.ts +4 -7
- package/src/commands/files.ts +3 -4
- package/src/commands/fleet.ts +672 -0
- package/src/commands/genui.ts +59 -0
- package/src/commands/git-credential.ts +2 -3
- package/src/commands/kartas.ts +45 -11
- package/src/commands/keys.ts +152 -35
- package/src/commands/login.ts +2 -1
- package/src/commands/members.ts +31 -6
- package/src/commands/model-connections.ts +547 -0
- package/src/commands/open.ts +5 -4
- package/src/commands/org.ts +57 -0
- package/src/commands/organization.ts +153 -0
- package/src/commands/parity.ts +1 -3
- package/src/commands/repos.ts +23 -0
- package/src/commands/rollback.ts +2 -3
- package/src/commands/schedules.ts +33 -22
- package/src/commands/scopes.ts +8 -1
- package/src/commands/sessions.ts +9 -3
- package/src/commands/setup.ts +5 -4
- package/src/commands/update.ts +28 -12
- package/src/commands/webhooks.ts +30 -19
- package/src/completions.ts +25 -13
- package/src/config.ts +141 -9
- package/src/context.ts +34 -7
- package/src/docs/cli-reference.ts +206 -0
- package/src/exit-codes.ts +122 -0
- package/src/genui.ts +1398 -0
- package/src/harnesses.ts +2 -1
- package/src/jq.ts +109 -0
- package/src/login-offer.ts +6 -2
- package/src/manifest.ts +134 -0
- package/src/model-auth.ts +173 -0
- package/src/model-settings.ts +222 -0
- package/src/money.ts +5 -1
- package/src/output.ts +60 -0
- package/src/runtime.ts +1 -1
- package/src/scaffold.ts +2 -1
- package/src/validators.ts +18 -11
- package/src/version-check.ts +1 -1
- package/dist/commands/model-keys.d.ts +0 -22
- package/dist/commands/model-keys.js +0 -222
- package/dist/commands/model-keys.js.map +0 -1
- package/src/commands/model-keys.ts +0 -278
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/** RFC 0065 semantic activity wire contract (snake_case, server -> consumer). */
|
|
2
|
+
|
|
3
|
+
export const ACTIVITY_KINDS = [
|
|
4
|
+
"read", "search", "create", "edit", "delete", "move", "command",
|
|
5
|
+
"test", "request", "artifact", "task", "other",
|
|
6
|
+
] as const;
|
|
7
|
+
|
|
8
|
+
export const ACTIVITY_STATUSES = [
|
|
9
|
+
"queued", "running", "awaiting_approval", "succeeded", "failed",
|
|
10
|
+
"denied", "cancelled", "interrupted",
|
|
11
|
+
] as const;
|
|
12
|
+
|
|
13
|
+
export const ACTIVITY_TARGET_KINDS = [
|
|
14
|
+
"file", "directory", "command", "url", "artifact", "task", "other",
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
export const ACTIVITY_DETAIL_RENDERERS = [
|
|
18
|
+
"file_diff", "command", "search_results", "request", "artifact", "json",
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
export const ACTIVITY_PRESENTATIONS = ["row", "current", "badge"] as const;
|
|
22
|
+
|
|
23
|
+
export const ACTIVITY_SOURCE_KINDS = [
|
|
24
|
+
"workspace", "web", "integration", "system", "subagent", "harness", "other",
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
export const ACTIVITY_LIMITS = {
|
|
28
|
+
idChars: 128,
|
|
29
|
+
labelChars: 240,
|
|
30
|
+
pathChars: 1024,
|
|
31
|
+
detailBytes: 32_768,
|
|
32
|
+
detailLines: 400,
|
|
33
|
+
detailItems: 200,
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
export type ActivityKindWire = (typeof ACTIVITY_KINDS)[number];
|
|
37
|
+
export type ActivityStatusWire = (typeof ACTIVITY_STATUSES)[number];
|
|
38
|
+
export type ActivityTargetKindWire = (typeof ACTIVITY_TARGET_KINDS)[number];
|
|
39
|
+
export type ActivityDetailRendererWire = (typeof ACTIVITY_DETAIL_RENDERERS)[number];
|
|
40
|
+
export type ActivityPresentationModeWire = (typeof ACTIVITY_PRESENTATIONS)[number];
|
|
41
|
+
export type ActivitySourceKindWire = (typeof ACTIVITY_SOURCE_KINDS)[number];
|
|
42
|
+
|
|
43
|
+
export interface ActivitySourceWire {
|
|
44
|
+
kind: ActivitySourceKindWire;
|
|
45
|
+
label?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ActivityTargetWire {
|
|
49
|
+
kind: ActivityTargetKindWire;
|
|
50
|
+
label: string;
|
|
51
|
+
path?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ActivityMetricsWire {
|
|
55
|
+
added_lines?: number;
|
|
56
|
+
removed_lines?: number;
|
|
57
|
+
item_count?: number;
|
|
58
|
+
exit_code?: number;
|
|
59
|
+
duration_ms?: number;
|
|
60
|
+
tool_uses?: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ActivityDetailWire {
|
|
64
|
+
renderer: ActivityDetailRendererWire;
|
|
65
|
+
payload: unknown;
|
|
66
|
+
truncated?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ActivityPresentationWire {
|
|
70
|
+
schema_version: 1;
|
|
71
|
+
activity_id: string;
|
|
72
|
+
turn_id: string;
|
|
73
|
+
task_id?: string;
|
|
74
|
+
kind: ActivityKindWire;
|
|
75
|
+
status: ActivityStatusWire;
|
|
76
|
+
target?: ActivityTargetWire;
|
|
77
|
+
metrics?: ActivityMetricsWire;
|
|
78
|
+
detail?: ActivityDetailWire;
|
|
79
|
+
started_at?: string;
|
|
80
|
+
completed_at?: string;
|
|
81
|
+
fallback_label?: string;
|
|
82
|
+
presentation?: ActivityPresentationModeWire;
|
|
83
|
+
source?: ActivitySourceWire;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const KIND_SET = new Set<string>(ACTIVITY_KINDS);
|
|
87
|
+
const STATUS_SET = new Set<string>(ACTIVITY_STATUSES);
|
|
88
|
+
const TARGET_KIND_SET = new Set<string>(ACTIVITY_TARGET_KINDS);
|
|
89
|
+
const DETAIL_RENDERER_SET = new Set<string>(ACTIVITY_DETAIL_RENDERERS);
|
|
90
|
+
const PRESENTATION_SET = new Set<string>(ACTIVITY_PRESENTATIONS);
|
|
91
|
+
const SOURCE_KIND_SET = new Set<string>(ACTIVITY_SOURCE_KINDS);
|
|
92
|
+
const METRIC_KEYS = [
|
|
93
|
+
"added_lines", "removed_lines", "item_count", "exit_code", "duration_ms", "tool_uses",
|
|
94
|
+
] as const;
|
|
95
|
+
|
|
96
|
+
/** Validate an untrusted decoded value. Invalid metadata falls back to its legacy tool event. */
|
|
97
|
+
export function parseActivityPresentationWire(value: unknown): ActivityPresentationWire | null {
|
|
98
|
+
if (!isRecord(value) || value.schema_version !== 1) return null;
|
|
99
|
+
if (!boundedString(value.activity_id, ACTIVITY_LIMITS.idChars)) return null;
|
|
100
|
+
if (!boundedString(value.turn_id, ACTIVITY_LIMITS.idChars)) return null;
|
|
101
|
+
if (!KIND_SET.has(String(value.kind)) || !STATUS_SET.has(String(value.status))) return null;
|
|
102
|
+
if (value.task_id !== undefined && !boundedString(value.task_id, ACTIVITY_LIMITS.idChars)) return null;
|
|
103
|
+
if (value.started_at !== undefined && !validTimestamp(value.started_at)) return null;
|
|
104
|
+
if (value.completed_at !== undefined && !validTimestamp(value.completed_at)) return null;
|
|
105
|
+
if (value.presentation !== undefined && !PRESENTATION_SET.has(String(value.presentation))) return null;
|
|
106
|
+
|
|
107
|
+
const kind = value.kind as ActivityKindWire;
|
|
108
|
+
if (value.fallback_label !== undefined) {
|
|
109
|
+
if (kind !== "other" || !boundedString(value.fallback_label, ACTIVITY_LIMITS.labelChars)) return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const target = parseTarget(value.target);
|
|
113
|
+
if (value.target !== undefined && target === null) return null;
|
|
114
|
+
const metrics = parseMetrics(value.metrics);
|
|
115
|
+
if (value.metrics !== undefined && metrics === null) return null;
|
|
116
|
+
const detail = parseDetail(value.detail);
|
|
117
|
+
if (value.detail !== undefined && detail === null) return null;
|
|
118
|
+
const source = parseSource(value.source);
|
|
119
|
+
if (value.source !== undefined && source === null) return null;
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
schema_version: 1,
|
|
123
|
+
activity_id: value.activity_id as string,
|
|
124
|
+
turn_id: value.turn_id as string,
|
|
125
|
+
...(value.task_id !== undefined ? { task_id: value.task_id as string } : {}),
|
|
126
|
+
kind,
|
|
127
|
+
status: value.status as ActivityStatusWire,
|
|
128
|
+
...(target ? { target } : {}),
|
|
129
|
+
...(metrics ? { metrics } : {}),
|
|
130
|
+
...(detail ? { detail } : {}),
|
|
131
|
+
...(value.started_at !== undefined ? { started_at: value.started_at as string } : {}),
|
|
132
|
+
...(value.completed_at !== undefined ? { completed_at: value.completed_at as string } : {}),
|
|
133
|
+
...(value.fallback_label !== undefined ? { fallback_label: value.fallback_label as string } : {}),
|
|
134
|
+
...(value.presentation !== undefined ? { presentation: value.presentation as ActivityPresentationModeWire } : {}),
|
|
135
|
+
...(source ? { source } : {}),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function parseSource(value: unknown): ActivitySourceWire | null {
|
|
140
|
+
if (value === undefined) return null;
|
|
141
|
+
if (!isRecord(value) || !SOURCE_KIND_SET.has(String(value.kind))) return null;
|
|
142
|
+
if (value.label !== undefined && !boundedString(value.label, ACTIVITY_LIMITS.labelChars)) return null;
|
|
143
|
+
return {
|
|
144
|
+
kind: value.kind as ActivitySourceKindWire,
|
|
145
|
+
...(value.label !== undefined ? { label: value.label as string } : {}),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function parseTarget(value: unknown): ActivityTargetWire | null {
|
|
150
|
+
if (value === undefined) return null;
|
|
151
|
+
if (!isRecord(value) || !TARGET_KIND_SET.has(String(value.kind))) return null;
|
|
152
|
+
if (!boundedString(value.label, ACTIVITY_LIMITS.labelChars)) return null;
|
|
153
|
+
if (value.path !== undefined) {
|
|
154
|
+
if (!boundedString(value.path, ACTIVITY_LIMITS.pathChars) || !safeRelativePath(value.path)) return null;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
kind: value.kind as ActivityTargetKindWire,
|
|
158
|
+
label: value.label as string,
|
|
159
|
+
...(value.path !== undefined ? { path: value.path as string } : {}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function parseMetrics(value: unknown): ActivityMetricsWire | null {
|
|
164
|
+
if (value === undefined) return null;
|
|
165
|
+
if (!isRecord(value)) return null;
|
|
166
|
+
const metrics: Record<string, number> = {};
|
|
167
|
+
for (const key of METRIC_KEYS) {
|
|
168
|
+
const metric = value[key];
|
|
169
|
+
if (metric === undefined) continue;
|
|
170
|
+
if (!Number.isSafeInteger(metric)) return null;
|
|
171
|
+
if (key !== "exit_code" && (metric as number) < 0) return null;
|
|
172
|
+
metrics[key] = metric as number;
|
|
173
|
+
}
|
|
174
|
+
return metrics as ActivityMetricsWire;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function parseDetail(value: unknown): ActivityDetailWire | null {
|
|
178
|
+
if (value === undefined) return null;
|
|
179
|
+
if (!isRecord(value) || !DETAIL_RENDERER_SET.has(String(value.renderer))) return null;
|
|
180
|
+
if (!("payload" in value)) return null;
|
|
181
|
+
if (value.truncated !== undefined && typeof value.truncated !== "boolean") return null;
|
|
182
|
+
if (jsonByteLength(value.payload) > ACTIVITY_LIMITS.detailBytes) return null;
|
|
183
|
+
return {
|
|
184
|
+
renderer: value.renderer as ActivityDetailRendererWire,
|
|
185
|
+
payload: value.payload,
|
|
186
|
+
...(value.truncated !== undefined ? { truncated: value.truncated } : {}),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function safeRelativePath(value: string): boolean {
|
|
191
|
+
if (value.startsWith("/") || value.includes("\\")) return false;
|
|
192
|
+
if (/^[A-Za-z]:[\\/]/.test(value)) return false;
|
|
193
|
+
return !value.split("/").some((part) => part === "" || part === "." || part === "..");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function jsonByteLength(value: unknown): number {
|
|
197
|
+
try {
|
|
198
|
+
const encoded = JSON.stringify(value);
|
|
199
|
+
return encoded === undefined ? 0 : new TextEncoder().encode(encoded).byteLength;
|
|
200
|
+
} catch {
|
|
201
|
+
return Number.POSITIVE_INFINITY;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function validTimestamp(value: unknown): value is string {
|
|
206
|
+
return boundedString(value, 64) && Number.isFinite(Date.parse(value));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function boundedString(value: unknown, max: number): value is string {
|
|
210
|
+
return typeof value === "string" && value.length > 0 && value.length <= max;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
214
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
215
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Format validators for the Artifact runtime wire schemas.
|
|
2
|
+
//
|
|
3
|
+
// Ajv deliberately ships without format implementations. Keep these tiny
|
|
4
|
+
// validators local so the canonical runtime package enforces the same formats
|
|
5
|
+
// promised by its published JSON Schema without pulling browser-hostile
|
|
6
|
+
// transitive code into every widget bundle.
|
|
7
|
+
//
|
|
8
|
+
// They live in their own module because the standalone-compiled validators
|
|
9
|
+
// (artifact-runtime-validators.generated.ts) import `wireFormats` by name;
|
|
10
|
+
// the shape registered with Ajv at codegen time and the shape exported here
|
|
11
|
+
// must stay identical.
|
|
12
|
+
|
|
13
|
+
export const RFC3339_DATE_TIME = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T([01]\d|2[0-3]):([0-5]\d):([0-5]\d|60)(?:\.(\d+))?(Z|([+-])([01]\d|2[0-3]):([0-5]\d))$/;
|
|
14
|
+
|
|
15
|
+
export function isRfc3339DateTime(value: string): boolean {
|
|
16
|
+
const fields = RFC3339_DATE_TIME.exec(value);
|
|
17
|
+
if (!fields) return false;
|
|
18
|
+
const year = Number(fields[1]);
|
|
19
|
+
const month = Number(fields[2]);
|
|
20
|
+
const day = Number(fields[3]);
|
|
21
|
+
const hour = Number(fields[4]);
|
|
22
|
+
const minute = Number(fields[5]);
|
|
23
|
+
const second = Number(fields[6]);
|
|
24
|
+
if (day > daysInMonth(year, month)) return false;
|
|
25
|
+
// Dharta emitters never produce leap seconds. Rejecting `60` is deterministic
|
|
26
|
+
// across offsets and runtimes; accepting it correctly would require a
|
|
27
|
+
// maintained UTC leap-second table rather than local-clock heuristics.
|
|
28
|
+
return second !== 60 && hour <= 23 && minute <= 59;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function daysInMonth(year: number, month: number): number {
|
|
32
|
+
if (month === 2) {
|
|
33
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28;
|
|
34
|
+
}
|
|
35
|
+
return [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isAbsoluteUri(value: string): boolean {
|
|
39
|
+
try {
|
|
40
|
+
return new URL(value).toString().length > 0;
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The format table the standalone-compiled validators reference. Must match
|
|
48
|
+
* the definitions registered with Ajv in generate-artifact-runtime-bindings.mjs
|
|
49
|
+
* (same names, same `{ type, validate }` shape).
|
|
50
|
+
*/
|
|
51
|
+
export const wireFormats = {
|
|
52
|
+
"date-time": { type: "string", validate: isRfc3339DateTime },
|
|
53
|
+
uri: { type: "string", validate: isAbsoluteUri },
|
|
54
|
+
} as const;
|