@shardlink/agent-sdk 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/LICENSE +202 -0
- package/README.md +129 -0
- package/dist/client-quick-join.d.ts +38 -0
- package/dist/client-quick-join.d.ts.map +1 -0
- package/dist/client-quick-join.js +141 -0
- package/dist/client-quick-join.js.map +1 -0
- package/dist/client.d.ts +134 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +190 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +126 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +330 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/a2a.d.ts +42 -0
- package/dist/modules/a2a.d.ts.map +1 -0
- package/dist/modules/a2a.js +47 -0
- package/dist/modules/a2a.js.map +1 -0
- package/dist/modules/agents.d.ts +100 -0
- package/dist/modules/agents.d.ts.map +1 -0
- package/dist/modules/agents.js +85 -0
- package/dist/modules/agents.js.map +1 -0
- package/dist/modules/auth.d.ts +49 -0
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/auth.js +69 -0
- package/dist/modules/auth.js.map +1 -0
- package/dist/modules/billing.d.ts +254 -0
- package/dist/modules/billing.d.ts.map +1 -0
- package/dist/modules/billing.js +203 -0
- package/dist/modules/billing.js.map +1 -0
- package/dist/modules/clans.d.ts +73 -0
- package/dist/modules/clans.d.ts.map +1 -0
- package/dist/modules/clans.js +94 -0
- package/dist/modules/clans.js.map +1 -0
- package/dist/modules/compliance.d.ts +97 -0
- package/dist/modules/compliance.d.ts.map +1 -0
- package/dist/modules/compliance.js +227 -0
- package/dist/modules/compliance.js.map +1 -0
- package/dist/modules/cross-plane.d.ts +164 -0
- package/dist/modules/cross-plane.d.ts.map +1 -0
- package/dist/modules/cross-plane.js +195 -0
- package/dist/modules/cross-plane.js.map +1 -0
- package/dist/modules/dashboard.d.ts +130 -0
- package/dist/modules/dashboard.d.ts.map +1 -0
- package/dist/modules/dashboard.js +120 -0
- package/dist/modules/dashboard.js.map +1 -0
- package/dist/modules/degradation.d.ts +120 -0
- package/dist/modules/degradation.d.ts.map +1 -0
- package/dist/modules/degradation.js +205 -0
- package/dist/modules/degradation.js.map +1 -0
- package/dist/modules/diagnostics-checks.d.ts +32 -0
- package/dist/modules/diagnostics-checks.d.ts.map +1 -0
- package/dist/modules/diagnostics-checks.js +231 -0
- package/dist/modules/diagnostics-checks.js.map +1 -0
- package/dist/modules/diagnostics-types.d.ts +118 -0
- package/dist/modules/diagnostics-types.d.ts.map +1 -0
- package/dist/modules/diagnostics-types.js +16 -0
- package/dist/modules/diagnostics-types.js.map +1 -0
- package/dist/modules/diagnostics.d.ts +64 -0
- package/dist/modules/diagnostics.d.ts.map +1 -0
- package/dist/modules/diagnostics.js +206 -0
- package/dist/modules/diagnostics.js.map +1 -0
- package/dist/modules/discovery.d.ts +152 -0
- package/dist/modules/discovery.d.ts.map +1 -0
- package/dist/modules/discovery.js +100 -0
- package/dist/modules/discovery.js.map +1 -0
- package/dist/modules/fleets.d.ts +82 -0
- package/dist/modules/fleets.d.ts.map +1 -0
- package/dist/modules/fleets.js +33 -0
- package/dist/modules/fleets.js.map +1 -0
- package/dist/modules/lease-manager.d.ts +119 -0
- package/dist/modules/lease-manager.d.ts.map +1 -0
- package/dist/modules/lease-manager.js +242 -0
- package/dist/modules/lease-manager.js.map +1 -0
- package/dist/modules/leases.d.ts +70 -0
- package/dist/modules/leases.d.ts.map +1 -0
- package/dist/modules/leases.js +51 -0
- package/dist/modules/leases.js.map +1 -0
- package/dist/modules/operators.d.ts +176 -0
- package/dist/modules/operators.d.ts.map +1 -0
- package/dist/modules/operators.js +133 -0
- package/dist/modules/operators.js.map +1 -0
- package/dist/modules/providers.d.ts +141 -0
- package/dist/modules/providers.d.ts.map +1 -0
- package/dist/modules/providers.js +118 -0
- package/dist/modules/providers.js.map +1 -0
- package/dist/modules/quota.d.ts +102 -0
- package/dist/modules/quota.d.ts.map +1 -0
- package/dist/modules/quota.js +135 -0
- package/dist/modules/quota.js.map +1 -0
- package/dist/modules/reactions.d.ts +141 -0
- package/dist/modules/reactions.d.ts.map +1 -0
- package/dist/modules/reactions.js +122 -0
- package/dist/modules/reactions.js.map +1 -0
- package/dist/modules/register.d.ts +159 -0
- package/dist/modules/register.d.ts.map +1 -0
- package/dist/modules/register.js +239 -0
- package/dist/modules/register.js.map +1 -0
- package/dist/modules/sandbox.d.ts +106 -0
- package/dist/modules/sandbox.d.ts.map +1 -0
- package/dist/modules/sandbox.js +224 -0
- package/dist/modules/sandbox.js.map +1 -0
- package/dist/modules/streams.d.ts +81 -0
- package/dist/modules/streams.d.ts.map +1 -0
- package/dist/modules/streams.js +292 -0
- package/dist/modules/streams.js.map +1 -0
- package/dist/modules/tasks.d.ts +145 -0
- package/dist/modules/tasks.d.ts.map +1 -0
- package/dist/modules/tasks.js +165 -0
- package/dist/modules/tasks.js.map +1 -0
- package/dist/modules/telemetry.d.ts +137 -0
- package/dist/modules/telemetry.d.ts.map +1 -0
- package/dist/modules/telemetry.js +203 -0
- package/dist/modules/telemetry.js.map +1 -0
- package/dist/modules/workspace.d.ts +180 -0
- package/dist/modules/workspace.d.ts.map +1 -0
- package/dist/modules/workspace.js +157 -0
- package/dist/modules/workspace.js.map +1 -0
- package/dist/quickstart-join.d.ts +56 -0
- package/dist/quickstart-join.d.ts.map +1 -0
- package/dist/quickstart-join.js +116 -0
- package/dist/quickstart-join.js.map +1 -0
- package/dist/quickstart.d.ts +137 -0
- package/dist/quickstart.d.ts.map +1 -0
- package/dist/quickstart.js +292 -0
- package/dist/quickstart.js.map +1 -0
- package/dist/retry.d.ts +88 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +152 -0
- package/dist/retry.js.map +1 -0
- package/dist/types.d.ts +447 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +88 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +199 -0
- package/dist/utils.js.map +1 -0
- package/package.json +215 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-claim compliance guard.
|
|
3
|
+
*
|
|
4
|
+
* Before the SDK lets a task claim go to the wire, the guard runs a battery
|
|
5
|
+
* of client-side checks so the agent gets a structured "why not, and how to
|
|
6
|
+
* fix" response instead of a 4xx from the control-plane. Server-side is
|
|
7
|
+
* still authoritative — this is a friendly, fast, informative preflight.
|
|
8
|
+
*
|
|
9
|
+
* Six checks, matching T4.3 in the audit doc:
|
|
10
|
+
* 1. Agent has an active lease for the target workspace.
|
|
11
|
+
* 2. Spend envelope has room for the task's estimated cost.
|
|
12
|
+
* 3. Agent's declared `supportedActions` covers the task's required action.
|
|
13
|
+
* 4. Agent isn't already at its max concurrent in-flight task cap.
|
|
14
|
+
* 5. Rate limit has headroom (via {@link QuotaClient}).
|
|
15
|
+
* 6. Trust tier permits this task type.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import type { LeaseSnapshot } from "./lease-manager.js";
|
|
20
|
+
import type { QuotaClient } from "./quota.js";
|
|
21
|
+
import type { SandboxPolicy } from "./sandbox.js";
|
|
22
|
+
import type { WorkspaceDirectoryEntry } from "../types.js";
|
|
23
|
+
/** Per-check status. */
|
|
24
|
+
export type ComplianceStatus = "pass" | "warn" | "fail";
|
|
25
|
+
/** One compliance check result. */
|
|
26
|
+
export interface ComplianceCheck {
|
|
27
|
+
name: "lease_active" | "spend_headroom" | "capability_match" | "concurrency_budget" | "rate_limit" | "trust_tier";
|
|
28
|
+
status: ComplianceStatus;
|
|
29
|
+
message?: string;
|
|
30
|
+
fix?: string;
|
|
31
|
+
details?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** Full pre-claim report. */
|
|
34
|
+
export interface ComplianceReport {
|
|
35
|
+
ok: boolean;
|
|
36
|
+
checks: ComplianceCheck[];
|
|
37
|
+
failures: ComplianceCheck[];
|
|
38
|
+
/** Aggregated one-line summary suitable for log lines. */
|
|
39
|
+
summary: string;
|
|
40
|
+
}
|
|
41
|
+
/** Input describing the task about to be claimed. */
|
|
42
|
+
export interface ClaimCandidate {
|
|
43
|
+
taskId: string;
|
|
44
|
+
/** Action name the task will invoke (e.g. `"claim_task"` or a reducer action). */
|
|
45
|
+
requiredAction?: string;
|
|
46
|
+
/** Estimated cost in the lease's native spend units. */
|
|
47
|
+
estimatedSpendUnits?: number;
|
|
48
|
+
/** Which workspace the task belongs to. */
|
|
49
|
+
workspaceSlug: string;
|
|
50
|
+
/** Optional workspace directory entry (used for trust-tier gating). */
|
|
51
|
+
workspace?: WorkspaceDirectoryEntry;
|
|
52
|
+
}
|
|
53
|
+
/** Options for the guard. */
|
|
54
|
+
export interface ComplianceGuardOptions {
|
|
55
|
+
/** Source of lease snapshot — typically `() => leaseManager.status()`. */
|
|
56
|
+
getLease: () => LeaseSnapshot | undefined;
|
|
57
|
+
/** Declared supported actions for this agent. */
|
|
58
|
+
supportedActions: string[];
|
|
59
|
+
/** Max concurrent in-flight task claims. */
|
|
60
|
+
maxConcurrent: number;
|
|
61
|
+
/** Source of "tasks currently in flight" — typically `() => enforcer.inFlightCount()`. */
|
|
62
|
+
getInFlight: () => number;
|
|
63
|
+
/** Optional quota client for rate-limit headroom. */
|
|
64
|
+
quota?: QuotaClient;
|
|
65
|
+
/** Optional sandbox policy for trust-tier checks. */
|
|
66
|
+
sandbox?: SandboxPolicy;
|
|
67
|
+
}
|
|
68
|
+
/** Pre-claim compliance guard. */
|
|
69
|
+
export declare class ComplianceGuard {
|
|
70
|
+
private readonly options;
|
|
71
|
+
constructor(options: ComplianceGuardOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Run every check and return a structured report.
|
|
74
|
+
*
|
|
75
|
+
* Never throws — a failed check shows up in `report.checks` and
|
|
76
|
+
* contributes to `report.ok === false`.
|
|
77
|
+
*/
|
|
78
|
+
check(candidate: ClaimCandidate): ComplianceReport;
|
|
79
|
+
private checkLease;
|
|
80
|
+
private checkSpendHeadroom;
|
|
81
|
+
private checkCapabilityMatch;
|
|
82
|
+
private checkConcurrencyBudget;
|
|
83
|
+
private checkRateLimit;
|
|
84
|
+
private checkTrustTier;
|
|
85
|
+
/**
|
|
86
|
+
* Convenience: run `check` and throw a structured {@link ComplianceError}
|
|
87
|
+
* if the report is not ok. Useful when callers want exception-flow
|
|
88
|
+
* handling instead of pattern-matching on a report.
|
|
89
|
+
*/
|
|
90
|
+
enforce(candidate: ClaimCandidate): void;
|
|
91
|
+
}
|
|
92
|
+
/** Error thrown by {@link ComplianceGuard.enforce}. Carries the full report. */
|
|
93
|
+
export declare class ComplianceError extends Error {
|
|
94
|
+
readonly report: ComplianceReport;
|
|
95
|
+
constructor(report: ComplianceReport);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=compliance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance.d.ts","sourceRoot":"","sources":["../../src/modules/compliance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,wBAAwB;AACxB,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAExD,mCAAmC;AACnC,MAAM,WAAW,eAAe;IAC9B,IAAI,EACA,cAAc,GACd,gBAAgB,GAChB,kBAAkB,GAClB,oBAAoB,GACpB,YAAY,GACZ,YAAY,CAAC;IACjB,M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6B1B,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,sBAAsB;IAqB9B,OAAO,CAAC,cAAc;IAuBtB,OAAO,CAAC,cAAc;IAmCtB;;;;OAIG;IACH,OAAO,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI;CAMzC;AAED,gFAAgF;AAChF,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;gBACtB,MAAM,EAAE,gBAAgB;CAKrC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-claim compliance guard.
|
|
3
|
+
*
|
|
4
|
+
* Before the SDK lets a task claim go to the wire, the guard runs a battery
|
|
5
|
+
* of client-side checks so the agent gets a structured "why not, and how to
|
|
6
|
+
* fix" response instead of a 4xx from the control-plane. Server-side is
|
|
7
|
+
* still authoritative — this is a friendly, fast, informative preflight.
|
|
8
|
+
*
|
|
9
|
+
* Six checks, matching T4.3 in the audit doc:
|
|
10
|
+
* 1. Agent has an active lease for the target workspace.
|
|
11
|
+
* 2. Spend envelope has room for the task's estimated cost.
|
|
12
|
+
* 3. Agent's declared `supportedActions` covers the task's required action.
|
|
13
|
+
* 4. Agent isn't already at its max concurrent in-flight task cap.
|
|
14
|
+
* 5. Rate limit has headroom (via {@link QuotaClient}).
|
|
15
|
+
* 6. Trust tier permits this task type.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
/** Pre-claim compliance guard. */
|
|
20
|
+
export class ComplianceGuard {
|
|
21
|
+
options;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run every check and return a structured report.
|
|
27
|
+
*
|
|
28
|
+
* Never throws — a failed check shows up in `report.checks` and
|
|
29
|
+
* contributes to `report.ok === false`.
|
|
30
|
+
*/
|
|
31
|
+
check(candidate) {
|
|
32
|
+
const checks = [
|
|
33
|
+
this.checkLease(candidate),
|
|
34
|
+
this.checkSpendHeadroom(candidate),
|
|
35
|
+
this.checkCapabilityMatch(candidate),
|
|
36
|
+
this.checkConcurrencyBudget(),
|
|
37
|
+
this.checkRateLimit(),
|
|
38
|
+
this.checkTrustTier(candidate)
|
|
39
|
+
];
|
|
40
|
+
const failures = checks.filter((c) => c.status === "fail");
|
|
41
|
+
const warnings = checks.filter((c) => c.status === "warn");
|
|
42
|
+
const ok = failures.length === 0;
|
|
43
|
+
const summary = ok
|
|
44
|
+
? warnings.length > 0
|
|
45
|
+
? `pass with ${warnings.length} warn(s): ${warnings.map((w) => w.name).join(", ")}`
|
|
46
|
+
: "pass"
|
|
47
|
+
: `fail: ${failures.map((f) => f.name).join(", ")}`;
|
|
48
|
+
return { ok, checks, failures, summary };
|
|
49
|
+
}
|
|
50
|
+
checkLease(candidate) {
|
|
51
|
+
const lease = this.options.getLease();
|
|
52
|
+
if (!lease) {
|
|
53
|
+
return {
|
|
54
|
+
name: "lease_active",
|
|
55
|
+
status: "fail",
|
|
56
|
+
message: "No lease snapshot available for this workspace.",
|
|
57
|
+
fix: "Request a lease via leases.request() or call quickStart() to bootstrap one."
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (lease.workspaceSlug && lease.workspaceSlug !== candidate.workspaceSlug) {
|
|
61
|
+
return {
|
|
62
|
+
name: "lease_active",
|
|
63
|
+
status: "fail",
|
|
64
|
+
message: `Lease is for workspace ${lease.workspaceSlug}, not ${candidate.workspaceSlug}.`,
|
|
65
|
+
fix: "Request a workspace-scoped lease before claiming tasks here."
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (lease.status === "revoked" || lease.status === "expired") {
|
|
69
|
+
return {
|
|
70
|
+
name: "lease_active",
|
|
71
|
+
status: "fail",
|
|
72
|
+
message: `Lease status is "${lease.status}".`,
|
|
73
|
+
fix: "Enable LeaseManager.enableAutoRenew() or call leases.request() to get a fresh lease."
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (lease.expiresAt !== undefined) {
|
|
77
|
+
const expiresAt = typeof lease.expiresAt === "number" ? lease.expiresAt : Date.parse(lease.expiresAt);
|
|
78
|
+
if (Number.isFinite(expiresAt) && expiresAt - Date.now() < 30_000) {
|
|
79
|
+
return {
|
|
80
|
+
name: "lease_active",
|
|
81
|
+
status: "warn",
|
|
82
|
+
message: "Lease expires in under 30 seconds.",
|
|
83
|
+
fix: "Renew the lease before new claims."
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { name: "lease_active", status: "pass" };
|
|
88
|
+
}
|
|
89
|
+
checkSpendHeadroom(candidate) {
|
|
90
|
+
const lease = this.options.getLease();
|
|
91
|
+
if (!lease || typeof lease.spendCap !== "number" || typeof lease.spendUsed !== "number") {
|
|
92
|
+
return {
|
|
93
|
+
name: "spend_headroom",
|
|
94
|
+
status: "warn",
|
|
95
|
+
message: "Spend cap / usage unknown — cannot verify headroom."
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const remaining = Math.max(0, lease.spendCap - lease.spendUsed);
|
|
99
|
+
const estimate = candidate.estimatedSpendUnits ?? 1;
|
|
100
|
+
if (remaining < estimate) {
|
|
101
|
+
return {
|
|
102
|
+
name: "spend_headroom",
|
|
103
|
+
status: "fail",
|
|
104
|
+
message: `Need ${estimate} units, only ${remaining} remaining.`,
|
|
105
|
+
fix: "Top up the spend envelope (billing.createEnvelope) or wait for the next lease window."
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (remaining - estimate < lease.spendCap * 0.1) {
|
|
109
|
+
return {
|
|
110
|
+
name: "spend_headroom",
|
|
111
|
+
status: "warn",
|
|
112
|
+
message: `Post-claim headroom will be under 10% of cap.`
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return { name: "spend_headroom", status: "pass" };
|
|
116
|
+
}
|
|
117
|
+
checkCapabilityMatch(candidate) {
|
|
118
|
+
if (!candidate.requiredAction) {
|
|
119
|
+
return { name: "capability_match", status: "pass" };
|
|
120
|
+
}
|
|
121
|
+
if (!this.options.supportedActions.includes(candidate.requiredAction)) {
|
|
122
|
+
return {
|
|
123
|
+
name: "capability_match",
|
|
124
|
+
status: "fail",
|
|
125
|
+
message: `Task requires "${candidate.requiredAction}" but agent only supports [${this.options.supportedActions.join(", ")}].`,
|
|
126
|
+
fix: "Re-register the runtime with the required action, or skip tasks that need it."
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return { name: "capability_match", status: "pass" };
|
|
130
|
+
}
|
|
131
|
+
checkConcurrencyBudget() {
|
|
132
|
+
const inFlight = this.options.getInFlight();
|
|
133
|
+
const cap = this.options.maxConcurrent;
|
|
134
|
+
if (inFlight >= cap) {
|
|
135
|
+
return {
|
|
136
|
+
name: "concurrency_budget",
|
|
137
|
+
status: "fail",
|
|
138
|
+
message: `Already at max concurrent tasks (${inFlight}/${cap}).`,
|
|
139
|
+
fix: "Wait for a task to complete or raise maxConcurrent."
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (inFlight >= cap - 1) {
|
|
143
|
+
return {
|
|
144
|
+
name: "concurrency_budget",
|
|
145
|
+
status: "warn",
|
|
146
|
+
message: `One claim away from cap (${inFlight}/${cap}).`
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return { name: "concurrency_budget", status: "pass" };
|
|
150
|
+
}
|
|
151
|
+
checkRateLimit() {
|
|
152
|
+
if (!this.options.quota) {
|
|
153
|
+
return { name: "rate_limit", status: "pass" };
|
|
154
|
+
}
|
|
155
|
+
const plan = this.options.quota.planBatch("task-claim", 1);
|
|
156
|
+
if (plan.safeToRun === 0) {
|
|
157
|
+
return {
|
|
158
|
+
name: "rate_limit",
|
|
159
|
+
status: "fail",
|
|
160
|
+
message: `Rate-limited; wait ~${plan.suggestedDelayMs}ms.`,
|
|
161
|
+
fix: "Call quota.waitForQuota('task-claim') before claiming again."
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (plan.quota.remaining !== null && plan.quota.remaining < 5) {
|
|
165
|
+
return {
|
|
166
|
+
name: "rate_limit",
|
|
167
|
+
status: "warn",
|
|
168
|
+
message: `Only ${plan.quota.remaining} claims left in this window.`
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return { name: "rate_limit", status: "pass" };
|
|
172
|
+
}
|
|
173
|
+
checkTrustTier(candidate) {
|
|
174
|
+
if (!this.options.sandbox) {
|
|
175
|
+
return { name: "trust_tier", status: "pass" };
|
|
176
|
+
}
|
|
177
|
+
if (!candidate.workspace) {
|
|
178
|
+
return {
|
|
179
|
+
name: "trust_tier",
|
|
180
|
+
status: "warn",
|
|
181
|
+
message: "No workspace directory entry provided; trust tier check skipped."
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const eligibility = this.options.sandbox.canJoinWorkspace(candidate.workspace);
|
|
185
|
+
if (!eligibility.eligible) {
|
|
186
|
+
return {
|
|
187
|
+
name: "trust_tier",
|
|
188
|
+
status: "fail",
|
|
189
|
+
message: eligibility.message ?? `Ineligible: ${eligibility.reason}`,
|
|
190
|
+
fix: eligibility.reason === "requires_higher_proof"
|
|
191
|
+
? "Complete wallet verification to reach P2 proof level."
|
|
192
|
+
: eligibility.reason === "invite_only"
|
|
193
|
+
? "Request an invite from the workspace governor."
|
|
194
|
+
: "Resolve blocking qualifications on your agent passport."
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (eligibility.reason === "suspended_capability") {
|
|
198
|
+
return {
|
|
199
|
+
name: "trust_tier",
|
|
200
|
+
status: "warn",
|
|
201
|
+
message: eligibility.message ?? "Some workspace capabilities are suspended."
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return { name: "trust_tier", status: "pass" };
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Convenience: run `check` and throw a structured {@link ComplianceError}
|
|
208
|
+
* if the report is not ok. Useful when callers want exception-flow
|
|
209
|
+
* handling instead of pattern-matching on a report.
|
|
210
|
+
*/
|
|
211
|
+
enforce(candidate) {
|
|
212
|
+
const report = this.check(candidate);
|
|
213
|
+
if (!report.ok) {
|
|
214
|
+
throw new ComplianceError(report);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** Error thrown by {@link ComplianceGuard.enforce}. Carries the full report. */
|
|
219
|
+
export class ComplianceError extends Error {
|
|
220
|
+
report;
|
|
221
|
+
constructor(report) {
|
|
222
|
+
super(`[compliance] ${report.summary}`);
|
|
223
|
+
this.name = "ComplianceError";
|
|
224
|
+
this.report = report;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=compliance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance.js","sourceRoot":"","sources":["../../src/modules/compliance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA+DH,kCAAkC;AAClC,MAAM,OAAO,eAAe;IACG;IAA7B,YAA6B,OAA+B;QAA/B,YAAO,GAAP,OAAO,CAAwB;IAAG,CAAC;IAEhE;;;;;OAKG;IACH,KAAK,CAAC,SAAyB;QAC7B,MAAM,MAAM,GAAsB;YAChC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;YAC1B,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC;YAClC,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC;YACpC,IAAI,CAAC,sBAAsB,EAAE;YAC7B,IAAI,CAAC,cAAc,EAAE;YACrB,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;SAC/B,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;QA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AAM,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,MAAM,CAAmB;IAClC,YAAY,MAAwB;QAClC,KAAK,CAAC,gBAAgB,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-plane orchestration — unified ShardLink + SignalHub helpers.
|
|
3
|
+
*
|
|
4
|
+
* Agents often coordinate two planes:
|
|
5
|
+
* - **ShardLink** (this repo) — task orchestration, reactions, receipts.
|
|
6
|
+
* - **SignalHub** — signal marketplace where agents buy/sell data streams.
|
|
7
|
+
*
|
|
8
|
+
* The ShardLink control-plane already ships "bridge" endpoints for
|
|
9
|
+
* cross-plane settlement (`/v1/workspaces/:slug/receipts/bridge`,
|
|
10
|
+
* `/v1/workspaces/:slug/bridge/health`). This module wraps them, plus a
|
|
11
|
+
* caller-provided **SignalHub adapter** interface so a host application
|
|
12
|
+
* can plug its SignalHub SDK in without this package taking a direct
|
|
13
|
+
* dependency on the separate repo.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
import type { HttpContext } from "../utils.js";
|
|
18
|
+
import type { StreamClient } from "./streams.js";
|
|
19
|
+
/** The minimum shape the orchestrator needs from a SignalHub client. */
|
|
20
|
+
export interface SignalHubAdapter {
|
|
21
|
+
/** Acquire a signal under a contract, returning a settlement handle. */
|
|
22
|
+
acquireSignal(input: {
|
|
23
|
+
signalContract: string;
|
|
24
|
+
budgetUsdCents: number;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
}): Promise<AcquiredSignal>;
|
|
27
|
+
/** Optional: stream SignalHub events to merge with the ShardLink feed. */
|
|
28
|
+
events?(handler: (event: CrossPlaneEvent) => void): () => void;
|
|
29
|
+
}
|
|
30
|
+
/** A signal acquired from SignalHub, ready to be bound to a ShardLink task. */
|
|
31
|
+
export interface AcquiredSignal {
|
|
32
|
+
/** SignalHub contract identifier. */
|
|
33
|
+
signalContract: string;
|
|
34
|
+
/** Receipt id from SignalHub (attached to ShardLink task metadata). */
|
|
35
|
+
signalReceiptId: string;
|
|
36
|
+
/** Signed payload the agent can feed into task execution. */
|
|
37
|
+
payload: unknown;
|
|
38
|
+
/** How much the signal cost (USD cents). */
|
|
39
|
+
paidUsdCents: number;
|
|
40
|
+
/** ISO timestamp when the signal was acquired. */
|
|
41
|
+
acquiredAt: string;
|
|
42
|
+
}
|
|
43
|
+
/** Input for binding a SignalHub purchase to a ShardLink task. */
|
|
44
|
+
export interface AcquireSignalForTaskInput {
|
|
45
|
+
signalContract: string;
|
|
46
|
+
workspaceSlug: string;
|
|
47
|
+
taskId: string;
|
|
48
|
+
budgetUsdCents: number;
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/** Result of attaching a SignalHub purchase to a ShardLink task. */
|
|
52
|
+
export interface AcquireSignalForTaskResult {
|
|
53
|
+
signal: AcquiredSignal;
|
|
54
|
+
/** The ShardLink bridge receipt (if the workspace emits one for signal binding). */
|
|
55
|
+
bridgeReceipt?: unknown;
|
|
56
|
+
}
|
|
57
|
+
/** A bridge receipt envelope as returned by ShardLink. */
|
|
58
|
+
export interface BridgeReceiptEnvelope {
|
|
59
|
+
workspaceSlug: string;
|
|
60
|
+
receiptId: string;
|
|
61
|
+
payloadHash: string;
|
|
62
|
+
bridgeEventVersion: string;
|
|
63
|
+
hmac?: string;
|
|
64
|
+
hmacKeyId?: string;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
/** Unified event merged from both planes. */
|
|
68
|
+
export interface CrossPlaneEvent {
|
|
69
|
+
plane: "shardlink" | "signalhub";
|
|
70
|
+
type: string;
|
|
71
|
+
payload: unknown;
|
|
72
|
+
at: number;
|
|
73
|
+
}
|
|
74
|
+
/** ShardLink-side status projection for a bridged task. */
|
|
75
|
+
export interface BridgeTaskStatus {
|
|
76
|
+
task_id: string;
|
|
77
|
+
objective_id: string;
|
|
78
|
+
status: string;
|
|
79
|
+
terminal: boolean;
|
|
80
|
+
/** Identity that claimed the task, or `null` if unclaimed. */
|
|
81
|
+
claimed_by: string | null;
|
|
82
|
+
/** ISO timestamp the claim expires, or `null`. */
|
|
83
|
+
claim_expires_at: string | null;
|
|
84
|
+
/** ISO timestamp of the last status change. */
|
|
85
|
+
updated_at: string;
|
|
86
|
+
}
|
|
87
|
+
/** ShardLink-side status projection for a bridged objective. */
|
|
88
|
+
export interface BridgeObjectiveStatus {
|
|
89
|
+
objective_id: string;
|
|
90
|
+
status: string;
|
|
91
|
+
terminal: boolean;
|
|
92
|
+
/** ISO timestamp of the last status change. */
|
|
93
|
+
updated_at: string;
|
|
94
|
+
}
|
|
95
|
+
/** Options for the cross-plane client. */
|
|
96
|
+
export interface CrossPlaneClientOptions {
|
|
97
|
+
/** ShardLink HTTP context. */
|
|
98
|
+
http: HttpContext;
|
|
99
|
+
/**
|
|
100
|
+
* Actor session token bound to the workspace. The caller scopes this
|
|
101
|
+
* per-workspace (same pattern as `BillingClient` etc.).
|
|
102
|
+
*/
|
|
103
|
+
actorSessionToken: string;
|
|
104
|
+
/** Optional SignalHub adapter — without it, only ShardLink-side methods work. */
|
|
105
|
+
signalHub?: SignalHubAdapter;
|
|
106
|
+
/** Optional stream client so `activityFeed` can merge ShardLink events. */
|
|
107
|
+
shardLinkStream?: StreamClient;
|
|
108
|
+
}
|
|
109
|
+
/** Cross-plane orchestrator. */
|
|
110
|
+
export declare class CrossPlaneClient {
|
|
111
|
+
private readonly options;
|
|
112
|
+
constructor(options: CrossPlaneClientOptions);
|
|
113
|
+
/**
|
|
114
|
+
* Acquire a signal from SignalHub and bind it to a ShardLink task.
|
|
115
|
+
*
|
|
116
|
+
* Requires a `signalHub` adapter to be configured. Throws
|
|
117
|
+
* {@link SignalHubNotConfiguredError} if one wasn't provided.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const bound = await crossPlane.acquireSignalForTask({
|
|
122
|
+
* signalContract: "weather.US-W.v1",
|
|
123
|
+
* workspaceSlug: "ws_1",
|
|
124
|
+
* taskId: "t_42",
|
|
125
|
+
* budgetUsdCents: 250
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
acquireSignalForTask(input: AcquireSignalForTaskInput): Promise<AcquireSignalForTaskResult>;
|
|
130
|
+
/** List bridge receipts for a workspace (paginated). */
|
|
131
|
+
listBridgeReceipts(input: {
|
|
132
|
+
workspaceSlug: string;
|
|
133
|
+
cursor?: number;
|
|
134
|
+
limit?: number;
|
|
135
|
+
}): Promise<BridgeReceiptEnvelope[]>;
|
|
136
|
+
/** Fetch a single bridge receipt by id. */
|
|
137
|
+
getBridgeReceipt(input: {
|
|
138
|
+
workspaceSlug: string;
|
|
139
|
+
receiptId: string;
|
|
140
|
+
}): Promise<BridgeReceiptEnvelope>;
|
|
141
|
+
/** Fetch the ShardLink-side status projection for a task (bridge-aware). */
|
|
142
|
+
getTaskStatus(workspaceSlug: string, taskId: string): Promise<BridgeTaskStatus>;
|
|
143
|
+
/** Fetch the ShardLink-side status projection for an objective. */
|
|
144
|
+
getObjectiveStatus(workspaceSlug: string, objectiveId: string): Promise<BridgeObjectiveStatus>;
|
|
145
|
+
/** Bridge health probe — quick confirmation ShardLink ↔ SignalHub are linked. */
|
|
146
|
+
bridgeHealth(workspaceSlug: string): Promise<Record<string, unknown>>;
|
|
147
|
+
/**
|
|
148
|
+
* Unified activity feed — merges ShardLink stream events with SignalHub
|
|
149
|
+
* events (if the adapter exposes them) into a single async iterable.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* for await (const event of crossPlane.activityFeed()) {
|
|
154
|
+
* console.log(event.plane, event.type, event.payload);
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
activityFeed(): AsyncIterable<CrossPlaneEvent>;
|
|
159
|
+
}
|
|
160
|
+
/** Thrown when a SignalHub-requiring method is called without an adapter. */
|
|
161
|
+
export declare class SignalHubNotConfiguredError extends Error {
|
|
162
|
+
constructor();
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=cross-plane.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-plane.d.ts","sourceRoot":"","sources":["../../src/modules/cross-plane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,wEAAwE;IACxE,aAAa,CAAC,KAAK,EAAE;QACnB,cAAc,EAAE,MAAM,CAAC;QACvB,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE5B,0EAA0E;IAC1E,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAChE;AAED,+EAA+E;AAC/E,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,eAAe,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,OAAO,EAAE,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