@patchbay-nebius/agent 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,40 +1,11 @@
1
- interface ModelTier {
2
- id: string;
3
- /** USD per million tokens, used for the cost readout. */
4
- inputPrice: number;
5
- outputPrice: number;
6
- }
7
- interface AgentConfig {
8
- mock: boolean;
9
- /** `nebius` (isolated sandbox, default) or `local` (dev fallback, not isolated). */
10
- runner: 'nebius' | 'local';
11
- nebiusApiKey: string;
12
- nebiusProject: string;
13
- nebiusBaseUrl: string;
14
- sandboxUrl: string;
15
- tavilyApiKey: string;
16
- baseImage: string | undefined;
17
- maxAttempts: number;
18
- /** How many repair variants to try in parallel per attempt. 1 = classic sequential repair. */
19
- parallelRepairs: number;
20
- /**
21
- * LLM provider identity, chosen by setting PATCHBAY_LLM_PROVIDER. Default `nebius` keeps
22
- * the Nemotron-specific `chat_template_kwargs: { enable_thinking: false }` field in requests;
23
- * `openai` / `generic` strip it so any other OpenAI-compatible endpoint (OpenAI, Groq,
24
- * Together, Fireworks, OpenRouter, self-hosted vLLM) stops rejecting it.
25
- */
26
- llmProvider: 'nebius' | 'openai' | 'generic';
27
- models: {
28
- fast: ModelTier;
29
- mid: ModelTier;
30
- strong: ModelTier;
31
- };
32
- }
33
- type Env = Record<string, string | undefined>;
34
- declare function loadConfig(env?: Env): AgentConfig;
35
- declare function missingLiveKeys(config: AgentConfig): string[];
36
-
37
1
  type StepId = 'plan' | 'research' | 'generate' | 'verify' | 'package';
2
+ /**
3
+ * Target language the connector is written in. TypeScript is the original path and the
4
+ * default; Python is a second code path with its own prompts, sandbox image, fixtures
5
+ * file and pytest report parser. The plan + research steps are language-agnostic — only
6
+ * generation + verification + fixtures diverge.
7
+ */
8
+ type Lang = 'ts' | 'py';
38
9
  interface Plan {
39
10
  summary: string;
40
11
  source: {
@@ -127,6 +98,7 @@ interface Usage {
127
98
  type RunEvent = {
128
99
  type: 'mode';
129
100
  mode: 'live' | 'replay';
101
+ lang?: Lang;
130
102
  } | {
131
103
  type: 'step';
132
104
  step: StepId;
@@ -174,6 +146,64 @@ type RunEvent = {
174
146
  message: string;
175
147
  };
176
148
 
149
+ interface ModelTier {
150
+ id: string;
151
+ /** USD per million tokens, used for the cost readout. */
152
+ inputPrice: number;
153
+ outputPrice: number;
154
+ }
155
+
156
+ interface AgentConfig {
157
+ mock: boolean;
158
+ /** Target language of the generated connector. Default `ts`; `py` writes Python with pytest. */
159
+ lang: Lang;
160
+ /** `nebius` (isolated sandbox, default) or `local` (dev fallback, not isolated). */
161
+ runner: 'nebius' | 'local';
162
+ nebiusApiKey: string;
163
+ nebiusProject: string;
164
+ nebiusBaseUrl: string;
165
+ sandboxUrl: string;
166
+ tavilyApiKey: string;
167
+ baseImage: string | undefined;
168
+ maxAttempts: number;
169
+ /** How many repair variants to try in parallel per attempt. 1 = classic sequential repair. */
170
+ parallelRepairs: number;
171
+ /**
172
+ * LLM provider identity, chosen by setting PATCHBAY_LLM_PROVIDER. Default `nebius` keeps
173
+ * the Nemotron-specific `chat_template_kwargs: { enable_thinking: false }` field in requests;
174
+ * `openai` / `generic` strip it so any other OpenAI-compatible endpoint (OpenAI, Groq,
175
+ * Together, Fireworks, OpenRouter, self-hosted vLLM) stops rejecting it.
176
+ */
177
+ llmProvider: 'nebius' | 'openai' | 'generic';
178
+ /**
179
+ * `repair` is the model used for the repair/retry step. It defaults to the same model as
180
+ * `strong` (so single-model deployments keep working), but can be overridden independently
181
+ * when the fine-tune was trained on red→green repair pairs — then `strong` stays as
182
+ * Nemotron Ultra for the fresh-generation step, and `repair` points at the fine-tune.
183
+ */
184
+ models: {
185
+ fast: ModelTier;
186
+ mid: ModelTier;
187
+ strong: ModelTier;
188
+ repair: ModelTier;
189
+ };
190
+ /** Per-tier endpoint override for `strong` (when strong lives on a dedicated endpoint). */
191
+ strongOverride: {
192
+ baseUrl: string;
193
+ apiKey: string;
194
+ provider: 'nebius' | 'openai' | 'generic';
195
+ } | null;
196
+ /** Per-tier endpoint override for `repair`. Same shape; usually points at the fine-tune. */
197
+ repairOverride: {
198
+ baseUrl: string;
199
+ apiKey: string;
200
+ provider: 'nebius' | 'openai' | 'generic';
201
+ } | null;
202
+ }
203
+ type Env = Record<string, string | undefined>;
204
+ declare function loadConfig(env?: Env): AgentConfig;
205
+ declare function missingLiveKeys(config: AgentConfig): string[];
206
+
177
207
  interface RecordedRun {
178
208
  prompt: string;
179
209
  /** `fixture` for the bundled example, `live` for runs captured with `npm run agent -- --record`. */
@@ -216,7 +246,7 @@ interface RepairContext {
216
246
  }
217
247
 
218
248
  interface SandboxRunner {
219
- /** Returns an image id that has node, typescript and vitest installed under /work. */
249
+ /** Returns an image id prepared for the configured language (node+vitest, or python+pytest). */
220
250
  prepare(log: (message: string) => void): Promise<string>;
221
251
  /** Runs typecheck + tests for the given files on a fresh branch of the prepared image. */
222
252
  runTests(baseImage: string, files: GeneratedFile[], log: (message: string) => void): Promise<TestReport>;
@@ -275,6 +305,7 @@ declare function repairParallel(files: GeneratedFile[], report: TestReport, deps
275
305
  sandbox: SandboxRunner;
276
306
  config: AgentConfig;
277
307
  baseImage: string;
308
+ lang?: Lang;
278
309
  withFixtures: (files: GeneratedFile[]) => GeneratedFile[];
279
310
  context?: RepairContext;
280
311
  }, log: (m: string) => void): Promise<{
@@ -290,8 +321,85 @@ declare function repairParallel(files: GeneratedFile[], report: TestReport, deps
290
321
  }>;
291
322
 
292
323
  declare function parseTestOutput(stdout: string, ranOn: string): TestReport;
324
+ /**
325
+ * Parse the two-section Python output: py_compile exit code + pytest JSON report.
326
+ * typecheckOk here means `python -m compileall` printed exit 0 — every .py file parsed.
327
+ * A collection error (e.g. import failure in test_connector.py) still produces a report
328
+ * with failed > 0 so the repair loop reacts to it.
329
+ */
330
+ declare function parsePytestOutput(stdout: string, ranOn: string): TestReport;
293
331
  declare function isGreen(report: TestReport): boolean;
294
332
 
333
+ declare const FIXTURES_PATH = "src/fixtures.ts";
334
+ declare const FIXTURES_PATH_PY = "fixtures.py";
335
+ /**
336
+ * The model writes the connector and most of its tests, so those tests share its
337
+ * assumptions. The contract fixtures break that loop: patchbay writes them from the
338
+ * documentation the research step extracted, overwrites them on every attempt, and the
339
+ * test suite must run the connector against them unchanged.
340
+ *
341
+ * Documented URLs are often templates (`https://usX.api.mailchimp.com/3.0/lists/{list_id}`),
342
+ * so the file ships its own matcher and a ready-made fake fetch instead of asking the model
343
+ * to compare URLs.
344
+ */
345
+ declare function renderFixtures(spec: ApiSpec): GeneratedFile;
346
+ /** Static half of the contract check: the suite must actually use the fixtures. */
347
+ declare function contractMissing(files: GeneratedFile[]): string | null;
348
+ /** Folds the static check and the contract test results into the report. */
349
+ declare function withContract(report: TestReport, files: GeneratedFile[]): TestReport;
350
+ /** Keeps the model's files and puts the authoritative fixtures next to them. */
351
+ declare function withFixtures(files: GeneratedFile[], fixtures: GeneratedFile): GeneratedFile[];
352
+ /**
353
+ * Python counterpart of renderFixtures. Same contract: patchbay writes fixtures.py from
354
+ * the researched API spec, the model writes a connector + test file that imports from it,
355
+ * and the test suite must run a contract test (name starts with `test_contract`) that
356
+ * passes SOURCE_EXAMPLE through handle() with contract_fetch injected.
357
+ *
358
+ * The runtime (FakeResponse / fake_fetch / contract_fetch / URL matcher) lives in
359
+ * fixtures-py.template.py as real Python; we only inject the spec-specific pieces
360
+ * (SOURCE_EXAMPLE, TARGET_ENDPOINTS, documentation URLs) via marker substitution.
361
+ */
362
+ declare function renderFixturesPy(spec: ApiSpec): GeneratedFile;
363
+ /** Static half of the Python contract check: the suite must actually use fixtures.py. */
364
+ declare function contractMissingPy(files: GeneratedFile[]): string | null;
365
+ /** Dispatch: pick the right static contract check for the connector's language. */
366
+ declare function contractMissingFor(lang: Lang, files: GeneratedFile[]): string | null;
367
+ /** Dispatch: render fixtures for the connector's language. */
368
+ declare function renderFixturesFor(lang: Lang, spec: ApiSpec): GeneratedFile;
369
+ /** Language-aware fold of the static check + contract test results into the report. */
370
+ declare function withContractFor(lang: Lang, report: TestReport, files: GeneratedFile[]): TestReport;
371
+
372
+ /**
373
+ * `patchbay scan <dir>` walks a repository looking for integration opportunities
374
+ * patchbay could build. It reports a prioritised list with a concrete one-sentence
375
+ * prompt per opportunity so the user can go straight to `patchbay build "..."`
376
+ * (or `patchbay scan <dir> --build-top=N` for the hands-off path).
377
+ *
378
+ * The scanner is deliberately heuristic — regex + file-structure only, no LLM —
379
+ * so it's instant, free, and the user can audit every signal we flagged.
380
+ */
381
+ interface Opportunity {
382
+ score: number;
383
+ kind: 'todo' | 'env-var' | 'webhook-handler' | 'vendor-sdk-import';
384
+ file: string;
385
+ line: number;
386
+ evidence: string;
387
+ prompt: string;
388
+ vendors: string[];
389
+ }
390
+ interface ScanInputFile {
391
+ /** Repo-relative path, forward slashes. */
392
+ path: string;
393
+ content: string;
394
+ }
395
+ /**
396
+ * Scan a list of in-memory files. Used by both the CLI (which populates it by walking
397
+ * disk) and the web scanner (which populates it from the GitHub REST API).
398
+ */
399
+ declare function scanFiles(files: ScanInputFile[]): Opportunity[];
400
+ declare function scanRepo(root: string): Opportunity[];
401
+ declare function formatReport(opportunities: Opportunity[], root: string, limit?: number): string;
402
+
295
403
  /** Live run when keys are configured and mock mode is off, otherwise the recorded replay. */
296
404
  declare function startRun(prompt: string, config?: AgentConfig): AsyncGenerator<RunEvent>;
297
405
  /** Plan + research only. Live if keys are set; the replay stream truncated after `spec` otherwise. */
@@ -299,4 +407,4 @@ declare function startResearch(prompt: string, config?: AgentConfig): AsyncGener
299
407
  /** Verify + repair for given files. Requires live keys; throws in mock mode. */
300
408
  declare function startVerify(files: GeneratedFile[], config?: AgentConfig): AsyncGenerator<RunEvent>;
301
409
 
302
- export { type AgentDeps, type ApiSpec, type AuthSpec, type EndpointSpec, type GeneratedFile, type Plan, REPLAY_RUN, type RecordedRun, type RunEvent, type Source, type StepId, type TestFailure, type TestReport, type Usage, generate, isGreen, loadConfig, makePlan, missingLiveKeys, parseTestOutput, repair, repairParallel, replayRun, research, researchAgent, runAgent, startResearch, startRun, startVerify, verifyAgent };
410
+ export { type AgentDeps, type ApiSpec, type AuthSpec, type EndpointSpec, FIXTURES_PATH, FIXTURES_PATH_PY, type GeneratedFile, type Lang, type Opportunity, type Plan, REPLAY_RUN, type RecordedRun, type RunEvent, type ScanInputFile, type Source, type StepId, type TestFailure, type TestReport, type Usage, contractMissing, contractMissingFor, contractMissingPy, formatReport, generate, isGreen, loadConfig, makePlan, missingLiveKeys, parsePytestOutput, parseTestOutput, renderFixtures, renderFixturesFor, renderFixturesPy, repair, repairParallel, replayRun, research, researchAgent, runAgent, scanFiles, scanRepo, startResearch, startRun, startVerify, verifyAgent, withContract, withContractFor, withFixtures };
package/dist/index.js CHANGED
@@ -1,11 +1,20 @@
1
1
  import {
2
+ FIXTURES_PATH,
3
+ FIXTURES_PATH_PY,
2
4
  REPLAY_RUN,
5
+ contractMissing,
6
+ contractMissingFor,
7
+ contractMissingPy,
3
8
  generate,
4
9
  isGreen,
5
10
  loadConfig,
6
11
  makePlan,
7
12
  missingLiveKeys,
13
+ parsePytestOutput,
8
14
  parseTestOutput,
15
+ renderFixtures,
16
+ renderFixturesFor,
17
+ renderFixturesPy,
9
18
  repair,
10
19
  repairParallel,
11
20
  replayRun,
@@ -15,25 +24,48 @@ import {
15
24
  startResearch,
16
25
  startRun,
17
26
  startVerify,
18
- verifyAgent
19
- } from "./chunk-JVXVCXNZ.js";
27
+ verifyAgent,
28
+ withContract,
29
+ withContractFor,
30
+ withFixtures
31
+ } from "./chunk-DZXK5OTN.js";
32
+ import {
33
+ formatReport,
34
+ scanFiles,
35
+ scanRepo
36
+ } from "./chunk-63LPPBLZ.js";
20
37
  export {
38
+ FIXTURES_PATH,
39
+ FIXTURES_PATH_PY,
21
40
  REPLAY_RUN,
41
+ contractMissing,
42
+ contractMissingFor,
43
+ contractMissingPy,
44
+ formatReport,
22
45
  generate,
23
46
  isGreen,
24
47
  loadConfig,
25
48
  makePlan,
26
49
  missingLiveKeys,
50
+ parsePytestOutput,
27
51
  parseTestOutput,
52
+ renderFixtures,
53
+ renderFixturesFor,
54
+ renderFixturesPy,
28
55
  repair,
29
56
  repairParallel,
30
57
  replayRun,
31
58
  research,
32
59
  researchAgent,
33
60
  runAgent,
61
+ scanFiles,
62
+ scanRepo,
34
63
  startResearch,
35
64
  startRun,
36
65
  startVerify,
37
- verifyAgent
66
+ verifyAgent,
67
+ withContract,
68
+ withContractFor,
69
+ withFixtures
38
70
  };
39
71
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import {
2
+ formatReport,
3
+ scanFiles,
4
+ scanRepo
5
+ } from "./chunk-63LPPBLZ.js";
6
+ export {
7
+ formatReport,
8
+ scanFiles,
9
+ scanRepo
10
+ };
11
+ //# sourceMappingURL=scanner-CEZ56J5N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@patchbay-nebius/agent",
3
- "version": "0.1.3",
4
- "description": "Describe an integration in one sentence, get a tested TypeScript connector. Nemotron on Nebius + Tavily + Nebius Sandboxes.",
3
+ "version": "0.2.0",
4
+ "description": "patchbay CLI: audit MCP servers for OAuth 2.1 gaps and build tested TypeScript/Python connectors from one-line prompts.",
5
5
  "keywords": [
6
6
  "patchbay",
7
7
  "codegen",
@@ -55,6 +55,7 @@
55
55
  "prepublishOnly": "npm run build"
56
56
  },
57
57
  "dependencies": {
58
+ "@patchbay-nebius/audit-core": "^0.1.0",
58
59
  "esbuild": "^0.28.2"
59
60
  },
60
61
  "devDependencies": {