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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
/**
 * Host-owned shape of an extension-authored setup experience.
 *
 * A catalog entry is declarative data published by `@openhands/extensions`. Its
 * optional `setup` block says what to ask a user for; everything derivable from
 * that — the request to send, the route, the review screen, the analytics — is
 * this host's to generate, so none of it appears here.
 *
 * The names mirror `@openhands/extensions/automations`' own declarations, so an
 * entry from the published package assigns without an adapter.
 */

export const SETUP_VERSION = "1.0";

export type SetupMode = "direct" | "assisted";

export type SetupFieldType =
  | "text"
  | "textarea"
  | "select"
  | "number"
  | "cron"
  | "timezone"
  | "repo-picker"
  | "llm-profile"
  | "event-source"
  | "event-type"
  | "plugin-sources"
  | "tarball-upload";

export type SetupGitProvider = "github" | "gitlab" | "bitbucket";

export type SetupTriggerKind = "cron" | "event";

/** Placeholder namespaces a setup block may reference inside `{{...}}`. */
export const SETUP_PLACEHOLDER_NAMESPACES = ["form", "automation"] as const;

export interface SetupFieldOption {
  value: string;
  label: string;
}

export interface SetupFieldConstraints {
  minLength?: number;
  maxLength?: number;
  min?: number;
  max?: number;
  /**
   * A host-implemented check named from a closed set. Entries supply no regex
   * of their own, so they cannot hand the host a pathological pattern.
   */
  format?: "safeExpressionLiteral";
}

export interface SetupFormField {
  type: SetupFieldType;
  label: string;
  help: string;
  placeholder?: string;
  default?: string | number | boolean | null;
  required: boolean;
  provider?: SetupGitProvider;
  /**
   * repo-picker only. The field collects several repositories rather than one,
   * and its value is a list. A placeholder that is the whole value resolves to
   * that list, so a payload can state one and get an array.
   */
  multiple?: true;
  options?: SetupFieldOption[];
  constraints?: SetupFieldConstraints;
}

/** Keyed by field name, which is what `{{form.<name>}}` resolves against. */
export type SetupFormFields = Record<string, SetupFormField>;

export interface SetupForm {
  note?: string;
  /** Inputs that decide when the automation runs, keyed by trigger kind. Multiple keys are selectable variants. */
  triggers?: Partial<Record<SetupTriggerKind, SetupFormFields>>;
  /** Every other input: the arguments to the automation itself. */
  args: SetupFormFields;
}

/** A config.json leaf: templated string, number, boolean, null, or a nesting. */
export type SetupBundleConfigValue =
  | string
  | number
  | boolean
  | null
  | SetupBundleConfigValue[]
  | { [key: string]: SetupBundleConfigValue };

/**
 * The name the rendered configuration is packed under, which is therefore a
 * name a bundle's own files may not claim. Stated here rather than beside the
 * packing, so admission can refuse the collision without importing it.
 */
export const BUNDLE_CONFIG_FILENAME = "config.json";

/**
 * The script tarball a direct entry may ship instead of a prompt, for an
 * automation that is deterministic machinery rather than judgement.
 *
 * `files` maps a path inside the archive to the repository path the extensions
 * package read it from; the contents themselves come from that package's
 * `getAutomationBundleFiles`, because this host has the package and not the
 * repository.
 */
export interface SetupBundle {
  /** Provenance recorded on the created automation, alongside the entry id. */
  version: string;
  /** The command the service runs inside the extracted tarball. */
  entrypoint: string;
  /** Script run once before the entrypoint. Absent when nothing to install. */
  setupScript?: string;
  /** Seconds a run may take, when the service default is not enough. */
  timeout?: number;
  files: Record<string, string>;
  /** Rendered from the form and packed as config.json. */
  config: Record<string, SetupBundleConfigValue>;
}

export type SetupActionKind = "prompt" | "plugin" | "upload";

export interface SetupPromptAction {
  label: string;
  help: string;
  features: string[];
  args: SetupFormFields;
  prompt: string;
}

