@superatomai/sdk-node 0.0.52-dsp → 0.0.53-dsp
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +942 -942
- package/dist/index.d.mts +611 -1
- package/dist/index.d.ts +611 -1
- package/dist/index.js +1193 -99
- package/dist/index.mjs +1253 -174
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -4472,6 +4472,616 @@ interface DashboardAgentCollectionConfig {
|
|
|
4472
4472
|
}
|
|
4473
4473
|
declare function registerDashboardAgentCollection(sdk: SuperatomSDK, config?: DashboardAgentCollectionConfig): void;
|
|
4474
4474
|
|
|
4475
|
+
/**
|
|
4476
|
+
* Coding-agent driver contract — one shape over every harness (codex today;
|
|
4477
|
+
* claude-code / opencode / pi next). Callers depend on this file only, never on
|
|
4478
|
+
* a harness SDK, so swapping the agent behind a task is a config change.
|
|
4479
|
+
*
|
|
4480
|
+
* Deliberately narrower than the harness SDKs it wraps: the three things a
|
|
4481
|
+
* production run needs and that harness abstractions usually omit — real abort,
|
|
4482
|
+
* real token accounting, and structured tool args — are part of the contract,
|
|
4483
|
+
* not per-driver extras.
|
|
4484
|
+
*/
|
|
4485
|
+
type AgentEventKind = 'turn' | 'message' | 'reasoning' | 'command' | 'tool' | 'file' | 'todo' | 'error';
|
|
4486
|
+
interface AgentEvent {
|
|
4487
|
+
kind: AgentEventKind;
|
|
4488
|
+
/** Stable across started→updated→completed, so a UI updates one block in place. */
|
|
4489
|
+
id?: string;
|
|
4490
|
+
text?: string;
|
|
4491
|
+
command?: string;
|
|
4492
|
+
output?: string;
|
|
4493
|
+
/** Tool calls carry real parsed args — never SQL scraped back out of a shell string. */
|
|
4494
|
+
tool?: {
|
|
4495
|
+
server?: string;
|
|
4496
|
+
name: string;
|
|
4497
|
+
args?: unknown;
|
|
4498
|
+
};
|
|
4499
|
+
status?: 'in_progress' | 'completed' | 'failed';
|
|
4500
|
+
done?: boolean;
|
|
4501
|
+
}
|
|
4502
|
+
interface AgentUsage {
|
|
4503
|
+
inputTokens: number;
|
|
4504
|
+
outputTokens: number;
|
|
4505
|
+
reasoningTokens: number;
|
|
4506
|
+
cacheReadTokens: number;
|
|
4507
|
+
cacheWriteTokens: number;
|
|
4508
|
+
/** Tool + command invocations. With tokens, separates "silently did nothing" from a real run. */
|
|
4509
|
+
toolCalls: number;
|
|
4510
|
+
/** Only when the harness reports it — codex reports tokens but not cost. */
|
|
4511
|
+
costUSD?: number;
|
|
4512
|
+
}
|
|
4513
|
+
interface AgentRunHandlers {
|
|
4514
|
+
/** Formatted live stream: assistant text deltas plus one-line tool/command markers. */
|
|
4515
|
+
onOutput?: (chunk: string) => void;
|
|
4516
|
+
onEvent?: (event: AgentEvent) => void;
|
|
4517
|
+
/** Assistant prose only — safe to show a non-technical user as progress. */
|
|
4518
|
+
onNarration?: (text: string) => void;
|
|
4519
|
+
onUsage?: (usage: AgentUsage) => void;
|
|
4520
|
+
/**
|
|
4521
|
+
* Polled once the turn is live. When it returns true the run ends immediately —
|
|
4522
|
+
* for tasks whose deliverable is a file, the moment it exists there is nothing
|
|
4523
|
+
* left to wait for.
|
|
4524
|
+
*/
|
|
4525
|
+
doneWhen?: () => boolean | Promise<boolean>;
|
|
4526
|
+
}
|
|
4527
|
+
type AgentRunStatus = 'completed' | 'early' | 'aborted' | 'error';
|
|
4528
|
+
interface AgentRunResult {
|
|
4529
|
+
status: AgentRunStatus;
|
|
4530
|
+
/** The final assistant message. */
|
|
4531
|
+
answer: string;
|
|
4532
|
+
ms: number;
|
|
4533
|
+
usage: AgentUsage;
|
|
4534
|
+
/**
|
|
4535
|
+
* Set when status is 'error'. Covers stream-reported failures too, which arrive
|
|
4536
|
+
* as events rather than thrown exceptions — a swallowed provider error is the
|
|
4537
|
+
* failure mode that otherwise looks like a successful empty run.
|
|
4538
|
+
*/
|
|
4539
|
+
error?: string;
|
|
4540
|
+
sessionId?: string;
|
|
4541
|
+
}
|
|
4542
|
+
interface McpServerSpec {
|
|
4543
|
+
command: string;
|
|
4544
|
+
args?: string[];
|
|
4545
|
+
env?: Record<string, string>;
|
|
4546
|
+
}
|
|
4547
|
+
interface CodingAgentSessionOptions {
|
|
4548
|
+
/** Working directory the agent operates in. Scope it to a runtime dir, not a source checkout. */
|
|
4549
|
+
cwd: string;
|
|
4550
|
+
model?: string;
|
|
4551
|
+
/** Resume a prior conversation — the value a previous run returned as sessionId. */
|
|
4552
|
+
resumeId?: string;
|
|
4553
|
+
/** Tools, as MCP servers. Keyed by server name, which shows up on every tool event. */
|
|
4554
|
+
mcpServers?: Record<string, McpServerSpec>;
|
|
4555
|
+
/**
|
|
4556
|
+
* Extra env for the agent process. By default only a small allowlist is passed
|
|
4557
|
+
* through (see ENV_ALLOWLIST) so an agent with shell access can't read the
|
|
4558
|
+
* backend's own secrets out of its environment.
|
|
4559
|
+
*/
|
|
4560
|
+
env?: Record<string, string>;
|
|
4561
|
+
/** Opt out of env scrubbing. Only for local debugging. */
|
|
4562
|
+
inheritEnv?: boolean;
|
|
4563
|
+
}
|
|
4564
|
+
interface CodingAgentSession {
|
|
4565
|
+
readonly harness: string;
|
|
4566
|
+
/** Structured event log vs. a raw terminal stream — the UI picks its renderer from this. */
|
|
4567
|
+
readonly kind: 'events' | 'pty';
|
|
4568
|
+
run(prompt: string, handlers?: AgentRunHandlers, signal?: AbortSignal): Promise<AgentRunResult>;
|
|
4569
|
+
/** Rolling structured events, for replay when a client reconnects mid-run. */
|
|
4570
|
+
events(): AgentEvent[];
|
|
4571
|
+
/** Rolling formatted text, same purpose as events() for text-oriented views. */
|
|
4572
|
+
buffer(): string;
|
|
4573
|
+
busy(): boolean;
|
|
4574
|
+
/** Persist this and pass it back as resumeId to continue the conversation. */
|
|
4575
|
+
sessionId(): string | undefined;
|
|
4576
|
+
/** Abandon the conversation; the next run starts fresh. */
|
|
4577
|
+
reset(): void;
|
|
4578
|
+
dispose(): void;
|
|
4579
|
+
}
|
|
4580
|
+
|
|
4581
|
+
/**
|
|
4582
|
+
* Harness registry. Kept separate from index.ts so collection.ts can reach the
|
|
4583
|
+
* factory without importing the module's own barrel (a cycle tsup would have to
|
|
4584
|
+
* resolve at bundle time).
|
|
4585
|
+
*/
|
|
4586
|
+
type Harness = 'codex';
|
|
4587
|
+
declare function createCodingAgentSession(harness: Harness, opts: CodingAgentSessionOptions): CodingAgentSession;
|
|
4588
|
+
|
|
4589
|
+
/**
|
|
4590
|
+
* Codex driver — OpenAI Codex via @openai/codex-sdk.
|
|
4591
|
+
*
|
|
4592
|
+
* FORMAT CONTRACT: written against @openai/codex-sdk 0.149.1. Harness event
|
|
4593
|
+
* shapes drift; if the event log goes blank after an SDK bump, check normEvent
|
|
4594
|
+
* against the package's dist/index.d.ts first.
|
|
4595
|
+
*
|
|
4596
|
+
* Three things this leans on that the SDK gives natively, so we don't reinvent
|
|
4597
|
+
* them: TurnOptions.signal (real cancellation), TurnCompletedEvent.usage (token
|
|
4598
|
+
* accounting), and mcp_tool_call items (tool args arrive parsed, not scraped
|
|
4599
|
+
* out of a shell command string).
|
|
4600
|
+
*
|
|
4601
|
+
* The package is an optionalDependency: every deployment gets it, but an
|
|
4602
|
+
* install that cannot fetch the ~309MB platform binary skips it rather than
|
|
4603
|
+
* failing. It is therefore loaded dynamically and its types mirrored
|
|
4604
|
+
* structurally below, so a VM without it still builds, starts, and runs
|
|
4605
|
+
* everything else — only the coding agent reports itself unavailable.
|
|
4606
|
+
*/
|
|
4607
|
+
type CodexSandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
4608
|
+
type CodexReasoningEffort = 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'ultra';
|
|
4609
|
+
interface CodexSessionOptions extends CodingAgentSessionOptions {
|
|
4610
|
+
reasoningEffort?: CodexReasoningEffort;
|
|
4611
|
+
/**
|
|
4612
|
+
* Filesystem reach. Default 'workspace-write' — the agent writes its
|
|
4613
|
+
* deliverable into cwd and nothing else. 'danger-full-access' hands a
|
|
4614
|
+
* shell-capable agent the whole box; don't use it on a client VM.
|
|
4615
|
+
*/
|
|
4616
|
+
sandboxMode?: CodexSandboxMode;
|
|
4617
|
+
/** Network for commands the agent runs. Off by default; MCP tools don't need it. */
|
|
4618
|
+
networkAccessEnabled?: boolean;
|
|
4619
|
+
apiKey?: string;
|
|
4620
|
+
baseUrl?: string;
|
|
4621
|
+
/** Raw `--config` overrides merged into the codex config. */
|
|
4622
|
+
extraConfig?: Record<string, unknown>;
|
|
4623
|
+
approvalPolicy?: 'never' | 'on-request' | 'on-failure' | 'untrusted';
|
|
4624
|
+
}
|
|
4625
|
+
declare function createCodexSession(opts: CodexSessionOptions): CodingAgentSession;
|
|
4626
|
+
|
|
4627
|
+
/**
|
|
4628
|
+
* What makes an agent fire.
|
|
4629
|
+
*
|
|
4630
|
+
* Declared ON the definition, deliberately. If triggers lived at the call sites
|
|
4631
|
+
* instead — a counter in the conversation handler, a hook in the kb-nodes
|
|
4632
|
+
* collection — then adding an agent would mean editing unrelated files across
|
|
4633
|
+
* the backend, and no one file would tell you when an agent actually runs.
|
|
4634
|
+
* Here, an agent's folder plus its definition is the whole story.
|
|
4635
|
+
*
|
|
4636
|
+
* The deployment's only job is to announce that something happened:
|
|
4637
|
+
*
|
|
4638
|
+
* emitAgentEvent('conversation.answered', { threadId })
|
|
4639
|
+
* emitAgentEvent('kb-node.changed', { id, op: 'update' })
|
|
4640
|
+
*
|
|
4641
|
+
* Which agents care, and how many events it takes, is the agents' business.
|
|
4642
|
+
*/
|
|
4643
|
+
type AgentTrigger =
|
|
4644
|
+
/** Only runCodingAgent(). The default. */
|
|
4645
|
+
{
|
|
4646
|
+
type: 'manual';
|
|
4647
|
+
}
|
|
4648
|
+
/** Every N milliseconds while the process is up. */
|
|
4649
|
+
| {
|
|
4650
|
+
type: 'interval';
|
|
4651
|
+
everyMs: number;
|
|
4652
|
+
}
|
|
4653
|
+
/**
|
|
4654
|
+
* On a named event. `debounceMs` collapses a burst into one run — editing
|
|
4655
|
+
* five knowledge nodes in a row is one reason to rebuild, not five.
|
|
4656
|
+
*/
|
|
4657
|
+
| {
|
|
4658
|
+
type: 'event';
|
|
4659
|
+
on: string | string[];
|
|
4660
|
+
debounceMs?: number;
|
|
4661
|
+
}
|
|
4662
|
+
/**
|
|
4663
|
+
* Every Nth occurrence of an event. The count is PERSISTED, so "after 10
|
|
4664
|
+
* questions" survives a restart instead of silently starting over.
|
|
4665
|
+
*/
|
|
4666
|
+
| {
|
|
4667
|
+
type: 'count';
|
|
4668
|
+
on: string;
|
|
4669
|
+
every: number;
|
|
4670
|
+
};
|
|
4671
|
+
interface TriggerFireInfo {
|
|
4672
|
+
agentId: string;
|
|
4673
|
+
/** What set it off, for the log line. */
|
|
4674
|
+
reason: string;
|
|
4675
|
+
payload?: unknown;
|
|
4676
|
+
}
|
|
4677
|
+
/** Notified after every triggered run — for recording history or alerting. */
|
|
4678
|
+
type RunListener = (record: AgentRunRecord, info: TriggerFireInfo) => void;
|
|
4679
|
+
declare function onAgentRun(fn: RunListener): () => void;
|
|
4680
|
+
/**
|
|
4681
|
+
* Tell the agents something happened. Safe to call from anywhere, including a
|
|
4682
|
+
* request path — it never throws and never blocks: matching runs are started,
|
|
4683
|
+
* not awaited.
|
|
4684
|
+
*/
|
|
4685
|
+
declare function emitAgentEvent(event: string, payload?: unknown): void;
|
|
4686
|
+
/**
|
|
4687
|
+
* Start interval triggers. Call once at startup, after registerCodingAgents.
|
|
4688
|
+
* Event and count triggers need nothing started — they wake on emitAgentEvent.
|
|
4689
|
+
*/
|
|
4690
|
+
declare function startAgentTriggers(): void;
|
|
4691
|
+
declare function stopAgentTriggers(): void;
|
|
4692
|
+
/** What fires each agent — for a startup log or an admin screen. */
|
|
4693
|
+
declare function describeTriggers(): Array<{
|
|
4694
|
+
agentId: string;
|
|
4695
|
+
triggers: string[];
|
|
4696
|
+
}>;
|
|
4697
|
+
|
|
4698
|
+
/**
|
|
4699
|
+
* What a coding agent IS.
|
|
4700
|
+
*
|
|
4701
|
+
* An agent is a job description, not code that does the job: instructions, the
|
|
4702
|
+
* inputs it should be handed, the tools it may reach, the deliverable it must
|
|
4703
|
+
* produce, and what we do with that deliverable. The agent itself decides HOW —
|
|
4704
|
+
* it can read the inputs, write and run scripts over them, check its own work,
|
|
4705
|
+
* and iterate. That is the whole reason for using a coding agent rather than a
|
|
4706
|
+
* single LLM call: the job's data never has to fit in a context window.
|
|
4707
|
+
*
|
|
4708
|
+
* Adding an agent is a folder with a system.md, one file implementing this
|
|
4709
|
+
* interface, and one line in the registry. Nothing else changes.
|
|
4710
|
+
*/
|
|
4711
|
+
/** The disposable directory one run happens in. */
|
|
4712
|
+
interface Workspace {
|
|
4713
|
+
/** Absolute path the agent runs in. Everything below is relative to it. */
|
|
4714
|
+
dir: string;
|
|
4715
|
+
/** Unique per run — also the folder name, so runs never collide. */
|
|
4716
|
+
runId: string;
|
|
4717
|
+
/** Write a file into the workspace, creating parent directories. */
|
|
4718
|
+
write(relPath: string, contents: string): Promise<void>;
|
|
4719
|
+
/** Write JSON (pretty-printed — the agent reads these by eye as often as by script). */
|
|
4720
|
+
writeJson(relPath: string, value: unknown): Promise<void>;
|
|
4721
|
+
/** Write one JSON object per line. The right shape for anything the agent will stream or grep. */
|
|
4722
|
+
writeJsonl(relPath: string, rows: unknown[]): Promise<void>;
|
|
4723
|
+
/** Read a file the agent produced. Returns null when it isn't there. */
|
|
4724
|
+
read(relPath: string): Promise<string | null>;
|
|
4725
|
+
/** Absolute path for a workspace-relative path — for telling the agent where to write. */
|
|
4726
|
+
pathTo(relPath: string): string;
|
|
4727
|
+
}
|
|
4728
|
+
/** Minimal validator shape, so this file needn't depend on a schema library. */
|
|
4729
|
+
interface OutputValidator<T> {
|
|
4730
|
+
/** Throw with a useful message, or return the parsed value. Zod's `.parse` satisfies this. */
|
|
4731
|
+
parse(value: unknown): T;
|
|
4732
|
+
}
|
|
4733
|
+
interface OutputContract<T> {
|
|
4734
|
+
/**
|
|
4735
|
+
* Workspace-relative path the agent must write, e.g. 'out/concepts.json'.
|
|
4736
|
+
* Nothing else counts as the deliverable: the run ends the moment this
|
|
4737
|
+
* appears, and a run that finishes without it is a failure, not a partial
|
|
4738
|
+
* success.
|
|
4739
|
+
*/
|
|
4740
|
+
file: string;
|
|
4741
|
+
/** Validated before anything is persisted, so a malformed run fails loudly and applies nothing. */
|
|
4742
|
+
schema: OutputValidator<T>;
|
|
4743
|
+
}
|
|
4744
|
+
/** What apply() reports back — surfaced in the run record and to the caller. */
|
|
4745
|
+
interface ApplySummary {
|
|
4746
|
+
/** One line a human can read in a log or the UI. */
|
|
4747
|
+
summary: string;
|
|
4748
|
+
/** Whatever counts for this agent: {created, updated, skipped}, etc. */
|
|
4749
|
+
counts?: Record<string, number>;
|
|
4750
|
+
/** Anything the caller may want to inspect or show. */
|
|
4751
|
+
details?: unknown;
|
|
4752
|
+
}
|
|
4753
|
+
interface AgentRunContext {
|
|
4754
|
+
projectId?: string;
|
|
4755
|
+
userId?: string;
|
|
4756
|
+
/**
|
|
4757
|
+
* This run's id — also the workspace directory name. Passed so apply() can
|
|
4758
|
+
* stamp whatever it persists with the run that produced it, which is the
|
|
4759
|
+
* only link from a stored result back to the inputs and scripts behind it.
|
|
4760
|
+
*/
|
|
4761
|
+
runId?: string;
|
|
4762
|
+
/** The run's workspace, for an apply() that needs a file the agent left. */
|
|
4763
|
+
workspaceDir?: string;
|
|
4764
|
+
/** Cancels the run; forwarded to the driver's real abort. */
|
|
4765
|
+
signal?: AbortSignal;
|
|
4766
|
+
/** Live progress. Populated for chat mode; a task run may also stream to a log. */
|
|
4767
|
+
onOutput?: (chunk: string) => void;
|
|
4768
|
+
onEvent?: (event: AgentEvent) => void;
|
|
4769
|
+
onUsage?: (usage: AgentUsage) => void;
|
|
4770
|
+
}
|
|
4771
|
+
/**
|
|
4772
|
+
* How much an agent carries between runs.
|
|
4773
|
+
*
|
|
4774
|
+
* Codex manages its own context: it tracks the window and compacts when it
|
|
4775
|
+
* crosses `auto_compact_token_limit`, emitting a ContextCompacted event. That
|
|
4776
|
+
* happens with no involvement from us, so a persistent session survives
|
|
4777
|
+
* indefinitely on its own. (The mechanism is in the engine but not the
|
|
4778
|
+
* TypeScript SDK — Thread exposes only id/run/runStreamed — which is why there
|
|
4779
|
+
* is nothing here to call.)
|
|
4780
|
+
*
|
|
4781
|
+
* What compaction cannot do is make the session authoritative. It summarises to
|
|
4782
|
+
* make room, so detail is lost by design; and ~/.codex/sessions is a directory
|
|
4783
|
+
* on one machine, not the database. So durable facts belong in `memory/` files
|
|
4784
|
+
* and in the tables the agent writes through apply(), with the session free to
|
|
4785
|
+
* compact itself as it likes. Memory on disk, context managed by codex.
|
|
4786
|
+
*/
|
|
4787
|
+
interface SessionPolicy {
|
|
4788
|
+
/**
|
|
4789
|
+
* 'per-run' a fresh harness session each time (default).
|
|
4790
|
+
* 'persistent' resume the same session across runs, so the agent keeps its
|
|
4791
|
+
* working context. Always paired with durable files — never rely
|
|
4792
|
+
* on it alone.
|
|
4793
|
+
*/
|
|
4794
|
+
scope?: 'per-run' | 'persistent';
|
|
4795
|
+
/**
|
|
4796
|
+
* 'per-run' a throwaway directory per run (default); pruned by keepRuns.
|
|
4797
|
+
* 'persistent' one directory the agent owns across runs. `memory/` survives
|
|
4798
|
+
* untouched; `input/` is cleared each run so a stale input can
|
|
4799
|
+
* never be mistaken for this run's.
|
|
4800
|
+
*/
|
|
4801
|
+
workspace?: 'per-run' | 'persistent';
|
|
4802
|
+
/**
|
|
4803
|
+
* Safety valve, not the compaction mechanism — codex already compacts on its
|
|
4804
|
+
* own. Starts a fresh session after this many runs while keeping the
|
|
4805
|
+
* workspace, for when you want a hard ceiling on how much summarised history
|
|
4806
|
+
* an agent drags along, or a clean slate on a cadence. Omit by default.
|
|
4807
|
+
*/
|
|
4808
|
+
resetAfterTurns?: number;
|
|
4809
|
+
}
|
|
4810
|
+
interface CodingAgentDefinition<TInput = unknown, TOutput = unknown> {
|
|
4811
|
+
/** Stable id: the folder name under .prompts/coding-agents, and the key callers use. */
|
|
4812
|
+
id: string;
|
|
4813
|
+
/** Human-readable, for the UI and logs. */
|
|
4814
|
+
title: string;
|
|
4815
|
+
/** One line: what this agent is for. */
|
|
4816
|
+
description?: string;
|
|
4817
|
+
/**
|
|
4818
|
+
* 'task' — headless. Runs from a cron, an event, or a command; produces the
|
|
4819
|
+
* deliverable and applies it. Nobody is watching.
|
|
4820
|
+
* 'chat' — a person is typing. Streams, keeps its session across turns, and
|
|
4821
|
+
* is not required to produce a deliverable at all.
|
|
4822
|
+
*/
|
|
4823
|
+
mode: 'task' | 'chat';
|
|
4824
|
+
/**
|
|
4825
|
+
* Directory holding this agent's system.md. Defaults to
|
|
4826
|
+
* `<promptRoot>/<id>`. The runner copies system.md into the workspace as
|
|
4827
|
+
* AGENTS.md, which is the filename the harness actually reads from its
|
|
4828
|
+
* working directory — that indirection is what lets the instructions stay
|
|
4829
|
+
* version-controlled while the workspace stays disposable.
|
|
4830
|
+
*/
|
|
4831
|
+
promptDir?: string;
|
|
4832
|
+
/** Override the deployment default for this agent alone. */
|
|
4833
|
+
harness?: Harness;
|
|
4834
|
+
model?: string;
|
|
4835
|
+
/**
|
|
4836
|
+
* Let this agent's shell reach the network. Off by default.
|
|
4837
|
+
*
|
|
4838
|
+
* Needed by any agent given bridge shims (writeBridgeShims), which reach the
|
|
4839
|
+
* backend over localhost HTTP. Note the sandbox has no host allowlist, so
|
|
4840
|
+
* this grants the whole internet, not just the bridge — scope it to agents
|
|
4841
|
+
* that genuinely need it.
|
|
4842
|
+
*/
|
|
4843
|
+
networkAccessEnabled?: boolean;
|
|
4844
|
+
/**
|
|
4845
|
+
* Filesystem reach. Defaults to the driver's 'workspace-write'.
|
|
4846
|
+
* 'danger-full-access' removes the sandbox entirely — it is the only mode in
|
|
4847
|
+
* which codex permits MCP tool calls headlessly, which is exactly why the
|
|
4848
|
+
* shims exist instead.
|
|
4849
|
+
*/
|
|
4850
|
+
sandboxMode?: 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
4851
|
+
/**
|
|
4852
|
+
* Tools this agent may reach, as MCP servers. Deliberately per-agent: an
|
|
4853
|
+
* agent that reads the knowledge base has no business holding a database
|
|
4854
|
+
* connection. Omit for an agent that only needs the files it is given.
|
|
4855
|
+
*/
|
|
4856
|
+
tools?: Record<string, McpServerSpec>;
|
|
4857
|
+
/**
|
|
4858
|
+
* Put the job's inputs in the workspace as FILES, not prompt text. A coding
|
|
4859
|
+
* agent can grep, aggregate and script over a file; it cannot do any of that
|
|
4860
|
+
* with text pasted into its prompt, and a large input would not fit there
|
|
4861
|
+
* anyway.
|
|
4862
|
+
*/
|
|
4863
|
+
prepare?(ws: Workspace, input: TInput, ctx: AgentRunContext): Promise<void>;
|
|
4864
|
+
/**
|
|
4865
|
+
* The short framing sent as the turn's prompt. Keep it short — the standing
|
|
4866
|
+
* instructions belong in system.md and the data belongs in files. Defaults
|
|
4867
|
+
* to a generic instruction naming the output path.
|
|
4868
|
+
*/
|
|
4869
|
+
buildPrompt?(ws: Workspace, input: TInput, ctx: AgentRunContext): string | Promise<string>;
|
|
4870
|
+
/** Required for 'task' mode; meaningless for 'chat'. */
|
|
4871
|
+
output?: OutputContract<TOutput>;
|
|
4872
|
+
/**
|
|
4873
|
+
* Persist the validated deliverable — through existing services, never raw
|
|
4874
|
+
* SQL from inside the agent. Keeping the write on this side is what makes a
|
|
4875
|
+
* run auditable and replayable: the artifact on disk is the same input
|
|
4876
|
+
* apply() would get again tomorrow.
|
|
4877
|
+
*/
|
|
4878
|
+
apply?(result: TOutput, input: TInput, ctx: AgentRunContext): Promise<ApplySummary>;
|
|
4879
|
+
/**
|
|
4880
|
+
* What makes this agent run. Declared here so an agent's folder plus this
|
|
4881
|
+
* file is the complete story of when it fires. See triggers.ts.
|
|
4882
|
+
*/
|
|
4883
|
+
trigger?: AgentTrigger | AgentTrigger[];
|
|
4884
|
+
/**
|
|
4885
|
+
* WHO this agent's accumulated state belongs to. Distinct from `mode`, which
|
|
4886
|
+
* is only how a run was triggered — the two were conflated before, so a
|
|
4887
|
+
* project agent someone chatted with silently got a private per-thread
|
|
4888
|
+
* workspace and lost its memory.
|
|
4889
|
+
*
|
|
4890
|
+
* 'project' ONE workspace and session for the whole deployment, whoever
|
|
4891
|
+
* invokes it. A concept builder is project-wide: everything it
|
|
4892
|
+
* learns should accumulate in one place, and a chat turn joins
|
|
4893
|
+
* that same workspace rather than forking a copy. Concurrent
|
|
4894
|
+
* runs serialise.
|
|
4895
|
+
* 'user' one per user, shared across that user's threads.
|
|
4896
|
+
* 'thread' one per conversation — an ordinary chat assistant.
|
|
4897
|
+
*
|
|
4898
|
+
* Default: 'thread' for mode 'chat', 'project' for mode 'task'.
|
|
4899
|
+
*/
|
|
4900
|
+
scope?: 'project' | 'user' | 'thread';
|
|
4901
|
+
/**
|
|
4902
|
+
* Kill the turn the moment the deliverable file appears, instead of letting
|
|
4903
|
+
* the agent finish.
|
|
4904
|
+
*
|
|
4905
|
+
* Off by default, and the reason is measured: an agent typically writes its
|
|
4906
|
+
* output and then keeps going — verifying, re-reading, summarising — so
|
|
4907
|
+
* stopping at the write cuts the turn well before codex emits
|
|
4908
|
+
* turn.completed, which is the only event carrying token usage. Early stop
|
|
4909
|
+
* therefore costs you all cost tracking, and skips the agent's own
|
|
4910
|
+
* self-check. Turn it on for a long-tailed agent where the file really is
|
|
4911
|
+
* the last thing that matters.
|
|
4912
|
+
*/
|
|
4913
|
+
stopOnDeliverable?: boolean;
|
|
4914
|
+
/** What this agent carries between runs. Default: nothing (fresh session and workspace). */
|
|
4915
|
+
session?: SessionPolicy;
|
|
4916
|
+
/** Hard cap for one run. Default 15 minutes. */
|
|
4917
|
+
timeoutMs?: number;
|
|
4918
|
+
}
|
|
4919
|
+
/** What a completed run reports. */
|
|
4920
|
+
interface AgentRunRecord<TOutput = unknown> {
|
|
4921
|
+
agentId: string;
|
|
4922
|
+
runId: string;
|
|
4923
|
+
/** The run's directory — instructions, inputs, scripts and output all still there. */
|
|
4924
|
+
workspaceDir: string;
|
|
4925
|
+
/**
|
|
4926
|
+
* 'early' the deliverable landed and we stopped the turn — a success, kept
|
|
4927
|
+
* distinct from 'completed' so a masked early exit is visible.
|
|
4928
|
+
* 'skipped' another run of this agent held the lock; nothing was done.
|
|
4929
|
+
*/
|
|
4930
|
+
status: 'completed' | 'early' | 'aborted' | 'error' | 'skipped';
|
|
4931
|
+
/** The agent's closing message. */
|
|
4932
|
+
answer: string;
|
|
4933
|
+
ms: number;
|
|
4934
|
+
usage: AgentUsage;
|
|
4935
|
+
/** Present when the agent produced and validated its deliverable. */
|
|
4936
|
+
output?: TOutput;
|
|
4937
|
+
/** Present when apply() ran. */
|
|
4938
|
+
applied?: ApplySummary;
|
|
4939
|
+
error?: string;
|
|
4940
|
+
/** Harness session id, for resuming a chat. */
|
|
4941
|
+
sessionId?: string;
|
|
4942
|
+
}
|
|
4943
|
+
|
|
4944
|
+
/**
|
|
4945
|
+
* The agent registry — one place that knows which agents this deployment has.
|
|
4946
|
+
*
|
|
4947
|
+
* Deliberately a plain module-level map rather than something on the SDK: a
|
|
4948
|
+
* cron job, a CLI command and the websocket handler all need to reach the same
|
|
4949
|
+
* agents, and only one of those has an SDK instance in hand.
|
|
4950
|
+
*/
|
|
4951
|
+
interface CodingAgentsConfig {
|
|
4952
|
+
/**
|
|
4953
|
+
* Where per-agent instruction folders live. Each agent reads
|
|
4954
|
+
* `<promptRoot>/<agent.id>/system.md`.
|
|
4955
|
+
* Default: `<cwd>/.prompts/coding-agents`, matching the .prompts convention
|
|
4956
|
+
* the rest of the deployment already uses.
|
|
4957
|
+
*/
|
|
4958
|
+
promptRoot?: string;
|
|
4959
|
+
/**
|
|
4960
|
+
* Root for run workspaces: `<runtimeDir>/<agentId>/<runId>/`. Regenerated
|
|
4961
|
+
* per run and safe to gitignore — deliberately not inside promptRoot, which
|
|
4962
|
+
* is version-controlled.
|
|
4963
|
+
* Default: `<cwd>/.coding-agent-runtime`.
|
|
4964
|
+
*/
|
|
4965
|
+
runtimeDir?: string;
|
|
4966
|
+
/** Fallback harness for agents that don't name one. */
|
|
4967
|
+
harness?: Harness;
|
|
4968
|
+
/** Fallback model. */
|
|
4969
|
+
model?: string;
|
|
4970
|
+
/** Tools every agent gets, merged under each agent's own (the agent's win on a name clash). */
|
|
4971
|
+
sharedTools?: Record<string, McpServerSpec>;
|
|
4972
|
+
/** Keep this many run directories per agent; older ones are pruned. 0 keeps everything. */
|
|
4973
|
+
keepRuns?: number;
|
|
4974
|
+
}
|
|
4975
|
+
/**
|
|
4976
|
+
* Register this deployment's agents. Call once at startup.
|
|
4977
|
+
*
|
|
4978
|
+
* Re-registering an id replaces it — that keeps hot-reload working in dev and
|
|
4979
|
+
* makes a double registration a no-op rather than a silent duplicate.
|
|
4980
|
+
*/
|
|
4981
|
+
declare function registerCodingAgents(definitions: CodingAgentDefinition<any, any>[], options?: CodingAgentsConfig): void;
|
|
4982
|
+
declare function getCodingAgent(id: string): CodingAgentDefinition<any, any> | undefined;
|
|
4983
|
+
declare function listCodingAgents(): Array<{
|
|
4984
|
+
id: string;
|
|
4985
|
+
title: string;
|
|
4986
|
+
description?: string;
|
|
4987
|
+
mode: 'task' | 'chat';
|
|
4988
|
+
}>;
|
|
4989
|
+
declare function getCodingAgentsConfig(): Required<Pick<CodingAgentsConfig, "harness" | "promptRoot" | "runtimeDir" | "keepRuns">> & CodingAgentsConfig;
|
|
4990
|
+
|
|
4991
|
+
interface RunAgentOptions<TInput> extends AgentRunContext {
|
|
4992
|
+
input?: TInput;
|
|
4993
|
+
/** Scopes a 'thread' agent. Ignored by a project-scoped one. */
|
|
4994
|
+
threadId?: string;
|
|
4995
|
+
/**
|
|
4996
|
+
* Escape hatch that pins the workspace directory outright. Almost never
|
|
4997
|
+
* right — it defeats the agent's own scope, which is how a project agent
|
|
4998
|
+
* ends up with a private copy per caller. Left for tests and one-offs.
|
|
4999
|
+
*/
|
|
5000
|
+
workspaceDir?: string;
|
|
5001
|
+
/** Resume the harness session — chat continuity across turns and restarts. */
|
|
5002
|
+
resumeId?: string;
|
|
5003
|
+
/** Overrides the definition's prompt entirely. Chat mode: this is the user's message. */
|
|
5004
|
+
prompt?: string;
|
|
5005
|
+
}
|
|
5006
|
+
/**
|
|
5007
|
+
* Run one agent, end to end.
|
|
5008
|
+
*
|
|
5009
|
+
* Never throws for an agent-side failure — a bad run comes back as a record
|
|
5010
|
+
* with status 'error', because callers are usually crons and message handlers
|
|
5011
|
+
* that must keep going. Genuinely programmer errors (unknown agent id) do throw.
|
|
5012
|
+
*/
|
|
5013
|
+
declare function runCodingAgent<TInput = unknown, TOutput = unknown>(agentId: string, options?: RunAgentOptions<TInput>): Promise<AgentRunRecord<TOutput>>;
|
|
5014
|
+
|
|
5015
|
+
/**
|
|
5016
|
+
* Write `./sources` and `./query` into an agent's workspace: read-only data
|
|
5017
|
+
* access as plain executables it runs with bash.
|
|
5018
|
+
*
|
|
5019
|
+
* Why not MCP: codex gates MCP tool calls on the sandbox. Under any sandboxed
|
|
5020
|
+
* mode they need approval, and a headless run must set approvalPolicy 'never',
|
|
5021
|
+
* which denies rather than grants — measured, not assumed. Only
|
|
5022
|
+
* danger-full-access permits them, and that removes the filesystem sandbox
|
|
5023
|
+
* entirely. Bash commands under workspace-write need no approval, so a shim
|
|
5024
|
+
* buys the same capability while the agent stays confined to its workspace.
|
|
5025
|
+
*
|
|
5026
|
+
* An MCP server for this was written and then removed: the same approval gate
|
|
5027
|
+
* applies to the Agents chat tab, which is equally headless from codex's point
|
|
5028
|
+
* of view, so it was unreachable everywhere. `mcpServers` stays plumbed through
|
|
5029
|
+
* the driver for third-party servers; see git history for the removed one.
|
|
5030
|
+
*
|
|
5031
|
+
* The cost is structured tool events: calls arrive as `bash → ./query ...`
|
|
5032
|
+
* rather than typed items with parsed arguments. That matters for a chat UI
|
|
5033
|
+
* with a human watching; for a headless task agent it does not.
|
|
5034
|
+
*
|
|
5035
|
+
* Requires networkAccessEnabled on the session — the shim reaches the bridge
|
|
5036
|
+
* over HTTP, and that is the whole point of it.
|
|
5037
|
+
*/
|
|
5038
|
+
declare function writeBridgeShims(ws: Workspace, opts: {
|
|
5039
|
+
bridgeUrl: string;
|
|
5040
|
+
sources: Array<{
|
|
5041
|
+
id: string;
|
|
5042
|
+
name?: string;
|
|
5043
|
+
description?: string;
|
|
5044
|
+
}>;
|
|
5045
|
+
maxRows?: number;
|
|
5046
|
+
}): void;
|
|
5047
|
+
|
|
5048
|
+
/**
|
|
5049
|
+
* Read-only SQL guard for any path that hands an agent a database.
|
|
5050
|
+
*
|
|
5051
|
+
* Defence in depth, NOT a boundary. The agent has a shell and can reach the
|
|
5052
|
+
* bridge directly, so anything enforced only here is advisory — it stops
|
|
5053
|
+
* mistakes, not determination. The real boundary is a database user without
|
|
5054
|
+
* write permission; this exists so a confused agent gets a clear correction
|
|
5055
|
+
* instead of a silent partial write.
|
|
5056
|
+
*/
|
|
5057
|
+
/** Throws with a message written for the agent to act on. */
|
|
5058
|
+
declare function assertReadOnlySql(sql: string): void;
|
|
5059
|
+
|
|
5060
|
+
/**
|
|
5061
|
+
* The 'coding-agent'.'run' collection — a chat turn against a coding agent.
|
|
5062
|
+
*
|
|
5063
|
+
* Generic on purpose: nothing here knows about dashboards, reports, or any
|
|
5064
|
+
* particular deliverable. It owns what every harness-backed chat needs — one
|
|
5065
|
+
* session per thread, a per-thread workspace, a run lock, and forwarding the
|
|
5066
|
+
* driver's callbacks to the transport. Task-specific flows (prompt assembly, a
|
|
5067
|
+
* draft-file contract, persistence) build on top of this rather than inside it.
|
|
5068
|
+
*/
|
|
5069
|
+
interface CodingAgentCollectionConfig {
|
|
5070
|
+
/**
|
|
5071
|
+
* Root for per-thread agent workspaces. Each thread gets its own directory
|
|
5072
|
+
* underneath, so one chat can't read or clobber another's files, and none of
|
|
5073
|
+
* them sit inside the backend's own source tree.
|
|
5074
|
+
* Default: `<process.cwd()>/.coding-agent-runtime`.
|
|
5075
|
+
*/
|
|
5076
|
+
runtimeDir?: string;
|
|
5077
|
+
/** Default harness when the request doesn't name one. */
|
|
5078
|
+
harness?: Harness;
|
|
5079
|
+
model?: string;
|
|
5080
|
+
/** Tools, as MCP servers, handed to every session. */
|
|
5081
|
+
mcpServers?: Record<string, McpServerSpec>;
|
|
5082
|
+
}
|
|
5083
|
+
declare function registerCodingAgentCollection(sdk: SuperatomSDK, config?: CodingAgentCollectionConfig): void;
|
|
5084
|
+
|
|
4475
5085
|
/**
|
|
4476
5086
|
* ScriptMatcher — LLM-Based Script Matching + Parameter Extraction
|
|
4477
5087
|
*
|
|
@@ -4783,4 +5393,4 @@ declare class SuperatomSDK {
|
|
|
4783
5393
|
getConversationSimilarityThreshold(): number;
|
|
4784
5394
|
}
|
|
4785
5395
|
|
|
4786
|
-
export { type Action, type AgentConfig, type AgentResponse, BM25L, type BM25LOptions, type BaseLLMConfig, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, DEFAULT_AGENT_CONFIG, type DashboardAgentCollectionConfig, type DatabaseType, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, MainAgent, type Message, type ModelStrategy, type OutputField, type RerankedResult, STORAGE_CONFIG, type ScriptComponentSpec, ScriptMatcher, type ScriptParameter, type ScriptRecipe, type ScriptRecipeMetaRow, type ScriptRecipeStore, type ScriptResult, ScriptStore, type ScriptStoreOptions, type SelectedWorkflow, SuperatomSDK, type SuperatomSDKConfig, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, UIBlock, UILogCollector, type User, UserManager, type UsersData, type WorkflowDescriptor, anthropicLLM, dashboardConversationHistory, geminiLLM, groqLLM, hybridRerank, llmUsageLogger, logger, normalizeScriptBody, openaiLLM, queryCache, registerDashboardAgentCollection, rerankChromaResults, rerankConversationResults, resolveScriptRecipeStore, runScript, userPromptErrorLogger };
|
|
5396
|
+
export { type Action, type AgentConfig, type AgentEvent, type AgentResponse, type AgentRunContext, type AgentRunHandlers, type AgentRunRecord, type AgentRunResult, type AgentTrigger, type AgentUsage, type ApplySummary, BM25L, type BM25LOptions, type BaseLLMConfig, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CodexSessionOptions, type CodingAgentCollectionConfig, type CodingAgentDefinition, type CodingAgentSession, type CodingAgentSessionOptions, type CodingAgentsConfig, type CollectionHandler, type CollectionOperation, type DBUIBlock, DEFAULT_AGENT_CONFIG, type DashboardAgentCollectionConfig, type DatabaseType, type Harness, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, MainAgent, type McpServerSpec, type Message, type ModelStrategy, type OutputContract, type OutputField, type OutputValidator, type RerankedResult, type RunAgentOptions, STORAGE_CONFIG, type ScriptComponentSpec, ScriptMatcher, type ScriptParameter, type ScriptRecipe, type ScriptRecipeMetaRow, type ScriptRecipeStore, type ScriptResult, ScriptStore, type ScriptStoreOptions, type SelectedWorkflow, SuperatomSDK, type SuperatomSDKConfig, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, UIBlock, UILogCollector, type User, UserManager, type UsersData, type WorkflowDescriptor, type Workspace, anthropicLLM, assertReadOnlySql, createCodexSession, createCodingAgentSession, dashboardConversationHistory, describeTriggers, emitAgentEvent, geminiLLM, getCodingAgent, getCodingAgentsConfig, groqLLM, hybridRerank, listCodingAgents, llmUsageLogger, logger, normalizeScriptBody, onAgentRun, openaiLLM, queryCache, registerCodingAgentCollection, registerCodingAgents, registerDashboardAgentCollection, rerankChromaResults, rerankConversationResults, resolveScriptRecipeStore, runCodingAgent, runScript, startAgentTriggers, stopAgentTriggers, userPromptErrorLogger, writeBridgeShims };
|