@agent-change-requests/client 0.0.0-stage → 0.3.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.
@@ -0,0 +1,205 @@
1
+ import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import type { ClientCapabilities } from "@modelcontextprotocol/sdk/types.js";
3
+ import { type Ledger, type LedgerEntry } from "./ledger.js";
4
+ import { type RedactOptions, type RedactionFinding } from "./redact.js";
5
+ import { type ConfirmParams, type ServerSettings, type Status, type StatusObject, type SubmitParams, type SubmitResult } from "./types.js";
6
+ export declare const CLIENT_CAPABILITIES_META_KEY = "io.modelcontextprotocol/clientCapabilities";
7
+ export interface ConsentOptions {
8
+ /** True only when the user or operator turned the extension on for this server. */
9
+ consent: boolean | (() => boolean);
10
+ /** An ephemeral or incognito session. Nothing overrides it: no advertising, no submissions. */
11
+ ephemeral?: boolean;
12
+ }
13
+ export interface ChangeRequestsClientOptions extends ConsentOptions {
14
+ /** The identifier the server advertises, e.g. "com.example/change-requests". */
15
+ extensionId: string;
16
+ /** A name for the server in the tool description the model sees. */
17
+ serverName?: string;
18
+ /** Most submissions to this server per UTC day. Default 5. */
19
+ dailyCap?: number;
20
+ redaction?: RedactOptions;
21
+ /**
22
+ * Called before each submission with the redacted request and where redaction fired.
23
+ * Return false to cancel, or a revised request. Use it to let the user review.
24
+ * Called on every submission when reviewAll is true, otherwise only when a rule fired.
25
+ */
26
+ review?: (draft: SubmitParams, findings: RedactionFinding[]) => boolean | SubmitParams | Promise<boolean | SubmitParams>;
27
+ reviewAll?: boolean;
28
+ /** Where requests are remembered between sessions. Default: in memory. */
29
+ ledger?: Ledger;
30
+ /** Called once per newly shipped request whose workaround is now obsolete. */
31
+ onShipped?: (status: StatusObject, entry: LedgerEntry) => void | Promise<void>;
32
+ /** Name of the model-facing submission tool. Default file_change_request. */
33
+ toolName?: string;
34
+ /**
35
+ * The inbox tool a client-built notice line names (SEP section 7). It must be a tool the
36
+ * model can call. Default: the server's change_requests_list, used only when the server
37
+ * lists it. Set it when the host gives the model its own inbox tool.
38
+ */
39
+ inboxToolName?: string;
40
+ /**
41
+ * The changes tool a client-built changes line names (SEP section 12). Default: the
42
+ * server's whats_new, used only when the server lists it.
43
+ */
44
+ whatsNewToolName?: string;
45
+ now?: () => Date;
46
+ }
47
+ export type SubmitOutcome = {
48
+ submitted: true;
49
+ result: SubmitResult;
50
+ findings: RedactionFinding[];
51
+ } | {
52
+ submitted: false;
53
+ reason: "already_filed";
54
+ requestId: string;
55
+ status: Status;
56
+ } | {
57
+ submitted: false;
58
+ reason: "cancelled" | "daily_cap" | "not_enabled" | "kind_unsupported";
59
+ };
60
+ export interface InboxCheck {
61
+ /** Requests whose status changed since the last check. */
62
+ updated: StatusObject[];
63
+ /** Of those, the ones that shipped with workaroundObsolete true. */
64
+ shipped: StatusObject[];
65
+ }
66
+ export interface Inspection<R> {
67
+ /** The update count the server announced, 0 when none. */
68
+ updates: number;
69
+ /** The result, with the notice line removed when this client must not act on it. */
70
+ result: R;
71
+ /** Present when the client read its inbox because of the notice. */
72
+ inbox?: InboxCheck;
73
+ /** The notice line the model should see, or null (SEP section 7). */
74
+ notice: string | null;
75
+ /** The unread changes count the server announced, 0 when none (SEP section 12). */
76
+ changes: number;
77
+ /** The changes line the model should see, or null (SEP section 12). */
78
+ changesNotice: string | null;
79
+ /** What to show the model for this result. See ChangeRequestsClient.modelContent(). */
80
+ modelContent: {
81
+ type: "text";
82
+ text: string;
83
+ }[];
84
+ }
85
+ /** A tool result as a client receives it. */
86
+ export interface ToolResultLike {
87
+ content?: unknown[];
88
+ structuredContent?: unknown;
89
+ _meta?: Record<string, unknown>;
90
+ [key: string]: unknown;
91
+ }
92
+ /** The fixed line a client adds from the _meta count. It carries no request content. */
93
+ export declare function updateNoticeLine(count: number, inboxTool: string): string;
94
+ /** The fixed changes line a client adds from the _meta count. It carries no change content. */
95
+ export declare function changesNoticeLine(count: number, changesTool: string): string;
96
+ /** The capabilities to pass to new Client(): the extension is advertised only when allowed. */
97
+ export declare function changeRequestsCapabilities(extensionId: string, consent: ConsentOptions, base?: ClientCapabilities): ClientCapabilities;
98
+ export declare class ChangeRequestsClient {
99
+ readonly extensionId: string;
100
+ private readonly client;
101
+ private readonly options;
102
+ private readonly ledger;
103
+ private readonly now;
104
+ private serverToolNames;
105
+ constructor(client: Client, options: ChangeRequestsClientOptions);
106
+ /** The server's settings for the extension, or null when it does not advertise it. */
107
+ settings(): ServerSettings | null;
108
+ /** Consent given, not ephemeral, and the server supports the extension. */
109
+ enabled(): boolean;
110
+ /** The one submission tool to show the model. Its description is the client's, not the server's. */
111
+ submissionTool(): {
112
+ name: string;
113
+ description: string;
114
+ inputSchema: Record<string, unknown>;
115
+ };
116
+ /** Runs the submission tool for the model and returns a tool result for it. */
117
+ callSubmissionTool(args: Record<string, unknown>): Promise<{
118
+ content: {
119
+ type: "text";
120
+ text: string;
121
+ }[];
122
+ isError?: boolean;
123
+ }>;
124
+ /**
125
+ * Submits a request after the client-side checks: consent, kind, daily cap,
126
+ * not already filed for the same target, redaction, and review.
127
+ */
128
+ submit(input: SubmitParams): Promise<SubmitOutcome>;
129
+ /** Reads one request. Passes the ledger's ticket for a request filed anonymously. */
130
+ get(requestId: string): Promise<StatusObject>;
131
+ /**
132
+ * For requests filed anonymously, which have no inbox: reads each open one by its
133
+ * ticket and returns what changed, like checkInbox(). Shipped requests with an obsolete
134
+ * workaround are marked in the ledger and passed to onShipped.
135
+ */
136
+ checkTickets(): Promise<InboxCheck>;
137
+ list(query?: {
138
+ status?: Status[];
139
+ updatedSince?: string;
140
+ cursor?: string;
141
+ }): Promise<{
142
+ requests: StatusObject[];
143
+ nextCursor?: string;
144
+ }>;
145
+ withdraw(requestId: string): Promise<StatusObject>;
146
+ confirm(params: ConfirmParams): Promise<StatusObject>;
147
+ /**
148
+ * Looks at any result from this server. When it announces updates and the client may
149
+ * act on them, reads the inbox. When the client must not act (no consent, ephemeral),
150
+ * removes the notice line so the model never sees it (SEP section 9). Also returns the
151
+ * notice line and the content to show the model, as modelContent() does.
152
+ */
153
+ inspect<R extends ToolResultLike>(result: R): Promise<Inspection<R>>;
154
+ /**
155
+ * The update notice line the model should see for this result, or null (SEP section 7).
156
+ * Null when the client must withhold the notice (no consent, ephemeral: section 9) or no
157
+ * update is announced. Reuses the server's own line when the text carries one. Otherwise
158
+ * builds the fixed line from the _meta count, naming inboxToolName, or the server's
159
+ * change_requests_list when the server lists it. The line never carries request content.
160
+ */
161
+ noticeLine(result: ToolResultLike): Promise<string | null>;
162
+ /**
163
+ * What a host should show the model for a tool result. A host that shows the model a
164
+ * tool's structuredContent in place of its text drops the server's notice line, so the
165
+ * duty to carry it falls on the client (SEP section 7). This returns the structured
166
+ * content as JSON text followed by the notice line, or, for a result without structured
167
+ * content, its text with the notice line removed when the client must withhold it.
168
+ */
169
+ modelContent(result: ToolResultLike): Promise<{
170
+ type: "text";
171
+ text: string;
172
+ }[]>;
173
+ /**
174
+ * The changes line the model should see for this result, or null (SEP section 12). It
175
+ * follows the rules for the update line: withheld without consent or in an ephemeral
176
+ * session, the server's own line when present, otherwise built from _meta.changes
177
+ * naming whatsNewToolName or the server's whats_new when the server lists it.
178
+ */
179
+ changesNoticeLine(result: ToolResultLike): Promise<string | null>;
180
+ private render;
181
+ /** The unread changes count a result announces, from _meta or else from the text line. */
182
+ private announcedChanges;
183
+ /** The update count a result announces, from _meta or else from the text line. */
184
+ private announced;
185
+ private serverHasTool;
186
+ /**
187
+ * Reads the inbox and returns what changed since the client last looked. Shipped
188
+ * requests with an obsolete workaround are marked in the ledger and passed to onShipped.
189
+ */
190
+ checkInbox(): Promise<InboxCheck>;
191
+ /**
192
+ * Re-runs the acceptance tests this client sent with a shipped request, under its own
193
+ * authorization, and confirms with the per-test outcomes.
194
+ */
195
+ retestAndConfirm(requestId: string, note?: string): Promise<{
196
+ outcome: "pass" | "fail";
197
+ status: StatusObject;
198
+ }>;
199
+ /** What the ledger knows, for showing the user or a later session. */
200
+ entries(): LedgerEntry[];
201
+ private call;
202
+ /** An open request of this client's for the same target, checked against the server. */
203
+ private findOpen;
204
+ private remember;
205
+ }