export interface SetupPluginAction {
  label: string;
  help: string;
  features: string[];
  args: SetupFormFields;
  prompt: string;
  plugins: string;
}

export interface SetupUploadAction {
  label: string;
  help: string;
  features: string[];
  args: SetupFormFields;
  tarballPath: string;
  entrypoint: string;
  setupScript?: string;
}

export interface SetupActions {
  prompt?: SetupPromptAction;
  plugin?: SetupPluginAction;
  upload?: SetupUploadAction;
}

export type SetupAction =
  | SetupPromptAction
  | SetupPluginAction
  | SetupUploadAction;

export interface SetupBlock {
  version: typeof SETUP_VERSION;
  mode: SetupMode;
  form: SetupForm;
  /** direct only. What the automation is told to do. */
  prompt?: string;
  /** direct only, and the alternative to `prompt`. Exactly one is present. */
  bundle?: SetupBundle;
  /** direct only, and the alternative to `prompt` or `bundle`. */
  actions?: SetupActions;
  /** direct only, event trigger only. Which delivered events belong to it. */
  filter?: string;
  /**
   * Setup context for the conversation that finishes setup. Required for
   * assisted mode. Optional for direct mode, where it seeds the fallback
   * conversation offered when the deployment cannot run the direct path.
   */
  message?: string;
}

export interface SetupIntegrationRequirement {
  /** Why this entry needs the integration. */
  message: string;
  /** Defaults to true. `false` lets setup continue while it is unconnected. */
  required?: false;
}

export interface SetupPrerequisites {
  /** Keyed by integration catalog id. */
  integrations: Record<string, SetupIntegrationRequirement>;
  /** Deployment capabilities this entry cannot run without. */
  features?: string[];
}

/**
 * The part of a catalog entry this host reads. An admitted entry always has a
 * `setup` block; entries without one are simply not setup entries.
 */
export interface SetupEntry {
  id: string;
  name: string;
  description: string;
  /**
   * Version of the template this entry publishes, sent with the create request
   * as provenance. A bundle declares its own at `setup.bundle.version`; a
   * prompt entry declares it here. Absent means the entry sends none, so the
   * service records no template for what it creates.
   */
  version?: string;
  requires: SetupPrerequisites;
  /** The skill that owns the launch command. Defaults to `id`. */
  skill?: string;
  setup: SetupBlock;
}

export type SetupPayloadValue =
  | string
  | number
  | boolean
  | null
  | SetupPayloadValue[]
  | { [key: string]: SetupPayloadValue };

export interface SetupRequestBody {
  [key: string]: SetupPayloadValue;
}

/**
 * Form values as collected; the payload mapping shapes them.
 *
 * A field collecting several values holds a list. Everything else holds a
 * string, including fields whose value is a number to the service - the
 * payload mapping is where a value stops being what was typed.
 */
export type SetupFormValue = string | number | boolean | null | string[] | File;
export type SetupFormValues = Record<string, SetupFormValue>;

/** `GET /v1/capabilities` — what this deployment supports. */
export interface DeploymentCapabilities {
  ready: boolean;
  /** Absolute timeout ceiling enforced by this deployment's automation API. */
  maxAutomationTimeoutSeconds?: number;
  triggerKinds: string[];
  eventSources: string[];
  eventTypes: string[];
  triggers: {
    cron?: { minIntervalSeconds: number; timezones: string[] };
    event?: { filterLanguage: string; filterFunctions: string[] };
  };
  features: string[];
}

/** A single problem with a draft, addressed to the field that caused it. */
export interface DraftValidationError {
  /** Dotted path into the draft. Null when the problem spans the whole draft. */
  field: string | null;
  code: string;
  message: string;
}

/** `POST /v1/validate` — an invalid draft is still a 200. */
export interface ValidateDraftResponse {
  valid: boolean;
  errors: DraftValidationError[];
  sampleEventMatched?: boolean | null;
}

