contextos-client 0.1.0-alpha.12 → 0.1.0-alpha.14

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 CHANGED
@@ -27,6 +27,17 @@ Results that are not plain success throw: `ToolPaused` (approval, input, or an u
27
27
  outcome to reconcile: never retry blindly), `ToolBlocked`, `ToolRejected`,
28
28
  `ToolFailed`. Only requests the server did not process (429, 503) are retried.
29
29
 
30
+ `run.checkToolCall(capabilityId, args, options)` answers what `callTool` would do with
31
+ the same call (`allowed`, `approval_required`, `escalation_required`, `blocked` or
32
+ `rejected`, with reason codes and obligations) without effect: nothing is requested,
33
+ reserved or sent, and the check is audited. It is advisory; `not_evaluated` names what
34
+ only dispatch decides.
35
+
36
+ `client.plan(packRef, runContext, { intent })` (`compile` scope) answers, before any
37
+ request, what a pack lets that principal do: each rule applies `always`, or `when` /
38
+ `unless` a residual condition over `request.*` holds. `client.reloadPacks()` (`control`
39
+ scope) has the server re-read its pack sources and add new versions.
40
+
30
41
  Try it against a local server from a checkout: `./examples/dev-server.sh` prints
31
42
  `CONTEXTOS_URL` and `CONTEXTOS_TOKEN`. The
