-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
205 lines (184 loc) · 7.01 KB
/
Copy pathindex.d.ts
File metadata and controls
205 lines (184 loc) · 7.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import { EventEmitter } from 'events';
/** Max length of a param description (chars). */
export const PARAM_DESC_MAX: number;
/** Inferred param type from runtime signature analysis. */
export type ParamType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'unknown';
/** A single declared parameter. */
export class Param {
name: string;
type: ParamType | string;
description: string;
required: boolean;
constructor(opts: string | {
name: string;
type?: string;
description?: string;
required?: boolean;
});
toJSON(): { name: string; type: string; description: string; required: boolean };
/** Wire form: a `[name, type]` tuple — what the server's RunRequest expects. */
toWire(): [string, string];
}
/**
* One param declaration. `name` is required and the array order is the
* positional arg order passed to `call`. `type` is optional — omit it and it's
* inferred from the `call` signature at runtime. `description` is capped at
* PARAM_DESC_MAX chars.
*/
export interface ParamSpec {
name: string;
type?: ParamType | string;
description?: string;
required?: boolean;
}
/** Ordered param declarations. */
export type ParamList = Array<ParamSpec | Param>;
/** Parse a function's signature into ordered params with inferred types. */
export function parseSignature(fn: Function): Array<{
name: string;
type: ParamType | string;
rest: boolean;
destructured: boolean;
}>;
/** Build catalog Param[] — order from `spec`, missing types inferred from `fn`. */
export function normalizeParams(spec?: ParamList | string, fn?: Function): Param[];
/** Successful tool output. Internal wrapper — `call` returns plain values. */
export class ToolResult {
value: any;
meta: Record<string, any>;
constructor(value: any, meta?: Record<string, any>);
static of(value: any, meta?: Record<string, any>): ToolResult;
toJSON(): { ok: true; value: any; meta: Record<string, any> };
}
/** Tool failure. Internal wrapper for a throw out of `call`. */
export class ToolError extends Error {
category: string;
cause?: any;
constructor(message: string, opts?: { category?: string; cause?: any });
toJSON(): { ok: false; category: string; message: string };
}
/**
* Node.js port of the Driver `Tool` trait. Subclass and override, or build one
* with `defineTool`.
*/
export class Tool {
/** Fully-qualified id, conventionally `module.member` (e.g. `fs.read_file`). */
name(): string;
/** One-line description shown in the catalog — the only thing the LLM sees. */
description(): string;
/** Ordered params `[{ name, type?, description? }]`. Types inferred from `call`. */
params(): ParamList;
/** Execute. Positional args spread in; return any plain value. May be async. */
call(...args: any[]): any;
/** Catalog entry sent to the cloud. `params` are `[name, type]` tuples. */
toJSON(): { name: string; description: string; params: Array<[string, string]> };
/** Run `call`, normalizing the return/throw. Never rejects. */
callSafe(args?: any[]): Promise<ToolResult | ToolError>;
}
/** Build a Tool from a plain spec — no class, no wrapping. */
export function defineTool(spec: {
name: string;
description?: string;
params?: ParamList;
call: (...args: any[]) => any;
}): Tool;
export interface DataPayload {
var: string;
label: string;
value: string;
}
/** Opaque tool category exposed on `action` events (no internal tool id). */
export type ToolCategory =
| 'filesystem'
| 'http fetching'
| 'web'
| 'integration'
| 'network'
| 'compute';
/** Error category exposed on `fatal` events (raw message is hidden). */
export type FatalCategory = 'provider' | 'decode' | 'tool' | 'engine';
/**
* Flat, JSON-friendly event streamed from Driver cloud. `kind` is always set;
* the remaining fields are present only for the variants that carry them.
*
* Only five kinds are emitted: `plan`, `plan_item_start`, `action`, `done`,
* `fatal`. Internal details (raw tool ids, action args, raw error messages) are
* never exposed.
*/
export interface AgentEvent {
kind: 'plan' | 'plan_item_start' | 'action' | 'done' | 'fatal' | string;
/** plan: the list of subtasks (text). */
items?: string[];
/** plan_item_start: index of the item that started. */
num?: number;
/** plan_item_start: the item text. */
def?: string;
/** action: opaque tool category (not the internal tool id). */
tool?: ToolCategory | string;
/** action: whether the tool touches the network. */
is_network?: boolean;
/** done: the final answer. */
result?: string;
/** done: structured output payloads. */
data?: DataPayload[];
/** done: error count over the run. */
errors?: number;
/** done: step count over the run. */
steps?: number;
/** fatal: error category only; closes the stream. */
semantic?: FatalCategory | string;
}
export interface DriverOptions {
/** The `dr_…` API key (machine credential). Falls back to DRIVER_API_KEY. */
apiKey?: string;
/** Cloud base URL. Defaults to https://driver.tors.app or DRIVER_BASE_URL. */
baseUrl?: string;
/** Custom fetch implementation. Defaults to global fetch (Node 18+). */
fetch?: typeof fetch;
/** Default tools sent with every `run`. A per-run `tools` overrides this. */
tools?: Array<Tool | object>;
/**
* Request zero data retention for every run by default; a per-run `zdr`
* overrides it. Requires the account entitlement (403 otherwise).
*/
zdr?: boolean;
}
export interface RunOptions {
/** Per-event callback, invoked for every AgentEvent. */
onEvent?: (ev: AgentEvent) => void;
/** Abort the SSE stream early. */
signal?: AbortSignal;
/** Tools for this run; overrides constructor `tools`. */
tools?: Array<Tool | object>;
/**
* Zero data retention for THIS run; overrides the constructor default. The
* cloud stores nothing the execution sees: no prompt, no event log, no
* outputs. Events stream to this client and die here. Requires the account
* entitlement; without it the run fails with 403.
*/
zdr?: boolean;
}
/**
* Node.js client for Driver cloud.
*
* Events surface as an EventEmitter (`on('event', …)` firehose, `on('action', …)`,
* `on('done', …)`, … per kind) and as a Promise (`run` resolves with `done`).
*/
export class Driver extends EventEmitter {
apiKey: string;
baseUrl: string;
tools: Array<Tool | object>;
zdr: boolean;
constructor(opts?: DriverOptions);
run(prompt: string, opts?: RunOptions): Promise<AgentEvent | null>;
/** Sugar for `run(prompt, { zdr: true })`: zero-data-retention run. */
runZdr(prompt: string, opts?: Omit<RunOptions, 'zdr'>): Promise<AgentEvent | null>;
on(event: 'event', listener: (ev: AgentEvent) => void): this;
on(event: 'plan', listener: (ev: AgentEvent) => void): this;
on(event: 'plan_item_start', listener: (ev: AgentEvent) => void): this;
on(event: 'action', listener: (ev: AgentEvent) => void): this;
on(event: 'done', listener: (ev: AgentEvent) => void): this;
on(event: 'fatal', listener: (ev: AgentEvent) => void): this;
on(event: string, listener: (ev: AgentEvent) => void): this;
}
export default Driver;