/**
 * Host-owned shape of the production Automation interface manifest, published
 * by `@openhands/extensions/automations` as `AUTOMATION_INTERFACE`.
 *
 * The catalog states what varies per automation; this states the domain-level
 * facts of the interface itself. As with setup entries, the published data is
 * validated at admission rather than trusted, and a package that predates the
 * manifest simply leaves the host on its own defaults.
 */

export const INTERFACE_VERSION = "1.0";

/** The closed set of runtime-model properties a client may offer for setting. */
export type AutomationAttributeName =
  | "name"
  | "prompt"
  | "model"
  | "timeout"
  | "schedule";

export type InterfaceAttributeType =
  | "text"
  | "textarea"
  | "number"
  | "llm-profile"
  | "schedule";

/** How one settable attribute of an existing Automation is offered. */
export interface InterfaceAttribute {
  type: InterfaceAttributeType;
  label: string;
  help?: string;
  required: boolean;
  /** Only a `number` attribute carries constraints. */
  constraints?: { min?: number; max?: number };
}

export interface InterfaceRoutes {
  list: string;
  /** Carries the `:automationId` segment the host substitutes. */
  setup: string;
  /** Carries the `:automationId` segment the host substitutes. */
  detail: string;
  /** The templates sub-page. Static: there is no parameter to substitute. */
  templates?: string;
}

/**
 * Service-relative paths the host calls. The base path, methods, headers, and
 * auth remain the host's. `{id}` marks where the automation id is substituted.
 */
export interface InterfaceEndpoints {
  list: string;
  detail: string;
  dispatch: string;
  runs: string;
  tarball: string;
  health: string;
  capabilities: string;
  validate: string;
  createPrompt: string;
  createPlugin: string;
  /**
   * The raw create endpoint, which a bundle entry is created through, and
   * where its tarball is uploaded first. Optional: a manifest published before
   * bundles existed declares neither, and is still admitted.
   */
  createBundle?: string;
  uploads?: string;
}

export type InterfaceEndpointName = keyof InterfaceEndpoints;

export interface InterfaceImportExport {
  fileKind: string;
  fileVersion: number;
  filenameSuffix: string;
  importDefaults: {
    /** Provider inferred for short owner/repo repository URLs on import. */
    repoProvider: SetupGitProvider;
    /** Event source of the placeholder trigger that keeps an import inert. */
    placeholderEventSource: string;
  };
}

/**
 * The sub-page surface: navigation, overview tiles, filters, sort, and run
 * insights for the list page, and a templates page. Every value below names
 * something this host implements from a closed set — a metric it computes, a
 * predicate it applies, a comparator it runs, an icon it ships — and the
 * manifest picks and captions it, never defines it. The host carries no
 * definitions of its own for this surface, so a manifest without it simply
 * leaves the sub-pages unrendered.
 */

export const INTERFACE_SUB_PAGE_IDS = ["list", "templates"] as const;

export type InterfaceSubPageId = (typeof INTERFACE_SUB_PAGE_IDS)[number];

/** Icon names this host maps to artwork. A manifest cannot supply its own. */
export const INTERFACE_ICON_SLUGS = [
  "layout-dashboard",
  "sparkles",
  "library",
  "bot",
  "circle-alert",
  "activity",
  "timer",
] as const;

export type InterfaceIconSlug = (typeof INTERFACE_ICON_SLUGS)[number];

export interface InterfaceSubPageNavItem {
  /** The `pages` entry this item navigates to; its route comes from `routes`. */
  page: InterfaceSubPageId;
  label: string;
  icon: InterfaceIconSlug;
}

/** Values this host computes over the loaded automations and their runs. */
export const OVERVIEW_METRICS = [
  "automations",
  "needs-attention",
  "total-runs",
  "average-duration",
] as const;

export type OverviewMetric = (typeof OVERVIEW_METRICS)[number];

/**
 * Placeholder names a tile's `detail`/`zeroDetail` copy may reference inside
 * `{{...}}`, per metric. Plain substitution, like setup copy.
 */
export const OVERVIEW_TILE_PLACEHOLDERS: Record<
  OverviewMetric,
  readonly string[]