32
43
  [integration guides](https://github.com/contextosai/ContextOS/tree/main/docs/integrations)
package/client.d.ts CHANGED
@@ -1,3 +1,18 @@
1
+ /** The answer of `Run.checkToolCall`. */
2
+ export interface ToolCallCheck {
3
+ status: "allowed" | "approval_required" | "escalation_required" | "blocked" | "rejected";
4
+ capability_id: Json;
5
+ operation_id: string | null;
6
+ action_digest: string | null;
7
+ reason_codes: string[];
8
+ obligations: string[];
9
+ message: string | null;
10
+ /** The run already has an operation with this id: dispatch treats the call as its retry. */
11
+ operation_exists: boolean;
12
+ not_evaluated: ("budget_reservation" | "operation_claim" | "shared_guarantee_capacity")[];
13
+ audit_sequence: number;
14
+ }
15
+
1
16
  export declare const GENERATION_HEADER: "ContextOS-Executor-Generation";
2
17
 
3
18
  export type ApprovalMode = "read_only" | "local_write" | "network" | "delegated" | "destructive";
@@ -124,6 +139,35 @@ export interface CallOptions {
124
139
  toolCallId?: string;
125
140
  }
126
141
 
142
+ export interface PlannedRule {
143
+ bundle_id: string;
144
+ priority: number;
145
+ rule_id: string;
146
+ branch: "then" | "else";
147
+ effect: "allow" | "require_approval" | "deny";
148
+ approval_gate?: string;
149
+ obligations: string[];
150
+ prohibits: string[];
151
+ applies: "always" | "when" | "unless";
152
+ /** Residual JsonLogic over `request.*`, for `when` and `unless`. */
153
+ condition?: Json;
154
+ }
155
+
156
+ export interface DecisionPlan {
157
+ intent: string;
158
+ verdict: "deny" | "escalate" | "require_approval" | "allow" | "conditional";
159
+ possible_verdicts: string[] | null;
160
+ conditions: Json[];
161
+ rules: PlannedRule[];
162
+ }
163
+
164
+ export interface PackReload {
165
+ added: { pack_ref: string; tenant_id: string; sha256: string; path: string }[];
166
+ refused: { path: string; pack_ref?: string; tenant_id?: string; reason: "invalid" | "pack_ref_immutable" | "tenant_not_configured"; detail: string }[];
167
+ unchanged: number;
168
+ other: { added: number; refused: number };
169
+ }
170
+
127
171
  export declare class Client {
128
172
  constructor(baseUrl: string, options: { token: string; timeoutMs?: number; maxRetries?: number; fetch?: typeof fetch; checkServer?: boolean });
129
173
  /** Reads GET /v1/deployment: throws IncompatibleServer on another API generation, warns on another release. Runs once before the first admit. */
@@ -149,6 +193,10 @@ export declare class Client {
149
193
  revoke(kind: RevocationKind, target: string, reason: string): Promise<Revocations>;
150
194
  restore(kind: RevocationKind, target: string, reason: string): Promise<Revocations>;
151
195
  revocations(): Promise<Revocations>;
196
+ /** What a pack lets the run context's principal do for an intent, before any request (`compile`). */
197
+ plan(packRef: string, runContext: Json, options?: { intent?: string }): Promise<DecisionPlan>;
198
+ /** Re-reads the server's pack sources and adds new pack versions (`control`). */
199
+ reloadPacks(): Promise<PackReload>;
152
200
  auditEntries(options?: { from?: number; page?: number }): AsyncGenerator<Record<string, Json>>;
153
201
  }
154
202
 
@@ -197,6 +245,8 @@ export declare class Run {
197
245
  readonly principalChain: { kind: string; id: string }[];
198
246
  envelope(capabilityId: string, args: Record<string, Json>, options?: CallOptions): Record<string, Json>;
199
247
  callTool(capabilityId: string, args: Record<string, Json>, options?: CallOptions): Promise<Record<string, Json>>;
248
+ /** What callTool would do with this call, without effect; audited and advisory. */
249
+ checkToolCall(capabilityId: string, args: Record<string, Json>, options?: CallOptions): Promise<ToolCallCheck>;
200
250
  provideInput(paused: ToolPaused, envelope: Record<string, Json>, responses: Record<string, Json>): Promise<Record<string, Json>>;
201
251
  reconcile(operationId: string, options?: { outcome?: "confirmed" | "not_applied" | "partial"; evidenceRef?: Record<string, string> }): Promise<any>;
202
252
  /** Relays an outcome witness's signed reading (compact JWS); needs `outcome:report`. */
package/client.mjs CHANGED
@@ -18,7 +18,7 @@ export const RUN_HEADER = "ContextOS-Run-Id";
18
18
  export const RESERVATION_HEADER = "ContextOS-Usage-Reservation";
19
19
  // This client's release (scripts/package_clients.py checks it against Cargo.toml) and
20
20
  // the HTTP API generation it speaks; a server reports both in GET /v1/deployment.
21
- export const CLIENT_VERSION = "0.1.0-alpha.12";
21
+ export const CLIENT_VERSION = "0.1.0-alpha.14";
22
22
  export const API_VERSION = "v1";
23
23
 
24
24
  /** The server speaks a different HTTP API generation than this client. */
@@ -270,6 +270,22 @@ export class Client {
270
270
  return this.request("GET", "/v1/revocations");
271
271
  }
272
272
 
273
+ /**
274
+ * What `packRef` lets the run context's principal do for an intent before any request
275
+ * (`compile` scope): each rule applies `always`, or `when` / `unless` a residual
276
+ * condition over `request.*` holds, with the verdicts those conditions can reach.
277
+ */
278
+ async plan(packRef, runContext, { intent } = {}) {
279
+ const body = { pack_ref: packRef, run_context: runContext };
280
+ if (intent !== undefined) body.intent = intent;
281
+ return (await this.request("POST", "/v1/plan", { body })).plan;
282
+ }
283
+
284
+ /** Re-reads the server's pack sources and adds new pack versions (`control` scope). */
285
+ reloadPacks() {
286
+ return this.request("POST", "/v1/packs/reload");
287
+ }
288
+
273
289
  /** Yields the tenant's signed audit entries in order. */
274
290
  async *auditEntries({ from = 1, page = 500 } = {}) {
275
291
  let cursor = from;
@@ -313,6 +329,16 @@ export class Run {
313
329
  return outcome(response);
314
330
  }
315
331
 
332
+ /**
333
+ * What callTool would do with this call, without effect (`status`: allowed,
334
+ * approval_required, escalation_required, blocked or rejected). Nothing is requested,
335
+ * reserved or claimed; the check is audited. Advisory: `not_evaluated` names what only
336
+ * dispatch decides.
337
+ */
338
+ async checkToolCall(capabilityId, args, options = {}) {
339
+ return (await this.#post("/tool-calls/check", this.envelope(capabilityId, args, options))).check;
340
+ }
341
+
316
342
  async provideInput(paused, envelope, responses) {
317
343
  return outcome(await this.#post(`/operations/${segment(paused.operationId ?? "")}/input`,
318
344
  { tool_call: envelope, input_responses: responses }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contextos-client",
3
- "version": "0.1.0-alpha.12",
3
+ "version": "0.1.0-alpha.14",
4
4
  "description": "HTTP client for contextosd: govern an AI agent's tool calls. No dependencies.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {