sailfork 0.0.0-stage → 0.1.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/AGENTS.md +228 -0
- package/LICENSE +19 -0
- package/README.md +44 -2
- package/dist/index.cjs +3855 -0
- package/dist/index.js +3813 -0
- package/dist/tools.cjs +8513 -0
- package/dist/tools.js +8471 -0
- package/dist/types/core/agent.d.ts +2 -0
- package/dist/types/core/client.d.ts +19 -0
- package/dist/types/core/env.d.ts +2 -0
- package/dist/types/core/errors.d.ts +59 -0
- package/dist/types/core/sse.d.ts +3 -0
- package/dist/types/core/token.d.ts +7 -0
- package/dist/types/core/types.d.ts +65 -0
- package/dist/types/core/version.d.ts +2 -0
- package/dist/types/core/waits.d.ts +43 -0
- package/dist/types/generated/api.d.ts +1216 -0
- package/dist/types/generated/index.d.ts +5 -0
- package/dist/types/generated/ops.d.ts +1784 -0
- package/dist/types/generated/tools.d.ts +21 -0
- package/dist/types/generated/types.d.ts +4241 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/tools.d.ts +7 -0
- package/dist/types-cjs/core/agent.d.ts +2 -0
- package/dist/types-cjs/core/client.d.ts +19 -0
- package/dist/types-cjs/core/env.d.ts +2 -0
- package/dist/types-cjs/core/errors.d.ts +59 -0
- package/dist/types-cjs/core/sse.d.ts +3 -0
- package/dist/types-cjs/core/token.d.ts +7 -0
- package/dist/types-cjs/core/types.d.ts +65 -0
- package/dist/types-cjs/core/version.d.ts +2 -0
- package/dist/types-cjs/core/waits.d.ts +43 -0
- package/dist/types-cjs/generated/api.d.ts +1216 -0
- package/dist/types-cjs/generated/index.d.ts +5 -0
- package/dist/types-cjs/generated/ops.d.ts +1784 -0
- package/dist/types-cjs/generated/tools.d.ts +21 -0
- package/dist/types-cjs/generated/types.d.ts +4241 -0
- package/dist/types-cjs/index.d.ts +26 -0
- package/dist/types-cjs/package.json +1 -0
- package/dist/types-cjs/tools.d.ts +7 -0
- package/llms.txt +211 -0
- package/package.json +59 -5
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Core } from './core/client.js';
|
|
2
|
+
import type { ClientOptions } from './core/types.js';
|
|
3
|
+
import { type WaitAnswer, type WaitOptions, type WaitTarget } from './core/waits.js';
|
|
4
|
+
import { Org, Repo, type Resources } from './generated/api.js';
|
|
5
|
+
export interface Sailfork extends Resources {
|
|
6
|
+
}
|
|
7
|
+
export declare class Sailfork {
|
|
8
|
+
readonly core: Core;
|
|
9
|
+
constructor(options?: ClientOptions);
|
|
10
|
+
/** A repository by `owner/name`; its pull requests, issues and caissons hang off it. */
|
|
11
|
+
repo(name: string): Repo;
|
|
12
|
+
/** An org by handle. */
|
|
13
|
+
org(handle: string): Org;
|
|
14
|
+
/** Holds until a pull request, run, caisson, issue or held action reaches the state asked for, or `within` seconds pass. */
|
|
15
|
+
wait(target: WaitTarget, options?: WaitOptions): Promise<WaitAnswer>;
|
|
16
|
+
}
|
|
17
|
+
export default Sailfork;
|
|
18
|
+
export { Core } from './core/client.js';
|
|
19
|
+
export { detectAgent, detectSession } from './core/agent.js';
|
|
20
|
+
export { AgentPolicyError, AuthenticationError, ConflictError, ConnectionError, ERROR_CODES, InvalidRequestError, NotFoundError, PermissionError, RateLimitError, SailforkError, ServerError, TimeoutError, UnavailableForLegalReasonsError, } from './core/errors.js';
|
|
21
|
+
export type { ErrorCode, ErrorDetails } from './core/errors.js';
|
|
22
|
+
export type { ClientOptions, Done, Held as HeldOutcome, OpMeta, Page, Pager, RequestOptions, Result, StreamEvent } from './core/types.js';
|
|
23
|
+
export type { WaitAnswer, WaitOptions, WaitTarget } from './core/waits.js';
|
|
24
|
+
export { API_VERSION, VERSION } from './core/version.js';
|
|
25
|
+
export * from './generated/api.js';
|
|
26
|
+
export type * as types from './generated/types.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { anthropicTools, openaiTools } from './generated/tools.js';
|
|
2
|
+
import type { RequestOptions } from './core/types.js';
|
|
3
|
+
import { Sailfork } from 'sailfork';
|
|
4
|
+
export { anthropicTools, openaiTools };
|
|
5
|
+
export type { AnthropicTool, OpenAITool } from './generated/tools.js';
|
|
6
|
+
/** Runs the tool a model called, by its MCP name, with the tool's input. Uses `client`, else one built from the environment. */
|
|
7
|
+
export declare function run(name: string, input: Record<string, unknown>, client?: Sailfork, options?: RequestOptions): Promise<unknown>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ClientOptions, OpMeta, Pager, RequestOptions, Result, StreamEvent } from './types.js';
|
|
2
|
+
export declare class Core {
|
|
3
|
+
#private;
|
|
4
|
+
readonly host: string;
|
|
5
|
+
constructor(options?: ClientOptions);
|
|
6
|
+
request<T>(op: OpMeta & {
|
|
7
|
+
held: false;
|
|
8
|
+
}, params: Record<string, unknown>, opts?: RequestOptions): Promise<T>;
|
|
9
|
+
request<T>(op: OpMeta & {
|
|
10
|
+
held: true;
|
|
11
|
+
}, params: Record<string, unknown>, opts?: RequestOptions): Promise<Result<T>>;
|
|
12
|
+
request<T>(op: OpMeta, params: Record<string, unknown>, opts?: RequestOptions): Promise<T | Result<T>>;
|
|
13
|
+
paginate<T>(op: OpMeta, params: Record<string, unknown>, opts?: RequestOptions): Pager<T>;
|
|
14
|
+
/** Follows a server-sent event route, reconnecting from the last event id on a dropped connection until the server sends `end`, the caller stops or aborts. */
|
|
15
|
+
stream<T = unknown>(op: OpMeta, params: Record<string, unknown>, opts?: RequestOptions): AsyncGenerator<StreamEvent<T>>;
|
|
16
|
+
/** Reads a newline-delimited JSON route as it arrives. */
|
|
17
|
+
ndjson<T = unknown>(op: OpMeta, params: Record<string, unknown>, opts?: RequestOptions): AsyncGenerator<T>;
|
|
18
|
+
}
|
|
19
|
+
export type { OpMeta, RequestOptions, Result };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const ERROR_CODES: readonly ['invalid_request', 'unauthenticated', 'invalid_token', 'insufficient_scope', 'forbidden', 'not_found', 'conflict', 'file_changed', 'idempotency_in_progress', 'precondition_failed', 'payload_too_large', 'unsupported_media_type', 'rate_limited', 'internal', 'unavailable', 'busy', 'agent_policy', 'agent_change_cap', 'held_declined', 'bypass_needs_person', 'suspended', 'blocked', 'private_fork_stays_private', 'private_forks_off', 'private_fork_outside_org', 'sso_deactivated', 'sso_invite', 'sso_name_taken', 'sso_account_linked', 'sso_expired', 'disabled', 'region_blocked'];
|
|
2
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
3
|
+
export type ErrorDetails = {
|
|
4
|
+
status: number;
|
|
5
|
+
code: ErrorCode | (string & Record<never, never>);
|
|
6
|
+
message: string;
|
|
7
|
+
hint?: string | undefined;
|
|
8
|
+
param?: string | undefined;
|
|
9
|
+
requestId?: string | undefined;
|
|
10
|
+
docUrl?: string | undefined;
|
|
11
|
+
retryAfter?: number | undefined;
|
|
12
|
+
body?: unknown;
|
|
13
|
+
};
|
|
14
|
+
export declare class SailforkError extends Error {
|
|
15
|
+
readonly status: number;
|
|
16
|
+
readonly code: ErrorDetails['code'];
|
|
17
|
+
readonly hint: string | undefined;
|
|
18
|
+
readonly param: string | undefined;
|
|
19
|
+
readonly requestId: string | undefined;
|
|
20
|
+
readonly docUrl: string | undefined;
|
|
21
|
+
readonly retryAfter: number | undefined;
|
|
22
|
+
readonly body: unknown;
|
|
23
|
+
constructor(details: ErrorDetails);
|
|
24
|
+
toString(): string;
|
|
25
|
+
}
|
|
26
|
+
/** The request never got an answer: DNS, connection, TLS or a body that ended early. */
|
|
27
|
+
export declare class ConnectionError extends SailforkError {
|
|
28
|
+
constructor(message: string, cause?: unknown);
|
|
29
|
+
}
|
|
30
|
+
/** The call ran past its `timeout`. A caller's own `signal` aborting throws that signal's reason instead. */
|
|
31
|
+
export declare class TimeoutError extends SailforkError {
|
|
32
|
+
constructor(ms: number);
|
|
33
|
+
}
|
|
34
|
+
/** 422, 413, 415: the request did not fit the operation. */
|
|
35
|
+
export declare class InvalidRequestError extends SailforkError {
|
|
36
|
+
}
|
|
37
|
+
/** 401: no token, or one the server does not know. */
|
|
38
|
+
export declare class AuthenticationError extends SailforkError {
|
|
39
|
+
}
|
|
40
|
+
/** 403 with a code a caller cannot fix by retrying: scope, suspension, SSO, fork rules. */
|
|
41
|
+
export declare class PermissionError extends SailforkError {
|
|
42
|
+
}
|
|
43
|
+
/** 403 or 402 from an organization's agent rules: policy, change cap, a declined hold, a merge only a person makes. */
|
|
44
|
+
export declare class AgentPolicyError extends SailforkError {
|
|
45
|
+
}
|
|
46
|
+
export declare class NotFoundError extends SailforkError {
|
|
47
|
+
}
|
|
48
|
+
/** 409 and 412: the thing changed under the call, or its idempotency key is still running. */
|
|
49
|
+
export declare class ConflictError extends SailforkError {
|
|
50
|
+
}
|
|
51
|
+
export declare class RateLimitError extends SailforkError {
|
|
52
|
+
}
|
|
53
|
+
/** 5xx. */
|
|
54
|
+
export declare class ServerError extends SailforkError {
|
|
55
|
+
}
|
|
56
|
+
/** 451: taken down, or blocked in the caller's region. */
|
|
57
|
+
export declare class UnavailableForLegalReasonsError extends SailforkError {
|
|
58
|
+
}
|
|
59
|
+
export declare function errorFromResponse(status: number, body: unknown, headers: Headers, retryAfter: number | undefined): SailforkError;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { StreamEvent } from './types.js';
|
|
2
|
+
export declare function sseEvents(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
|
|
3
|
+
export declare function ndjsonLines(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<unknown>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const DEFAULT_HOST = "https://sailfork.com";
|
|
2
|
+
/** Mirrors `normalize_host` in crates/client/src/config.rs: an origin from what a person types. */
|
|
3
|
+
export declare function normalizeHost(input: string): string | undefined;
|
|
4
|
+
/** The host the client talks to unless told otherwise, and the only one `SAILFORK_TOKEN` may go to. */
|
|
5
|
+
export declare function envHost(): string;
|
|
6
|
+
/** The option, then `SAILFORK_TOKEN` for the env host only, then the CLI's stored token for `host`. */
|
|
7
|
+
export declare function resolveToken(host: string, option: string | undefined): Promise<string | undefined>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type OpMeta = {
|
|
2
|
+
id: string;
|
|
3
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
4
|
+
path: string;
|
|
5
|
+
pathParams: readonly string[];
|
|
6
|
+
queryParams: readonly string[];
|
|
7
|
+
bodyParams: readonly string[];
|
|
8
|
+
effect: 'read' | 'write' | 'delete';
|
|
9
|
+
retry: 'safe' | 'idempotent' | 'none';
|
|
10
|
+
held: boolean;
|
|
11
|
+
long: boolean;
|
|
12
|
+
paginated: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type Held = {
|
|
15
|
+
status: 'held';
|
|
16
|
+
/** The id of the held action. */
|
|
17
|
+
held: string;
|
|
18
|
+
/** Where a person decides it, as an absolute URL. */
|
|
19
|
+
url: string;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
export type Done<T> = {
|
|
23
|
+
status: 'done';
|
|
24
|
+
value: T;
|
|
25
|
+
};
|
|
26
|
+
/** What an operation that may be held for a person answers. */
|
|
27
|
+
export type Result<T> = Done<T> | Held;
|
|
28
|
+
export type Page<T> = {
|
|
29
|
+
items: T[];
|
|
30
|
+
/** Pass as `cursor` to read the next page; null on the last one. */
|
|
31
|
+
nextCursor: string | null;
|
|
32
|
+
};
|
|
33
|
+
export type Pager<T> = AsyncIterable<T> & {
|
|
34
|
+
page(): Promise<Page<T>>;
|
|
35
|
+
};
|
|
36
|
+
export type RequestOptions = {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
/** Milliseconds until the call fails with `TimeoutError`. Defaults to 60 s, 5 min for long operations. */
|
|
39
|
+
timeout?: number;
|
|
40
|
+
/** Overrides the client's retry count for this call. */
|
|
41
|
+
maxRetries?: number;
|
|
42
|
+
/** Use a key you already hold, to resume a call a crashed process began. */
|
|
43
|
+
idempotencyKey?: string;
|
|
44
|
+
headers?: Record<string, string>;
|
|
45
|
+
};
|
|
46
|
+
export type ClientOptions = {
|
|
47
|
+
/** Defaults to `SAILFORK_TOKEN`, then `sailfork auth token` when the CLI is installed. */
|
|
48
|
+
token?: string;
|
|
49
|
+
/** Defaults to `SAILFORK_HOST`, `SAILFORK_URL`, then https://sailfork.com. */
|
|
50
|
+
host?: string;
|
|
51
|
+
/** Defaults to 2. */
|
|
52
|
+
maxRetries?: number;
|
|
53
|
+
fetch?: typeof fetch;
|
|
54
|
+
/** The coding agent driving this client, or false to send none. Defaults to what the environment names. */
|
|
55
|
+
agent?: string | false;
|
|
56
|
+
/** The id of this run of the agent. Defaults to what the environment names. */
|
|
57
|
+
session?: string;
|
|
58
|
+
headers?: Record<string, string>;
|
|
59
|
+
};
|
|
60
|
+
export type StreamEvent<T = unknown> = {
|
|
61
|
+
/** The server's event id, resumed from with `Last-Event-ID`. */
|
|
62
|
+
id: string | undefined;
|
|
63
|
+
event: string;
|
|
64
|
+
data: T;
|
|
65
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Core } from './client.js';
|
|
2
|
+
import type { RequestOptions } from './types.js';
|
|
3
|
+
export type WaitTarget = {
|
|
4
|
+
kind: 'pull';
|
|
5
|
+
owner: string;
|
|
6
|
+
repo: string;
|
|
7
|
+
number: number;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'run';
|
|
10
|
+
owner: string;
|
|
11
|
+
repo: string;
|
|
12
|
+
id: number;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'caisson';
|
|
15
|
+
owner: string;
|
|
16
|
+
id: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'issue';
|
|
19
|
+
owner: string;
|
|
20
|
+
repo: string;
|
|
21
|
+
number: number;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'held';
|
|
24
|
+
owner: string;
|
|
25
|
+
id: string;
|
|
26
|
+
};
|
|
27
|
+
export type WaitAnswer = {
|
|
28
|
+
/** `met`, `failed`, `pending` (the wait ran out), or `none` (nothing to wait for, such as no CI configured). */
|
|
29
|
+
state: 'met' | 'failed' | 'pending' | 'none';
|
|
30
|
+
detail: string;
|
|
31
|
+
condition: string;
|
|
32
|
+
value: unknown;
|
|
33
|
+
/** What the server compares the next window against; passed back automatically. */
|
|
34
|
+
baseline?: unknown;
|
|
35
|
+
};
|
|
36
|
+
export type WaitOptions = RequestOptions & {
|
|
37
|
+
/** `checks`, `merged`, `reviewed`, `conflicts` or `pushed` for a pull request; the state to reach for a caisson or issue. */
|
|
38
|
+
until?: string;
|
|
39
|
+
/** Seconds to wait in all before answering `pending`. Defaults to 600. */
|
|
40
|
+
within?: number;
|
|
41
|
+
};
|
|
42
|
+
/** Calls `POST /api/waits` until the answer is not `pending`, carrying the server's baseline across windows. */
|
|
43
|
+
export declare function wait(core: Core, target: WaitTarget, options?: WaitOptions): Promise<WaitAnswer>;
|