@aion0/forge 0.9.16 → 0.9.18

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/RELEASE_NOTES.md CHANGED
@@ -1,14 +1,22 @@
1
- # Forge v0.9.16
1
+ # Forge v0.9.18
2
2
 
3
3
  Released: 2026-05-28
4
4
 
5
- ## Changes since v0.9.15
6
-
7
- ### Bug Fixes
8
- - fix: convert all @/ aliases in lib/ and src/ to relative paths
5
+ ## Changes since v0.9.16
9
6
 
10
7
  ### Other
11
- - fix(chat): replace @/src/* aliases with relative paths in lib/
8
+ - feat(chat): trigger_pipeline accepts skills array
9
+ - feat(connectors): body_form_inject_from + nested instances UI
10
+ - fix(http-protocol): JSON.parse args[X] when LLM stringified it + template inject keys
11
+ - feat(connectors): http body_form_inject for server-side credential injection
12
+ - Revert "feat(connectors): {secret:...} refs for cross-connector + global secrets"
13
+ - Revert "fix(chat): make secret-refs system prompt push the tool-call path"
14
+ - fix(chat): make secret-refs system prompt push the tool-call path
15
+ - revert: drop migrateConnectorInstanceSecrets startup hook
16
+ - fix(connectors): encrypt nested secrets inside type:instances rows
17
+ - feat(connectors): {secret:...} refs for cross-connector + global secrets
18
+ - feat(connectors): generic 'type: instances' field renderer + v0.9.17
19
+ - feat(connectors): generic auth + url_encoding + body_form + multi-instance
12
20
 
13
21
 
14
- **Full Changelog**: https://github.com/aiwatching/forge/compare/v0.9.15...v0.9.16
22
+ **Full Changelog**: https://github.com/aiwatching/forge/compare/v0.9.16...v0.9.18
@@ -41,17 +41,76 @@ function defaultsFor(id: string): Record<string, any> {
41
41
 
42
42
  const SECRET_MASK = '••••••••';
43
43
 
44
- function isSecretField(schema: ConnectorFieldSchema | undefined): boolean {
45
- if (!schema) return false;
46
- return schema.type === 'secret' || (schema.type as string) === 'password';
44
+ /**
45
+ * Walk `value` against `schema`, applying `mask` (plaintext → ••••) or
46
+ * `restore` (•••• stored plaintext). Recurses into `type: 'instances'`
47
+ * arrays so per-row sub-secrets get the same mask treatment as flat
48
+ * top-level secrets. Mirrors the encrypt/decrypt walker in
49
+ * lib/connectors/registry.ts so the on-disk and over-the-wire
50
+ * representations stay symmetric.
51
+ */
52
+ function transformFieldSecrets(
53
+ value: any,
54
+ schema: ConnectorFieldSchema | undefined,
55
+ existingValue: any,
56
+ op: 'mask' | 'restore',
57
+ ): any {
58
+ if (!schema) return value;
59
+ const t = String((schema as any)?.type || '');
60
+
61
+ if (t === 'secret' || t === 'password') {
62
+ if (op === 'mask') {
63
+ return typeof value === 'string' && value ? SECRET_MASK : value;
64
+ }
65
+ // restore
66
+ if (value === SECRET_MASK) {
67
+ return typeof existingValue === 'string' ? existingValue : undefined;
68
+ }
69
+ return value;
70
+ }
71
+
72
+ if (t === 'instances' && (schema as any).fields) {
73
+ const wasString = typeof value === 'string';
74
+ let rows: any;
75
+ if (wasString) {
76
+ try { rows = JSON.parse(value); } catch { return value; }
77
+ } else {
78
+ rows = value;
79
+ }
80
+ if (!Array.isArray(rows)) return value;
81
+
82
+ // Build name→row map of the existing stored value so per-instance
83
+ // mask restoration can find the corresponding row by name.
84
+ let existingRows: any[] = [];
85
+ if (typeof existingValue === 'string') {
86
+ try { existingRows = JSON.parse(existingValue); } catch { existingRows = []; }
87
+ } else if (Array.isArray(existingValue)) {
88
+ existingRows = existingValue;
89
+ }
90
+ const existingByName = new Map<string, any>();
91
+ for (const r of existingRows) {
92
+ if (r && typeof r === 'object' && typeof r.name === 'string') existingByName.set(r.name, r);
93
+ }
94
+
95
+ const transformed = rows.map((row: any) => {
96
+ if (!row || typeof row !== 'object') return row;
97
+ const existingRow = (typeof row.name === 'string' && existingByName.get(row.name)) || {};
98
+ const out: any = { ...row };
99
+ for (const [k, sub] of Object.entries((schema as any).fields)) {
100
+ out[k] = transformFieldSecrets(out[k], sub as ConnectorFieldSchema, existingRow[k], op);
101
+ }
102
+ return out;
103
+ });
104
+ return wasString ? JSON.stringify(transformed) : transformed;
105
+ }
106
+
107
+ return value;
47
108
  }
48
109
 
49
110
  function maskSecrets(settings: Record<string, any>, schema: Record<string, ConnectorFieldSchema>): Record<string, any> {
50
111
  const out: Record<string, any> = { ...settings };
51
112
  for (const [k, v] of Object.entries(schema)) {
52
- if (isSecretField(v) && typeof out[k] === 'string' && out[k]) {
53
- out[k] = SECRET_MASK;
54
- }
113
+ out[k] = transformFieldSecrets(out[k], v, undefined, 'mask');
55
114
  }
56
115
  return out;
57
116
  }
@@ -63,10 +122,9 @@ function restoreSecrets(
63
122
  ): Record<string, any> {
64
123
  const out: Record<string, any> = { ...incoming };
65
124
  for (const [k, v] of Object.entries(schema)) {
66
- if (isSecretField(v) && out[k] === SECRET_MASK) {
67
- if (typeof existing[k] === 'string') out[k] = existing[k];
68
- else delete out[k];
69
- }
125
+ const restored = transformFieldSecrets(out[k], v, existing[k], 'restore');
126
+ if (restored === undefined) delete out[k];
127
+ else out[k] = restored;
70
128
  }
71
129
  return out;
72
130
  }
@@ -34,6 +34,7 @@ import {
34
34
  } from '@/lib/connectors/registry';
35
35
  import { expandSettingsTokens, expandAllTokens } from '@/lib/plugins/templates';
36
36
  import { bridgeRpc } from '@/lib/chat/bridge-client';
37
+ import { applyAuth } from '@/lib/chat/protocols/http';
37
38
  import type { ConnectorDefinition, ConnectorTest, HttpRequestSpec } from '@/lib/connectors/types';
38
39
 
39
40
  const DEFAULT_TIMEOUT_MS = 15_000;
@@ -106,17 +107,39 @@ interface TestResult {
106
107
  body_preview?: string;
107
108
  }
108
109
 
109
- async function runHttpProbe(test: ConnectorTest, settings: Record<string, unknown>): Promise<TestResult> {
110
+ async function runHttpProbe(test: ConnectorTest, settings: Record<string, unknown>, def: ConnectorDefinition): Promise<TestResult> {
110
111
  const spec = test.request;
111
112
  if (!spec?.url) return { ok: false, error: 'test.request.url is required for http probe' };
112
113
 
114
+ // Multi-instance overlay: test probe always uses the first instance
115
+ // (same guard as tool-dispatcher — only kicks in when instances is a
116
+ // well-formed array, so single-instance connectors are unaffected).
117
+ let effectiveSettings = settings as Record<string, any>;
118
+ let instances = effectiveSettings?.instances;
119
+ // type: json fields persist as strings — parse before checking.
120
+ if (typeof instances === 'string') {
121
+ try { instances = JSON.parse(instances); } catch { instances = null; }
122
+ }
123
+ if (
124
+ Array.isArray(instances) &&
125
+ instances.length > 0 &&
126
+ instances.every((i: any) => i && typeof i === 'object' && typeof i.name === 'string')
127
+ ) {
128
+ effectiveSettings = { ...effectiveSettings, ...instances[0] };
129
+ }
130
+
113
131
  const method = (spec.method || 'GET').toUpperCase();
114
- const url = buildUrl(spec, settings);
115
- const headers = buildHeaders(spec, settings);
116
- const { body, contentType } = buildBody(spec, settings);
132
+ let url = buildUrl(spec, effectiveSettings);
133
+ const headers = buildHeaders(spec, effectiveSettings);
134
+ const { body, contentType } = buildBody(spec, effectiveSettings);
117
135
  if (body != null && contentType && !headers.has('content-type')) {
118
136
  headers.set('content-type', contentType);
119
137
  }
138
+ // Apply connector-level auth so the test probe uses the same scheme
139
+ // as live tool calls (e.g. Basic auth for Jenkins). Manifests that
140
+ // hand-craft Authorization in test.request.headers still work — the
141
+ // auth scheme would just overwrite the header.
142
+ url = applyAuth(url, headers, def.auth, effectiveSettings);
120
143
 
121
144
  const timeoutMs = test.timeout_ms || DEFAULT_TIMEOUT_MS;
122
145
  const okStatus = test.ok_status?.length ? test.ok_status : [200];
@@ -255,6 +278,6 @@ export async function POST(req: Request, { params }: { params: Promise<{ id: str
255
278
  const probe = def.test.probe || 'http';
256
279
  const r = probe === 'browser'
257
280
  ? await runBrowserProbe(def, inst.config)
258
- : await runHttpProbe(def.test, inst.config);
281
+ : await runHttpProbe(def.test, inst.config, def);
259
282
  return NextResponse.json(r);
260
283
  }
@@ -44,6 +44,8 @@ interface FieldSchema {
44
44
  required?: boolean;
45
45
  default?: any;
46
46
  options?: string[];
47
+ /** For type: 'instances' — schema of each row's inner fields. */
48
+ fields?: Record<string, FieldSchema>;
47
49
  }
48
50
 
49
51
  interface ConnectorTool {
@@ -532,7 +534,13 @@ export default function ConnectorsPanel() {
532
534
  <label className="text-[10px] text-[var(--text-secondary)] block mb-0.5">
533
535
  {sc.label || key} {sc.required && <span className="text-red-400">*</span>}
534
536
  </label>
535
- {sc.type === 'boolean' ? (
537
+ {sc.type === 'instances' ? (
538
+ <InstancesField
539
+ schema={sc}
540
+ rawValue={values[key]}
541
+ onChange={(v) => setValues({ ...values, [key]: v })}
542
+ />
543
+ ) : sc.type === 'boolean' ? (
536
544
  <input
537
545
  type="checkbox"
538
546
  checked={values[key] === true || values[key] === 'true'}
@@ -634,3 +642,135 @@ export default function ConnectorsPanel() {
634
642
  </div>
635
643
  );
636
644
  }
645
+
646
+ /**
647
+ * Generic renderer for `type: instances` — a list of named records
648
+ * configured per-connector (Jenkins instances, GitLab tenants, etc.).
649
+ * Each row collapses into the connector's declared sub-fields. Value
650
+ * is round-tripped as a JSON-stringified array so the existing
651
+ * connector-configs.json shape (the textarea-saved string) keeps
652
+ * working unchanged.
653
+ */
654
+ function InstancesField({
655
+ schema,
656
+ rawValue,
657
+ onChange,
658
+ }: {
659
+ schema: FieldSchema;
660
+ rawValue: any;
661
+ onChange: (next: string) => void;
662
+ }) {
663
+ const subFields = schema.fields || {};
664
+ const subKeys = Object.keys(subFields);
665
+
666
+ // Parse incoming value: accept stored JSON string, in-memory array,
667
+ // null, or anything malformed (treat as empty).
668
+ const rows: Record<string, any>[] = (() => {
669
+ let v: any = rawValue;
670
+ if (v == null || v === '') return [];
671
+ if (typeof v === 'string') {
672
+ try { v = JSON.parse(v); } catch { return []; }
673
+ }
674
+ return Array.isArray(v) ? v : [];
675
+ })();
676
+
677
+ const commit = (next: Record<string, any>[]) => onChange(JSON.stringify(next));
678
+
679
+ const addRow = () => {
680
+ const blank: Record<string, any> = {};
681
+ for (const k of subKeys) blank[k] = subFields[k]?.default ?? '';
682
+ commit([...rows, blank]);
683
+ };
684
+ const removeRow = (i: number) => commit(rows.filter((_, idx) => idx !== i));
685
+ const updateRow = (i: number, key: string, val: any) => {
686
+ const next = rows.map((r, idx) => (idx === i ? { ...r, [key]: val } : r));
687
+ commit(next);
688
+ };
689
+
690
+ return (
691
+ <div className="space-y-1.5">
692
+ {rows.length === 0 && (
693
+ <div className="text-[10px] text-[var(--text-secondary)] italic py-1">
694
+ No entries yet — click “+ Add” to create one.
695
+ </div>
696
+ )}
697
+ {rows.map((row, i) => {
698
+ const rowLabel =
699
+ (typeof row.name === 'string' && row.name.trim()) || `(unnamed #${i + 1})`;
700
+ return (
701
+ <div
702
+ key={i}
703
+ className="border border-[var(--border)] rounded p-2 bg-[var(--bg-secondary)]"
704
+ >
705
+ <div className="flex items-center justify-between mb-1.5">
706
+ <span className="text-[10px] font-semibold text-[var(--text-primary)]">
707
+ {rowLabel}
708
+ </span>
709
+ <button
710
+ type="button"
711
+ onClick={() => removeRow(i)}
712
+ title="Remove this entry"
713
+ className="text-[10px] text-red-400 hover:text-red-300"
714
+ >
715
+
716
+ </button>
717
+ </div>
718
+ <div className="space-y-1.5">
719
+ {subKeys.map((k) => {
720
+ const f = subFields[k];
721
+ // Nested instances — render the same component recursively.
722
+ // Lets a connector model "rows of rows" (e.g. Jenkins
723
+ // instances each with a list of inject_params key/value
724
+ // pairs).
725
+ if (f.type === 'instances') {
726
+ return (
727
+ <div key={k}>
728
+ <label className="text-[9px] text-[var(--text-secondary)] block mb-0.5">
729
+ {f.label || k} {f.required && <span className="text-red-400">*</span>}
730
+ </label>
731
+ <InstancesField
732
+ schema={f}
733
+ rawValue={row[k]}
734
+ onChange={(next) => updateRow(i, k, next)}
735
+ />
736
+ {f.description && (
737
+ <p className="text-[9px] text-[var(--text-secondary)] mt-0.5">{f.description}</p>
738
+ )}
739
+ </div>
740
+ );
741
+ }
742
+ const inputType =
743
+ f.type === 'secret' || f.type === 'password'
744
+ ? 'password'
745
+ : f.type === 'number'
746
+ ? 'number'
747
+ : 'text';
748
+ return (
749
+ <div key={k}>
750
+ <label className="text-[9px] text-[var(--text-secondary)] block mb-0.5">
751
+ {f.label || k} {f.required && <span className="text-red-400">*</span>}
752
+ </label>
753
+ <input
754
+ type={inputType}
755
+ value={row[k] ?? ''}
756
+ onChange={(e) => updateRow(i, k, e.target.value)}
757
+ placeholder={f.description || ''}
758
+ className="w-full bg-[var(--bg-tertiary)] border border-[var(--border)] rounded px-2 py-1 text-[10px] text-[var(--text-primary)] font-mono"
759
+ />
760
+ </div>
761
+ );
762
+ })}
763
+ </div>
764
+ </div>
765
+ );
766
+ })}
767
+ <button
768
+ type="button"
769
+ onClick={addRow}
770
+ className="text-[10px] px-2 py-1 rounded border border-dashed border-[var(--border)] text-[var(--text-secondary)] hover:border-[var(--accent)] hover:text-[var(--accent)] transition-colors w-full"
771
+ >
772
+ + Add {schema.label || 'instance'}
773
+ </button>
774
+ </div>
775
+ );
776
+ }
@@ -15,13 +15,20 @@
15
15
  * is_error so the LLM can react.
16
16
  */
17
17
 
18
- import type { HttpRequestSpec, ConnectorTool } from '../../connectors/types';
18
+ import type { HttpRequestSpec, ConnectorTool, ConnectorAuth, ConnectorFieldSchema } from '../../connectors/types';
19
19
  import { expandAllTokens } from '../../plugins/templates';
20
20
 
21
21
  export interface HttpProtocolArgs {
22
22
  tool: ConnectorTool;
23
23
  settings: Record<string, any>;
24
24
  args: Record<string, any>;
25
+ /**
26
+ * Connector-level auth. Tool-level `tool.auth` takes precedence.
27
+ * Forge resolves the scheme into the right header/query at dispatch
28
+ * time so manifests don't have to hand-craft Authorization headers
29
+ * or base64-encode credentials.
30
+ */
31
+ connectorAuth?: ConnectorAuth;
25
32
  /**
26
33
  * When true, return the full response body without the 8KB cap. Used by
27
34
  * the Jobs scheduler — it parses JSON, not feeds the response into an
@@ -53,22 +60,42 @@ function expandObjectLeaves(obj: any, settings: Record<string, any>, args: Recor
53
60
  }
54
61
 
55
62
  /**
56
- * Expand `{args.X}` placeholders in a URL path with the value URL-
57
- * encoded. `{settings.X}` is NOT encoded — `{settings.base_url}` is the
58
- * scheme + host (with its own `://` and `/`), which must stay literal.
59
- *
60
- * Why: GitLab and many REST APIs accept either a numeric id or a
61
- * URL-encoded namespace path (`fortinac%2FFortiNAC`) as the project
62
- * identifier in the path. Without encoding, `args.project_id =
63
- * "fortinac/FortiNAC"` interpolates as a raw `/` and turns
64
- * `/projects/{args.project_id}/...` into `/projects/fortinac/FortiNAC/...`
65
- * (extra path segment), which the API can't parse. Numeric ids encode
66
- * to themselves — no regression.
63
+ * Encode a string value per its parameter's `url_encoding` declaration.
64
+ * Default `uri_component` matches encodeURIComponent (slashes encoded).
65
+ * `none` is raw, for pre-formatted paths (e.g. Jenkins folder paths
66
+ * `job/team/job/build`). `path_segments` encodes each `/`-separated
67
+ * piece but preserves the slashes good for human-readable paths
68
+ * that contain spaces or unicode.
69
+ */
70
+ function encodePathValue(raw: string, mode: ConnectorFieldSchema['url_encoding'] | undefined): string {
71
+ switch (mode) {
72
+ case 'none':
73
+ return raw;
74
+ case 'path_segments':
75
+ return raw.split('/').map(encodeURIComponent).join('/');
76
+ case 'uri_component':
77
+ case undefined:
78
+ default:
79
+ return encodeURIComponent(raw);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Expand `{args.X}` placeholders in a URL path. Each arg's encoding is
85
+ * decided by its parameter schema's `url_encoding` field (default
86
+ * `uri_component` — see `encodePathValue` for the modes). `{settings.X}`
87
+ * is NOT encoded — `{settings.base_url}` is the scheme + host (with its
88
+ * own `://` and `/`), which must stay literal.
67
89
  */
68
- function expandUrlPath(template: string, settings: Record<string, any>, args: Record<string, any>): string {
90
+ function expandUrlPath(
91
+ template: string,
92
+ settings: Record<string, any>,
93
+ args: Record<string, any>,
94
+ paramSchemas?: Record<string, ConnectorFieldSchema>,
95
+ ): string {
69
96
  // First handle settings.* with raw substitution (keeps base_url intact).
70
97
  let out = expandAllTokens(template, settings, {});
71
- // Then handle args.* with URL-encoding.
98
+ // Then handle args.* with per-parameter URL encoding.
72
99
  out = out.replace(/\{args\.([^{}]+)\}/g, (full, rawKey) => {
73
100
  const path = String(rawKey).trim().split('.');
74
101
  let v: any = args;
@@ -78,13 +105,23 @@ function expandUrlPath(template: string, settings: Record<string, any>, args: Re
78
105
  }
79
106
  if (v == null) return full;
80
107
  const s = typeof v === 'string' ? v : (typeof v === 'number' || typeof v === 'boolean' ? String(v) : JSON.stringify(v));
81
- return encodeURIComponent(s);
108
+ // Encoding mode comes from the top-level parameter's schema. Nested
109
+ // arg paths inherit their root parameter's encoding — common case is
110
+ // a flat scalar parameter so this matters rarely.
111
+ const rootParam = path[0];
112
+ const mode = paramSchemas?.[rootParam]?.url_encoding;
113
+ return encodePathValue(s, mode);
82
114
  });
83
115
  return out;
84
116
  }
85
117
 
86
- function buildUrl(spec: HttpRequestSpec, settings: Record<string, any>, args: Record<string, any>): string {
87
- const base = expandUrlPath(spec.url, settings, args);
118
+ function buildUrl(
119
+ spec: HttpRequestSpec,
120
+ settings: Record<string, any>,
121
+ args: Record<string, any>,
122
+ paramSchemas?: Record<string, ConnectorFieldSchema>,
123
+ ): string {
124
+ const base = expandUrlPath(spec.url, settings, args, paramSchemas);
88
125
  if (!spec.query) return base;
89
126
  const url = new URL(base);
90
127
  for (const [k, raw] of Object.entries(spec.query)) {
@@ -98,6 +135,48 @@ function buildUrl(spec: HttpRequestSpec, settings: Record<string, any>, args: Re
98
135
  return url.toString();
99
136
  }
100
137
 
138
+ /**
139
+ * Apply a connector/tool auth scheme onto an outbound request. Resolves
140
+ * templated `{settings.*}` inside auth values, base64-encodes basic
141
+ * credentials, and chooses between header / query placement. The URL is
142
+ * passed by reference (returned as a new string if the auth scheme
143
+ * appends a query param). Centralised so the chat dispatcher and the
144
+ * connector-test probe stay consistent.
145
+ */
146
+ export function applyAuth(
147
+ url: string,
148
+ headers: Headers,
149
+ auth: ConnectorAuth | undefined,
150
+ settings: Record<string, any>,
151
+ args: Record<string, any> = {},
152
+ ): string {
153
+ if (!auth || auth.type === 'none') return url;
154
+ const exp = (s: string) => expandAllTokens(String(s ?? ''), settings, args);
155
+ switch (auth.type) {
156
+ case 'basic': {
157
+ const u = exp(auth.username);
158
+ const p = exp(auth.password);
159
+ const token = Buffer.from(`${u}:${p}`, 'utf-8').toString('base64');
160
+ headers.set('Authorization', `Basic ${token}`);
161
+ return url;
162
+ }
163
+ case 'bearer': {
164
+ headers.set('Authorization', `Bearer ${exp(auth.token)}`);
165
+ return url;
166
+ }
167
+ case 'header': {
168
+ headers.set(auth.name, exp(auth.value));
169
+ return url;
170
+ }
171
+ case 'query': {
172
+ const u = new URL(url);
173
+ u.searchParams.set(auth.name, exp(auth.value));
174
+ return u.toString();
175
+ }
176
+ }
177
+ return url;
178
+ }
179
+
101
180
  function buildHeaders(spec: HttpRequestSpec, settings: Record<string, any>, args: Record<string, any>): Headers {
102
181
  const h = new Headers();
103
182
  if (spec.headers) {
@@ -109,12 +188,102 @@ function buildHeaders(spec: HttpRequestSpec, settings: Record<string, any>, args
109
188
  }
110
189
 
111
190
  function buildBody(spec: HttpRequestSpec, settings: Record<string, any>, args: Record<string, any>): { body?: string; contentType?: string } {
112
- if (spec.body == null) return {};
113
- if (typeof spec.body === 'string') {
114
- return { body: expandAllTokens(spec.body, settings, args) };
191
+ if (spec.body != null) {
192
+ if (typeof spec.body === 'string') {
193
+ return { body: expandAllTokens(spec.body, settings, args) };
194
+ }
195
+ const obj = expandObjectLeaves(spec.body, settings, args);
196
+ return { body: JSON.stringify(obj), contentType: 'application/json' };
197
+ }
198
+ if (spec.body_form != null || spec.body_form_inject != null || spec.body_form_inject_from != null) {
199
+ return buildFormBody(spec.body_form, spec.body_form_inject, spec.body_form_inject_from, settings, args);
115
200
  }
116
- const obj = expandObjectLeaves(spec.body, settings, args);
117
- return { body: JSON.stringify(obj), contentType: 'application/json' };
201
+ return {};
202
+ }
203
+
204
+ /**
205
+ * Serialise an object into application/x-www-form-urlencoded body.
206
+ * The spec value can be:
207
+ * - a literal placeholder `{args.NAME}` — resolved to the named arg
208
+ * (must be a plain object); used by Jenkins trigger_build to take a
209
+ * dynamic `params` map of build parameters.
210
+ * - an inline object whose leaves get template-expanded — used when
211
+ * the form keys are static.
212
+ * - any other string — treated as a JSON-string template, parsed, then
213
+ * serialised (less common, but lets manifests build the body inline).
214
+ *
215
+ * null/undefined values are dropped (no empty `KEY=`). Non-string values
216
+ * are stringified.
217
+ */
218
+ function buildFormBody(spec: string | Record<string, unknown> | undefined, inject: Record<string, string> | undefined, injectFrom: string | undefined, settings: Record<string, any>, args: Record<string, any>): { body?: string; contentType?: string } {
219
+ let obj: any = null;
220
+ if (spec != null) {
221
+ if (typeof spec === 'string') {
222
+ const m = spec.match(/^\{args\.([^{}]+)\}$/);
223
+ if (m) {
224
+ obj = args[m[1]];
225
+ // LLMs frequently JSON-stringify an object arg even when the
226
+ // tool schema declares it as `type: json`. Parse it back so the
227
+ // form serialisation works either way.
228
+ if (typeof obj === 'string') {
229
+ try { obj = JSON.parse(obj); } catch { /* leave as null below */ }
230
+ }
231
+ } else {
232
+ const expanded = expandAllTokens(spec, settings, args);
233
+ try { obj = JSON.parse(expanded); } catch { obj = null; }
234
+ }
235
+ } else {
236
+ obj = expandObjectLeaves(spec, settings, args);
237
+ }
238
+ }
239
+ if (obj == null) obj = {};
240
+ if (typeof obj !== 'object' || Array.isArray(obj)) obj = {};
241
+
242
+ // Server-side inject — typically secrets pulled from settings.
243
+ // BOTH key and value are templated (against settings only, NOT args,
244
+ // so the LLM can't shadow injected keys). Templated keys let one
245
+ // manifest target different Jenkins jobs whose param names vary —
246
+ // each instance config sets the key name (e.g. TOKEN_PASSWORD)
247
+ // alongside the value source (e.g. {settings.gitlab_pat}). Entries
248
+ // where the key OR value comes back empty / unresolved get dropped.
249
+ if (inject) {
250
+ for (const [rawKey, rawVal] of Object.entries(inject)) {
251
+ const k = expandAllTokens(String(rawKey), settings, {});
252
+ if (!k || /\{(settings|args)\./.test(k)) continue;
253
+ const v = expandAllTokens(String(rawVal), settings, {});
254
+ if (!v || /\{(settings|args)\./.test(v)) continue;
255
+ obj[k] = v;
256
+ }
257
+ }
258
+
259
+ // body_form_inject_from — settings[X] is expected to be an
260
+ // `instances`-shaped array (each row { name, value, ... }). Inject
261
+ // every row as one form key/value pair. Lets the connector defer
262
+ // the actual key+value choices to per-user instance config without
263
+ // hardcoding them in the manifest. Rows with empty name or value
264
+ // are dropped.
265
+ if (injectFrom) {
266
+ let rows: any = (settings as any)[injectFrom];
267
+ if (typeof rows === 'string') {
268
+ try { rows = JSON.parse(rows); } catch { rows = null; }
269
+ }
270
+ if (Array.isArray(rows)) {
271
+ for (const row of rows) {
272
+ if (!row || typeof row !== 'object') continue;
273
+ const k = typeof row.name === 'string' ? row.name.trim() : '';
274
+ const v = typeof row.value === 'string' ? row.value : (row.value == null ? '' : String(row.value));
275
+ if (!k || !v) continue;
276
+ obj[k] = v;
277
+ }
278
+ }
279
+ }
280
+
281
+ const usp = new URLSearchParams();
282
+ for (const [k, v] of Object.entries(obj)) {
283
+ if (v == null) continue;
284
+ usp.append(k, typeof v === 'string' ? v : String(v));
285
+ }
286
+ return { body: usp.toString(), contentType: 'application/x-www-form-urlencoded' };
118
287
  }
119
288
 
120
289
  function truncate(s: string): { text: string; truncated: boolean; totalBytes: number } {
@@ -124,7 +293,7 @@ function truncate(s: string): { text: string; truncated: boolean; totalBytes: nu
124
293
  return { text: slice, truncated: true, totalBytes: buf.byteLength };
125
294
  }
126
295
 
127
- export async function runHttp({ tool, settings, args, noTruncation }: HttpProtocolArgs): Promise<HttpProtocolResult> {
296
+ export async function runHttp({ tool, settings, args, connectorAuth, noTruncation }: HttpProtocolArgs): Promise<HttpProtocolResult> {
128
297
  const spec = tool.request;
129
298
  if (!spec || !spec.url) {
130
299
  return { content: 'http tool missing `request.url`', is_error: true };
@@ -145,11 +314,16 @@ export async function runHttp({ tool, settings, args, noTruncation }: HttpProtoc
145
314
  }
146
315
  }
147
316
 
148
- const url = buildUrl(spec, settings, argsWithDefaults);
317
+ let url = buildUrl(spec, settings, argsWithDefaults, tool.parameters);
149
318
  const headers = buildHeaders(spec, settings, argsWithDefaults);
150
319
  const { body, contentType } = buildBody(spec, settings, argsWithDefaults);
151
320
  if (body != null && contentType && !headers.has('content-type')) headers.set('content-type', contentType);
152
321
 
322
+ // Tool-level auth overrides connector-level. `{ type: 'none' }` is a
323
+ // valid override that disables auth entirely (public endpoint).
324
+ const effectiveAuth = tool.auth ?? connectorAuth;
325
+ url = applyAuth(url, headers, effectiveAuth, settings, argsWithDefaults);
326
+
153
327
  const controller = new AbortController();
154
328
  const timer = setTimeout(() => controller.abort(), timeoutMs);
155
329
 
@@ -48,8 +48,8 @@ const BUILTINS: Record<string, BuiltinHandler> = {
48
48
  // required (no default) vs optional (have default) so the agent can omit
49
49
  // optional ones rather than passing wrong placeholder values.
50
50
  trigger_pipeline: async (input) => {
51
- const params = (input as { workflow?: string; input?: Record<string, unknown> } | undefined) || {};
52
- const { listWorkflows, startPipeline, getPipeline } = await import('../pipeline');
51
+ const params = (input as { workflow?: string; input?: Record<string, unknown>; skills?: unknown } | undefined) || {};
52
+ const { listWorkflows, startPipeline, getPipeline, getWorkflow } = await import('../pipeline');
53
53
  if (!params.workflow) {
54
54
  const workflows = listWorkflows();
55
55
  if (workflows.length === 0) return 'No workflows found. Create one in <dataDir>/flows/.';
@@ -120,7 +120,48 @@ const BUILTINS: Record<string, BuiltinHandler> = {
120
120
  for (const [k, v] of Object.entries(params.input || {})) {
121
121
  stringInput[k] = v == null ? '' : typeof v === 'string' ? v : String(v);
122
122
  }
123
- const pipeline = startPipeline(params.workflow, stringInput);
123
+
124
+ // Skills — same plumbing as Schedule / Job: pre-install each named
125
+ // skill into every project the workflow's nodes target, then thread
126
+ // the list through to startPipeline so per-task --append-system-prompt
127
+ // gets the /skill-name lines. Unknown skill names are warned (not
128
+ // blocked) — startPipeline ignores any that aren't installed by then.
129
+ let skills: string[] = [];
130
+ if (Array.isArray(params.skills)) {
131
+ skills = (params.skills as unknown[]).filter((s): s is string => typeof s === 'string' && s.trim() !== '');
132
+ }
133
+ if (skills.length > 0) {
134
+ try {
135
+ const { listSkills } = await import('../skills');
136
+ const known = new Set(listSkills().map((s: any) => s.name));
137
+ const unknown = skills.filter((s) => !known.has(s));
138
+ if (unknown.length > 0) {
139
+ return `Unknown skills: ${unknown.join(', ')}. Available: ${[...known].slice(0, 40).join(', ')}. Call list_forge_context to see all skills.`;
140
+ }
141
+ const { ensureInstalledInProject } = await import('../skills');
142
+ const { getProjectInfo } = await import('../projects');
143
+ const projectNames = new Set<string>();
144
+ for (const n of Object.values(wf.nodes || {})) {
145
+ if ((n as any).project) projectNames.add((n as any).project as string);
146
+ }
147
+ const seenPaths = new Set<string>();
148
+ for (const pName of projectNames) {
149
+ const resolved = pName.replace(/\{\{\s*input\.([\w-]+)\s*\}\}/g, (_, k: string) => stringInput[k] ?? '');
150
+ if (!resolved) continue;
151
+ const pInfo = getProjectInfo(resolved);
152
+ if (!pInfo || seenPaths.has(pInfo.path)) continue;
153
+ seenPaths.add(pInfo.path);
154
+ for (const skill of skills) {
155
+ try { await ensureInstalledInProject(skill, pInfo.path); }
156
+ catch (e) { console.warn(`[chat] skill "${skill}" install failed in ${pInfo.path}: ${(e as Error).message}`); }
157
+ }
158
+ }
159
+ } catch (e) {
160
+ console.warn(`[chat] skills preflight failed: ${(e as Error).message}`);
161
+ }
162
+ }
163
+
164
+ const pipeline = startPipeline(params.workflow, stringInput, { skills: skills.length ? skills : undefined });
124
165
  let line = `Pipeline started: ${pipeline.id} (workflow: ${params.workflow}, status: ${pipeline.status})`;
125
166
  if (pipeline.status === 'failed') {
126
167
  const fresh = getPipeline(pipeline.id) || pipeline;
@@ -242,6 +283,11 @@ export const BUILTIN_TOOL_DEFS: BuiltinToolDef[] = [
242
283
  type: 'object',
243
284
  description: 'Pipeline input fields as a flat object. Pass ONLY required fields (marked * in the list response) and optional fields the user explicitly named. Omit optional fields to use their defaults.',
244
285
  },
286
+ skills: {
287
+ type: 'array',
288
+ items: { type: 'string' },
289
+ description: 'Forge skills (by name) to make available to every Claude task inside the pipeline — injected via --append-system-prompt. Pass when the user mentions skill names ("用 git-savvy", "with the code-reviewer skill"). Call list_forge_context to validate names. Omit if the user didn\'t mention any.',
290
+ },
245
291
  },
246
292
  },
247
293
  },
@@ -400,23 +446,54 @@ export async function dispatchTool(
400
446
  const protocol = located.tool.protocol || 'browser';
401
447
  const argInput = (call.input ?? {}) as Record<string, any>;
402
448
 
449
+ // Multi-instance overlay: when a connector's settings carry a
450
+ // `instances` array of `{name, ...}` objects, the tool's `instance`
451
+ // arg picks one and its fields are merged into the top-level settings
452
+ // namespace so templates like `{settings.base_url}` resolve against
453
+ // the chosen instance. Strictly guarded so connectors without this
454
+ // shape (the existing gitlab/mantis/teams/github-api/pmdb) are
455
+ // completely unaffected.
456
+ let effectiveSettings = located.settings;
457
+ let instances = (located.settings as any)?.instances;
458
+ // The `type: json` settings UI stores the field as a string literal,
459
+ // not a parsed value — accept both forms (string from the form,
460
+ // already-parsed array from manifests that ship a default).
461
+ if (typeof instances === 'string') {
462
+ try { instances = JSON.parse(instances); } catch { instances = null; }
463
+ }
464
+ if (
465
+ Array.isArray(instances) &&
466
+ instances.length > 0 &&
467
+ instances.every((i: any) => i && typeof i === 'object' && typeof i.name === 'string')
468
+ ) {
469
+ const wanted = typeof argInput.instance === 'string' ? argInput.instance : undefined;
470
+ const inst = wanted
471
+ ? instances.find((i: any) => i.name === wanted)
472
+ : instances[0];
473
+ if (wanted && !inst) {
474
+ const available = instances.map((i: any) => i.name).join(', ');
475
+ return { content: `unknown instance "${wanted}". Available: ${available}`, is_error: true };
476
+ }
477
+ effectiveSettings = { ...located.settings, ...inst };
478
+ }
479
+
403
480
  try {
404
481
  switch (protocol) {
405
482
  case 'http':
406
- return await runHttp({ tool: located.tool, settings: located.settings, args: argInput, noTruncation: opts.noTruncation });
483
+ return await runHttp({ tool: located.tool, settings: effectiveSettings, args: argInput, connectorAuth: def.auth, noTruncation: opts.noTruncation });
407
484
  case 'shell':
408
- return await runShell({ tool: located.tool, settings: located.settings, args: argInput });
485
+ return await runShell({ tool: located.tool, settings: effectiveSettings, args: argInput });
409
486
  case 'browser': {
410
487
  // Hand the whole connector + tool spec + input + settings to the
411
488
  // extension's runner.ts via the bridge. The extension keeps owning
412
489
  // the runner logic (tab acquire, navigate, executeScript).
413
- const connector = buildConnectorPayload(def, located.entry, located.settings);
490
+ const connector = buildConnectorPayload(def, located.entry, effectiveSettings);
414
491
  const result = (await bridgeRpc('connector.run', {
415
492
  pluginId: located.connectorId, // wire-name kept for extension
416
493
  toolName: located.toolName,
417
494
  input: argInput,
418
495
  connector,
419
- settings: located.settings,
496
+ settings: effectiveSettings,
420
497
  })) as { content?: string; is_error?: boolean } | null;
421
498
  return { content: result?.content ?? '(no content returned)', is_error: !!result?.is_error };
422
499
  }
@@ -132,6 +132,70 @@ function getSecretFieldNames(def: ConnectorDefinition | null): string[] {
132
132
  .map(([name]) => name);
133
133
  }
134
134
 
135
+ function getAllSettingsSchema(def: ConnectorDefinition | null): Record<string, ConnectorFieldSchema> {
136
+ const out: Record<string, ConnectorFieldSchema> = {};
137
+ if (!def) return out;
138
+ if (def.settings) Object.assign(out, def.settings);
139
+ for (const entry of def.connectors || []) {
140
+ if (entry.settings) Object.assign(out, entry.settings);
141
+ }
142
+ return out;
143
+ }
144
+
145
+ /**
146
+ * Walk a connector config value applying `op` (encrypt | decrypt) to
147
+ * every leaf whose schema is `type: 'secret'` or `'password'`. Recurses
148
+ * into `type: 'instances'` arrays so per-row sub-secrets (e.g. Jenkins
149
+ * api_token inside each instances row) get the same treatment as flat
150
+ * top-level secrets — otherwise nested credentials stay plaintext at
151
+ * rest. The on-disk shape is preserved: instances stay as a JSON-
152
+ * stringified array (which is how the type:instances UI persists it).
153
+ */
154
+ function transformConnectorSecrets(
155
+ value: any,
156
+ schema: ConnectorFieldSchema | undefined,
157
+ op: 'encrypt' | 'decrypt',
158
+ ): any {
159
+ if (!schema) return value;
160
+ const t = String((schema as any)?.type || '');
161
+
162
+ if (t === 'secret' || t === 'password') {
163
+ if (typeof value !== 'string' || !value) return value;
164
+ if (op === 'encrypt') return isEncrypted(value) ? value : (() => {
165
+ try { return encryptSecret(value); } catch { return value; }
166
+ })();
167
+ if (op === 'decrypt') {
168
+ if (!isEncrypted(value)) return value;
169
+ try { return decryptSecret(value); }
170
+ catch { return value; }
171
+ }
172
+ return value;
173
+ }
174
+
175
+ if (t === 'instances' && (schema as any).fields) {
176
+ // Accept either the stored JSON-string form or an in-memory array.
177
+ let rows: any;
178
+ const wasString = typeof value === 'string';
179
+ if (wasString) {
180
+ try { rows = JSON.parse(value); } catch { return value; }
181
+ } else {
182
+ rows = value;
183
+ }
184
+ if (!Array.isArray(rows)) return value;
185
+ const transformed = rows.map((row: any) => {
186
+ if (!row || typeof row !== 'object') return row;
187
+ const out: any = { ...row };
188
+ for (const [k, sub] of Object.entries((schema as any).fields)) {
189
+ out[k] = transformConnectorSecrets(out[k], sub as ConnectorFieldSchema, op);
190
+ }
191
+ return out;
192
+ });
193
+ return wasString ? JSON.stringify(transformed) : transformed;
194
+ }
195
+
196
+ return value;
197
+ }
198
+
135
199
  function loadStoreRaw(): ConfigStore {
136
200
  const p = configsFile();
137
201
  if (!existsSync(p)) return {};
@@ -144,20 +208,16 @@ function loadStoreRaw(): ConfigStore {
144
208
 
145
209
  function loadStore(): ConfigStore {
146
210
  const store = loadStoreRaw();
147
- // Decrypt secret fields lazily — readers expect plaintext.
211
+ // Decrypt secret fields lazily — readers expect plaintext. Walks the
212
+ // schema so both flat top-level secrets AND nested instances sub-
213
+ // secrets get unwrapped uniformly.
148
214
  for (const [id, row] of Object.entries(store)) {
149
215
  if (!row?.config) continue;
150
216
  const def = getConnector(id);
151
- const secrets = getSecretFieldNames(def);
152
- if (!secrets.length) continue;
153
- for (const key of secrets) {
154
- const v = row.config[key];
155
- if (typeof v === 'string' && isEncrypted(v)) {
156
- try { row.config[key] = decryptSecret(v); }
157
- catch (err) {
158
- console.warn(`[connectors] failed to decrypt ${id}.${key}`, err);
159
- }
160
- }
217
+ const schema = getAllSettingsSchema(def);
218
+ for (const [k, sub] of Object.entries(schema)) {
219
+ try { row.config[k] = transformConnectorSecrets(row.config[k], sub, 'decrypt'); }
220
+ catch (err) { console.warn(`[connectors] failed to decrypt ${id}.${k}`, err); }
161
221
  }
162
222
  }
163
223
  return store;
@@ -169,15 +229,13 @@ function saveStore(store: ConfigStore): void {
169
229
  const out: ConfigStore = {};
170
230
  for (const [id, row] of Object.entries(store)) {
171
231
  const def = getConnector(id);
172
- const secrets = new Set(getSecretFieldNames(def));
232
+ const schema = getAllSettingsSchema(def);
173
233
  const encryptedConfig: Record<string, unknown> = {};
174
234
  for (const [k, v] of Object.entries(row.config || {})) {
175
- if (secrets.has(k) && typeof v === 'string' && v.length > 0 && !isEncrypted(v)) {
176
- try { encryptedConfig[k] = encryptSecret(v); }
177
- catch { encryptedConfig[k] = v; }
178
- } else {
179
- encryptedConfig[k] = v;
180
- }
235
+ const sub = schema[k];
236
+ encryptedConfig[k] = sub
237
+ ? transformConnectorSecrets(v, sub, 'encrypt')
238
+ : v;
181
239
  }
182
240
  out[id] = {
183
241
  config: encryptedConfig,
@@ -18,15 +18,55 @@ export type ConnectorProtocol = 'browser' | 'http' | 'shell';
18
18
 
19
19
  /** Schema for one settings or parameter field. */
20
20
  export interface ConnectorFieldSchema {
21
- type: 'string' | 'number' | 'boolean' | 'secret' | 'json' | 'select';
21
+ type: 'string' | 'number' | 'boolean' | 'secret' | 'json' | 'select' | 'instances';
22
22
  label?: string;
23
23
  description?: string;
24
24
  required?: boolean;
25
25
  default?: unknown;
26
26
  /** select-type options */
27
27
  options?: string[];
28
+ /**
29
+ * For `type: 'instances'` — schema for each row's sub-fields. The UI
30
+ * renders one collapsible group per row, with these as inner inputs;
31
+ * one field MUST be named `name` and serves as the row label / the
32
+ * `instance` key referenced by tools. Stored on disk as a
33
+ * JSON-stringified array; the tool-dispatcher overlay parses it
34
+ * before template expansion.
35
+ */
36
+ fields?: Record<string, ConnectorFieldSchema>;
37
+ /**
38
+ * How this parameter's value is encoded when expanded into a URL path
39
+ * (`{args.X}` inside an HTTP tool's `request.url`). Default
40
+ * `uri_component` matches encodeURIComponent (slashes encoded). Use
41
+ * `none` when the value is a pre-formatted path that must stay literal
42
+ * (e.g. a Jenkins folder path `job/team/job/build`). `path_segments`
43
+ * encodes each `/`-separated segment individually but preserves the
44
+ * slashes (good for human-readable paths with spaces / unicode).
45
+ *
46
+ * Has no effect on values used in headers, query strings, or bodies —
47
+ * those go through token expansion without URL encoding either way.
48
+ */
49
+ url_encoding?: 'uri_component' | 'none' | 'path_segments';
28
50
  }
29
51
 
52
+ /**
53
+ * How a connector authenticates its HTTP tools. Declared at the
54
+ * connector level (manifest top) and inherited by every `protocol: http`
55
+ * tool; an individual tool can override (`tool.auth: { type: none }`)
56
+ * to skip auth for a public endpoint.
57
+ *
58
+ * Forge resolves the scheme into the right header / query param at
59
+ * dispatch time so manifests don't have to hand-craft Authorization
60
+ * headers (and so secrets like `password` can be base64-encoded
61
+ * server-side without leaking to manifests).
62
+ */
63
+ export type ConnectorAuth =
64
+ | { type: 'none' }
65
+ | { type: 'basic'; username: string; password: string }
66
+ | { type: 'bearer'; token: string }
67
+ | { type: 'header'; name: string; value: string }
68
+ | { type: 'query'; name: string; value: string };
69
+
30
70
  /**
31
71
  * Server-side HTTP request shape, used by `protocol: http` tools.
32
72
  * Template tokens {base_url}, {settings.*}, {args.*} are expanded at run time.
@@ -41,6 +81,36 @@ export interface HttpRequestSpec {
41
81
  query?: Record<string, string>;
42
82
  /** Body. string = sent as-is (templated); object = JSON.stringify'd (string values templated). */
43
83
  body?: string | Record<string, unknown>;
84
+ /**
85
+ * Alternative body form: when set, Forge serialises the referenced
86
+ * value as `application/x-www-form-urlencoded` (URLSearchParams). Use
87
+ * the literal placeholder string `{args.NAME}` to point at an object-
88
+ * valued parameter — typical for triggering Jenkins builds with a
89
+ * dynamic `params` map, or any old-school form-POST API. Ignored if
90
+ * `body` is also set.
91
+ */
92
+ body_form?: string | Record<string, unknown>;
93
+ /**
94
+ * Extra form-urlencoded keys merged into `body_form` server-side.
95
+ * Each value is a template (`{settings.gitlab_pat}` typical). Both
96
+ * the KEY and the VALUE are templated against settings. Keys with an
97
+ * empty / unsubstituted value are dropped (don't post blank
98
+ * secrets). The LLM never sees these — used to inject credentials a
99
+ * tool needs from settings without exposing them in the tool's
100
+ * declared parameters. Takes precedence over `body_form` if the
101
+ * same key appears in both.
102
+ */
103
+ body_form_inject?: Record<string, string>;
104
+ /**
105
+ * Name of a `type: instances` settings field whose every row is
106
+ * injected as one form-urlencoded key/value pair. Each row must have
107
+ * `name` (Jenkins build-param name) and `value` (the value to send).
108
+ * Server-side resolution — LLM never sees these. Empty rows are
109
+ * dropped. Use alongside or instead of `body_form_inject` when the
110
+ * user needs to configure arbitrary key/value pairs at runtime
111
+ * rather than baking them into the manifest.
112
+ */
113
+ body_form_inject_from?: string;
44
114
  }
45
115
 
46
116
  /**
@@ -102,6 +172,13 @@ export interface ConnectorTool {
102
172
 
103
173
  /** shell/http: timeout in milliseconds. Default 30000, max 300000. */
104
174
  timeout_ms?: number;
175
+
176
+ /**
177
+ * http: per-tool auth override. Falls back to the connector's
178
+ * top-level `auth` when omitted. Set `{ type: 'none' }` to skip
179
+ * auth on a public endpoint.
180
+ */
181
+ auth?: ConnectorAuth;
105
182
  }
106
183
 
107
184
  /**
@@ -230,6 +307,15 @@ export interface ConnectorDefinition {
230
307
  host_match?: string;
231
308
  login_redirect?: string;
232
309
 
310
+ /**
311
+ * Default HTTP auth scheme applied to every `protocol: http` tool
312
+ * in this connector. Tools can override via their own `auth` field.
313
+ * Omitting it = no auth applied by Forge (tools may still hand-craft
314
+ * an Authorization header in `request.headers`, like the v0.1 gitlab
315
+ * and github-api manifests).
316
+ */
317
+ auth?: ConnectorAuth;
318
+
233
319
  // ─── 1:N suite — list of sibling entries sharing auth ──
234
320
  connectors?: ConnectorEntry[];
235
321
 
@@ -147,6 +147,145 @@ tools:
147
147
  timeout_ms: 15000
148
148
  ```
149
149
 
150
+ #### Auth schemes
151
+
152
+ Manifests can declare one auth scheme at the top and Forge applies it to every `protocol: http` tool — no need to hand-craft an `Authorization` header per tool, no manifest-side base64.
153
+
154
+ ```yaml
155
+ # Connector-level (applies to all http tools).
156
+ auth:
157
+ type: basic # basic | bearer | header | query | none
158
+ username: '{settings.username}'
159
+ password: '{settings.api_token}'
160
+
161
+ # Variants:
162
+ auth:
163
+ type: bearer
164
+ token: '{settings.token}'
165
+
166
+ auth:
167
+ type: header
168
+ name: PRIVATE-TOKEN
169
+ value: '{settings.token}'
170
+
171
+ auth:
172
+ type: query
173
+ name: access_token
174
+ value: '{settings.token}'
175
+ ```
176
+
177
+ A tool can override (or disable) the inherited scheme with its own `auth:` block. `{ type: none }` skips auth entirely (public endpoint).
178
+
179
+ #### Per-parameter URL encoding
180
+
181
+ Default behaviour for an `{args.X}` in a URL path is `encodeURIComponent` — slashes become `%2F`. This is right for GitLab-style project paths but wrong for systems that expect literal slashes (Jenkins folder paths). Override per parameter:
182
+
183
+ ```yaml
184
+ parameters:
185
+ job_path:
186
+ type: string
187
+ url_encoding: none # uri_component (default) | none | path_segments
188
+ description: 'Pre-formatted Jenkins path with "job/" prefixes, e.g. "job/team-x/job/build".'
189
+ artifact_path:
190
+ type: string
191
+ url_encoding: path_segments # encode each / segment individually, preserve slashes
192
+ ```
193
+
194
+ #### Form-urlencoded bodies (`body_form`)
195
+
196
+ For old-school form POST APIs (Jenkins `/buildWithParameters`, Slack `/chat.postMessage`, etc.). Point at a JSON-typed parameter and Forge serialises it with `URLSearchParams` (`application/x-www-form-urlencoded`):
197
+
198
+ ```yaml
199
+ parameters:
200
+ params:
201
+ type: json
202
+ description: 'Flat object of build params: { "BRANCH": "main", "ENV": "stg" }'
203
+ request:
204
+ method: POST
205
+ url: '{settings.base_url}/{args.job_path}/buildWithParameters'
206
+ body_form: '{args.params}'
207
+ ```
208
+
209
+ LLMs sometimes JSON-stringify nested objects even when the schema says `type: json` — Forge automatically `JSON.parse`'s string-form values, so both shapes work.
210
+
211
+ #### Server-side inject — credentials the LLM should never see
212
+
213
+ Two forms.
214
+
215
+ **1. `body_form_inject` (static keys, manifest-baked)** — useful when the manifest knows exactly which Jenkins / API param name the credential goes under.
216
+
217
+ ```yaml
218
+ request:
219
+ body_form: '{args.params}'
220
+ body_form_inject:
221
+ GITLAB_PAT: '{settings.gitlab_pat}' # key + value both templated against settings
222
+ ```
223
+
224
+ Forge expands both the key and the value against settings (NOT args, so the LLM can't shadow). Empty / unsubstituted entries are dropped — optional secrets don't post blank values.
225
+
226
+ **2. `body_form_inject_from` (dynamic, user-configured per instance)** — when each Jenkins job uses different param names, let the user supply a list of `{name, value}` rows in the settings UI; Forge injects every row.
227
+
228
+ ```yaml
229
+ # settings declaration:
230
+ settings:
231
+ inject_params:
232
+ type: instances # repeating-row UI
233
+ label: "Auto-inject build params"
234
+ fields:
235
+ name: { type: string, required: true, label: "Param name" }
236
+ value: { type: secret, required: true, label: "Value" }
237
+
238
+ # tool spec:
239
+ request:
240
+ body_form: '{args.params}'
241
+ body_form_inject_from: 'inject_params' # name of the instances settings field
242
+ ```
243
+
244
+ User adds rows in the UI (e.g. `TOKEN_PASSWORD` → `<the-real-pat>`); Forge merges every row into the form body server-side. LLM passes only build-specific params, never sees the credentials.
245
+
246
+ #### Multi-instance support (`settings.instances`)
247
+
248
+ To let one install hit multiple servers of the same kind (prod + staging Jenkins, multiple GitLab tenants, etc.), declare your config under a `type: instances` field:
249
+
250
+ ```yaml
251
+ settings:
252
+ instances:
253
+ type: instances
254
+ required: true
255
+ fields:
256
+ name: { type: string, required: true } # how the LLM picks one
257
+ base_url: { type: string, required: true }
258
+ username: { type: string, required: true }
259
+ api_token: { type: secret, required: true }
260
+ ```
261
+
262
+ Each tool gains an implicit `instance` parameter (string). When the LLM passes `instance: "prod"`, Forge looks up the matching row from `settings.instances` and **overlays its fields onto the settings namespace** before template expansion — so your tool spec keeps using `{settings.base_url}` / `{settings.api_token}` as if they were flat. Omitting the arg defaults to the first row.
263
+
264
+ Pair `instances` with `body_form_inject_from` for fully per-instance secret injection (each Jenkins instance has its own list of credentials to inject).
265
+
266
+ Secrets nested inside an instance row (e.g. `api_token: { type: secret }` as a sub-field) are encrypted at rest by the same AES-256-GCM pipeline as flat top-level secrets; the UI masks them with bullets and the Settings → Connectors panel renders a "Replace" button to change them.
267
+
268
+ #### Nested `instances` (rows of rows)
269
+
270
+ A sub-field of an `instances` schema can itself be `type: instances`, and the renderer handles the nesting. This is how Jenkins's `inject_params` lives inside each instance row:
271
+
272
+ ```yaml
273
+ settings:
274
+ instances:
275
+ type: instances
276
+ fields:
277
+ name: { type: string, required: true }
278
+ base_url: { type: string, required: true }
279
+ api_token: { type: secret, required: true }
280
+ inject_params: # nested instances inside a row
281
+ type: instances
282
+ fields:
283
+ name: { type: string, required: true }
284
+ value: { type: secret, required: true }
285
+ ```
286
+
287
+ UI: each top-level instance row expands to a form that includes a nested rows-list for its sub-collection. Encryption recurses, so per-row secrets in either level encrypt correctly.
288
+
150
289
  ### test block
151
290
 
152
291
  A connector can ship a self-test so the Settings → Connectors UI's
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aion0/forge",
3
- "version": "0.9.16",
3
+ "version": "0.9.18",
4
4
  "description": "Unified AI workflow platform — multi-model task orchestration, persistent sessions, web terminal, remote access",
5
5
  "type": "module",
6
6
  "scripts": {