> = {
  automations: ["active"],
  "needs-attention": [],
  "total-runs": [],
  "average-duration": [],
};

export interface InterfaceOverviewTile {
  metric: OverviewMetric;
  label: string;
  /** Caption under the value. */
  detail: string;
  /** Replaces `detail` while the metric's value is zero. */
  zeroDetail?: string;
  icon: InterfaceIconSlug;
}

export interface InterfaceOverview {
  /** Names the tiles section for assistive technology. */
  label: string;
  tiles: InterfaceOverviewTile[];
}

/** Filter values name predicates this host implements, per filter id. */
export const DASHBOARD_FILTER_VALUES = {
  status: ["all", "active", "failing", "disabled"],
  trigger: ["all", "schedule", "event"],
} as const;

export type DashboardFilterId = keyof typeof DASHBOARD_FILTER_VALUES;

export const DASHBOARD_FILTER_IDS = Object.keys(
  DASHBOARD_FILTER_VALUES,
) as readonly DashboardFilterId[];

export type DashboardStatusValue =
  (typeof DASHBOARD_FILTER_VALUES.status)[number];

export type DashboardTriggerValue =
  (typeof DASHBOARD_FILTER_VALUES.trigger)[number];

export interface InterfaceStatusFilter {
  id: "status";
  /** The control's accessible name. */
  label: string;
  options: { value: DashboardStatusValue; label: string }[];
}

export interface InterfaceTriggerFilter {
  id: "trigger";
  /** The control's accessible name. */
  label: string;
  options: { value: DashboardTriggerValue; label: string }[];
}

export type InterfaceDashboardFilter =
  | InterfaceStatusFilter
  | InterfaceTriggerFilter;

/** Sort values name comparators this host implements. */
export const DASHBOARD_SORT_VALUES = ["last-run", "runs", "name"] as const;

export type DashboardSortValue = (typeof DASHBOARD_SORT_VALUES)[number];

export interface InterfaceDashboardSort {
  /** The control's accessible name. */
  label: string;
  options: { value: DashboardSortValue; label: string }[];
  /** One of the declared option values. */
  default: DashboardSortValue;
}

/**
 * Copy for the per-automation run insights on cards and rows. The states,
 * precedence, sampling, and value formatting are this host's; the manifest
 * names them.
 */
export interface InterfaceListInsights {
  health: {
    healthy: string;
    failing: string;
    running: string;
    disabled: string;
    neverRun: string;
    checking: string;
  };
  lastRun: { label: string; never: string; justNow: string };
  stats: { runs: string; recentSuccess: string; averageDuration: string };
}

/**
 * The templates sub-page identity. Its body — the catalog cards and their
 * launch behavior — is this host's existing catalog surface.
 */
export interface InterfaceTemplatesPage {
  title: string;
  description: string;
}

export interface InterfaceManifest {
  version: typeof INTERFACE_VERSION;
  routes: InterfaceRoutes;
  navigation: {
    sidebar: { label: string };
    commandMenu: { title: string; description: string; keywords: string };
    /** The ordered sub-page navigation of the interface. */
    subPages?: InterfaceSubPageNavItem[];
  };
  pages: {
    list: {
      title: string;
      subtitle: string;
      overview?: InterfaceOverview;
      /** The filter dropdowns of the list page, in render order. */
      filters?: InterfaceDashboardFilter[];
      sort?: InterfaceDashboardSort;
      insights?: InterfaceListInsights;
    };
    detail: { backLabel: string };
    edit: { title: string };
    templates?: InterfaceTemplatesPage;
  };
  docsUrl: string;
  /**
   * The input surface of an existing Automation, keyed by the runtime-model
   * property the host sends. Rendering it as an edit dialog is this host's
   * choice, not stated here.
   */
  attributes: Partial<Record<AutomationAttributeName, InterfaceAttribute>>;
  importExport: InterfaceImportExport;
  endpoints: InterfaceEndpoints;
  featuredAutomationIds: string[];
  responderIntegrationIds: string[];
}