@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,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator profile client — CP-1 slice. Thin pass-through over
|
|
3
|
+
* `/v1/operators/:identity/profile` (GET + PUT). The response shape matches
|
|
4
|
+
* the control-plane `OperatorProfile` record for self reads; non-self reads
|
|
5
|
+
* receive the public-view subset (no internal timestamps).
|
|
6
|
+
*
|
|
7
|
+
* See `memory/emergence_thesis_solo_operators.md` — the profile surfaces the
|
|
8
|
+
* operator's flavor identity + cluster affinity in a single read.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import type { HttpContext } from "../utils.js";
|
|
13
|
+
export type FlavorHueFamily = "cyan" | "teal" | "blue" | "amber" | "lime" | "rose" | "violet";
|
|
14
|
+
export interface FlavorHints {
|
|
15
|
+
hueFamily?: FlavorHueFamily;
|
|
16
|
+
facetCount?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface OperatorReputation {
|
|
19
|
+
score: number;
|
|
20
|
+
taskCount: number;
|
|
21
|
+
lastActiveAt?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface OperatorProfile {
|
|
24
|
+
identity: string;
|
|
25
|
+
displayName?: string;
|
|
26
|
+
bio?: string;
|
|
27
|
+
domainTags: string[];
|
|
28
|
+
flavorSeed: string;
|
|
29
|
+
flavorHints?: FlavorHints;
|
|
30
|
+
reputation: OperatorReputation;
|
|
31
|
+
/** Only present on self-reads. */
|
|
32
|
+
createdAt?: number;
|
|
33
|
+
/** Only present on self-reads. */
|
|
34
|
+
updatedAt?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface UpdateOperatorProfileInput {
|
|
37
|
+
displayName?: string | null;
|
|
38
|
+
bio?: string | null;
|
|
39
|
+
domainTags?: string[];
|
|
40
|
+
flavorHints?: FlavorHints | null;
|
|
41
|
+
}
|
|
42
|
+
export interface OperatorProfileMutationOptions {
|
|
43
|
+
idempotencyKey?: string;
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
}
|
|
46
|
+
/** Typed client over `/v1/operators/:identity/profile`. */
|
|
47
|
+
export declare class OperatorProfileClient {
|
|
48
|
+
private readonly http;
|
|
49
|
+
constructor(http: HttpContext);
|
|
50
|
+
/**
|
|
51
|
+
* Fetch the profile for `identity`. Returns the public-view subset when
|
|
52
|
+
* `identity` is not the caller.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const me = await client.getOperatorProfile("op:alice");
|
|
56
|
+
*/
|
|
57
|
+
getOperatorProfile(identity: string, signal?: AbortSignal): Promise<OperatorProfile>;
|
|
58
|
+
/**
|
|
59
|
+
* Upsert the caller's own profile. `null` on an optional field clears it.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* await client.updateOperatorProfile("op:alice", {
|
|
63
|
+
* displayName: "Alice",
|
|
64
|
+
* domainTags: ["forecasting", "ops"],
|
|
65
|
+
* flavorHints: { hueFamily: "cyan", facetCount: 6 }
|
|
66
|
+
* });
|
|
67
|
+
*/
|
|
68
|
+
updateOperatorProfile(identity: string, input: UpdateOperatorProfileInput, options?: OperatorProfileMutationOptions): Promise<OperatorProfile>;
|
|
69
|
+
/**
|
|
70
|
+
* Fetch the caller's earnings/spend ledger. Returns only entries for the
|
|
71
|
+
* caller's own identity; reads against another identity will 403.
|
|
72
|
+
* Entries carry counterparty flavorSeed + optional clanRef/taskRef so the
|
|
73
|
+
* dashboard can render provenance viz (CP-2 slice).
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const page = await client.getOperatorLedger("op:alice", {
|
|
77
|
+
* type: "earning",
|
|
78
|
+
* limit: 25
|
|
79
|
+
* });
|
|
80
|
+
* if (page.nextCursor) {
|
|
81
|
+
* const next = await client.getOperatorLedger("op:alice", { cursor: page.nextCursor });
|
|
82
|
+
* }
|
|
83
|
+
*/
|
|
84
|
+
getOperatorLedger(identity: string, query?: GetOperatorLedgerQuery, signal?: AbortSignal): Promise<OperatorLedgerPage>;
|
|
85
|
+
/**
|
|
86
|
+
* Fetch operator-scoped marketplace match candidates — CP-3 slice. Matches
|
|
87
|
+
* are ranked by a transparent fitScore; each match surfaces `fitSignals`
|
|
88
|
+
* (flavorAffinity / domainOverlap / clanAttribution) so the UI can render
|
|
89
|
+
* WHY this shard lit up, not just how bright it is.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const page = await client.getOperatorMatches("op:alice", {
|
|
93
|
+
* minScore: 0.3,
|
|
94
|
+
* limit: 10
|
|
95
|
+
* });
|
|
96
|
+
* if (page.nextCursor) {
|
|
97
|
+
* const next = await client.getOperatorMatches("op:alice", {
|
|
98
|
+
* cursor: page.nextCursor
|
|
99
|
+
* });
|
|
100
|
+
* }
|
|
101
|
+
*/
|
|
102
|
+
getOperatorMatches(identity: string, query?: GetOperatorMatchesQuery, signal?: AbortSignal): Promise<OperatorMatchesPage>;
|
|
103
|
+
}
|
|
104
|
+
export type LedgerEntryKind = "earning" | "spend" | "refund" | "bonus";
|
|
105
|
+
export interface LedgerCounterparty {
|
|
106
|
+
id: string;
|
|
107
|
+
displayName?: string;
|
|
108
|
+
flavorSeed?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface LedgerEntry {
|
|
111
|
+
id: string;
|
|
112
|
+
occurredAt: number;
|
|
113
|
+
kind: LedgerEntryKind;
|
|
114
|
+
amount: number;
|
|
115
|
+
currency: "USD";
|
|
116
|
+
counterparty: LedgerCounterparty;
|
|
117
|
+
taskRef?: string;
|
|
118
|
+
clanRef?: string;
|
|
119
|
+
memo?: string;
|
|
120
|
+
streamEventRef?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface GetOperatorLedgerQuery {
|
|
123
|
+
since?: number;
|
|
124
|
+
until?: number;
|
|
125
|
+
type?: "earning" | "spend";
|
|
126
|
+
clanId?: string;
|
|
127
|
+
limit?: number;
|
|
128
|
+
cursor?: string;
|
|
129
|
+
}
|
|
130
|
+
export interface OperatorLedgerPage {
|
|
131
|
+
entries: LedgerEntry[];
|
|
132
|
+
nextCursor?: string;
|
|
133
|
+
totalEarnings: number;
|
|
134
|
+
totalSpend: number;
|
|
135
|
+
window: {
|
|
136
|
+
since?: number;
|
|
137
|
+
until?: number;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export interface OperatorMatchFitSignals {
|
|
141
|
+
flavorAffinity?: number;
|
|
142
|
+
domainOverlap?: number;
|
|
143
|
+
clanAttribution?: string;
|
|
144
|
+
}
|
|
145
|
+
export interface OperatorMatchCounterparty {
|
|
146
|
+
id: string;
|
|
147
|
+
displayName?: string;
|
|
148
|
+
flavorSeed?: string;
|
|
149
|
+
}
|
|
150
|
+
export interface OperatorMatchBountyHint {
|
|
151
|
+
range: [number, number];
|
|
152
|
+
currency: "USD";
|
|
153
|
+
}
|
|
154
|
+
export interface OperatorMatch {
|
|
155
|
+
taskRef: string;
|
|
156
|
+
title: string;
|
|
157
|
+
summary?: string;
|
|
158
|
+
fitScore: number;
|
|
159
|
+
fitSignals: OperatorMatchFitSignals;
|
|
160
|
+
postedAt: number;
|
|
161
|
+
counterparty: OperatorMatchCounterparty;
|
|
162
|
+
bountyHint?: OperatorMatchBountyHint;
|
|
163
|
+
}
|
|
164
|
+
export interface GetOperatorMatchesQuery {
|
|
165
|
+
limit?: number;
|
|
166
|
+
cursor?: string;
|
|
167
|
+
minScore?: number;
|
|
168
|
+
domain?: string;
|
|
169
|
+
clanOnly?: boolean;
|
|
170
|
+
}
|
|
171
|
+
export interface OperatorMatchesPage {
|
|
172
|
+
matches: OperatorMatch[];
|
|
173
|
+
nextCursor?: string;
|
|
174
|
+
generatedAt: number;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=operators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.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,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator profile client — CP-1 slice. Thin pass-through over
|
|
3
|
+
* `/v1/operators/:identity/profile` (GET + PUT). The response shape matches
|
|
4
|
+
* the control-plane `OperatorProfile` record for self reads; non-self reads
|
|
5
|
+
* receive the public-view subset (no internal timestamps).
|
|
6
|
+
*
|
|
7
|
+
* See `memory/emergence_thesis_solo_operators.md` — the profile surfaces the
|
|
8
|
+
* operator's flavor identity + cluster affinity in a single read.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
/** Typed client over `/v1/operators/:identity/profile`. */
|
|
13
|
+
export class OperatorProfileClient {
|
|
14
|
+
http;
|
|
15
|
+
constructor(http) {
|
|
16
|
+
this.http = http;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fetch the profile for `identity`. Returns the public-view subset when
|
|
20
|
+
* `identity` is not the caller.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const me = await client.getOperatorProfile("op:alice");
|
|
24
|
+
*/
|
|
25
|
+
async getOperatorProfile(identity, signal) {
|
|
26
|
+
const { profile } = await this.http.request({
|
|
27
|
+
path: `/v1/operators/${encodeURIComponent(identity)}/profile`,
|
|
28
|
+
operation: "operator-profile-get",
|
|
29
|
+
headers: await this.http.requiredAuthHeaders(),
|
|
30
|
+
...(signal ? { signal } : {})
|
|
31
|
+
});
|
|
32
|
+
return profile;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Upsert the caller's own profile. `null` on an optional field clears it.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* await client.updateOperatorProfile("op:alice", {
|
|
39
|
+
* displayName: "Alice",
|
|
40
|
+
* domainTags: ["forecasting", "ops"],
|
|
41
|
+
* flavorHints: { hueFamily: "cyan", facetCount: 6 }
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
44
|
+
async updateOperatorProfile(identity, input, options = {}) {
|
|
45
|
+
const headers = await this.http.requiredAuthHeaders({ "content-type": "application/json" });
|
|
46
|
+
if (options.idempotencyKey)
|
|
47
|
+
headers["idempotency-key"] = options.idempotencyKey;
|
|
48
|
+
const { profile } = await this.http.request({
|
|
49
|
+
path: `/v1/operators/${encodeURIComponent(identity)}/profile`,
|
|
50
|
+
method: "PUT",
|
|
51
|
+
operation: "operator-profile-put",
|
|
52
|
+
headers,
|
|
53
|
+
body: input,
|
|
54
|
+
...(options.signal ? { signal: options.signal } : {})
|
|
55
|
+
});
|
|
56
|
+
return profile;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fetch the caller's earnings/spend ledger. Returns only entries for the
|
|
60
|
+
* caller's own identity; reads against another identity will 403.
|
|
61
|
+
* Entries carry counterparty flavorSeed + optional clanRef/taskRef so the
|
|
62
|
+
* dashboard can render provenance viz (CP-2 slice).
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const page = await client.getOperatorLedger("op:alice", {
|
|
66
|
+
* type: "earning",
|
|
67
|
+
* limit: 25
|
|
68
|
+
* });
|
|
69
|
+
* if (page.nextCursor) {
|
|
70
|
+
* const next = await client.getOperatorLedger("op:alice", { cursor: page.nextCursor });
|
|
71
|
+
* }
|
|
72
|
+
*/
|
|
73
|
+
async getOperatorLedger(identity, query = {}, signal) {
|
|
74
|
+
const params = new URLSearchParams();
|
|
75
|
+
if (query.since !== undefined)
|
|
76
|
+
params.set("since", String(query.since));
|
|
77
|
+
if (query.until !== undefined)
|
|
78
|
+
params.set("until", String(query.until));
|
|
79
|
+
if (query.type !== undefined)
|
|
80
|
+
params.set("type", query.type);
|
|
81
|
+
if (query.clanId !== undefined)
|
|
82
|
+
params.set("clan_id", query.clanId);
|
|
83
|
+
if (query.limit !== undefined)
|
|
84
|
+
params.set("limit", String(query.limit));
|
|
85
|
+
if (query.cursor !== undefined)
|
|
86
|
+
params.set("cursor", query.cursor);
|
|
87
|
+
const qs = params.toString();
|
|
88
|
+
return this.http.request({
|
|
89
|
+
path: `/v1/operators/${encodeURIComponent(identity)}/ledger${qs ? `?${qs}` : ""}`,
|
|
90
|
+
operation: "operator-ledger-get",
|
|
91
|
+
headers: await this.http.requiredAuthHeaders(),
|
|
92
|
+
...(signal ? { signal } : {})
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Fetch operator-scoped marketplace match candidates — CP-3 slice. Matches
|
|
97
|
+
* are ranked by a transparent fitScore; each match surfaces `fitSignals`
|
|
98
|
+
* (flavorAffinity / domainOverlap / clanAttribution) so the UI can render
|
|
99
|
+
* WHY this shard lit up, not just how bright it is.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const page = await client.getOperatorMatches("op:alice", {
|
|
103
|
+
* minScore: 0.3,
|
|
104
|
+
* limit: 10
|
|
105
|
+
* });
|
|
106
|
+
* if (page.nextCursor) {
|
|
107
|
+
* const next = await client.getOperatorMatches("op:alice", {
|
|
108
|
+
* cursor: page.nextCursor
|
|
109
|
+
* });
|
|
110
|
+
* }
|
|
111
|
+
*/
|
|
112
|
+
async getOperatorMatches(identity, query = {}, signal) {
|
|
113
|
+
const params = new URLSearchParams();
|
|
114
|
+
if (query.limit !== undefined)
|
|
115
|
+
params.set("limit", String(query.limit));
|
|
116
|
+
if (query.cursor !== undefined)
|
|
117
|
+
params.set("cursor", query.cursor);
|
|
118
|
+
if (query.minScore !== undefined)
|
|
119
|
+
params.set("minScore", String(query.minScore));
|
|
120
|
+
if (query.domain !== undefined)
|
|
121
|
+
params.set("domain", query.domain);
|
|
122
|
+
if (query.clanOnly !== undefined)
|
|
123
|
+
params.set("clanOnly", String(query.clanOnly));
|
|
124
|
+
const qs = params.toString();
|
|
125
|
+
return this.http.request({
|
|
126
|
+
path: `/v1/operators/${encodeURIComponent(identity)}/matches${qs ? `?${qs}` : ""}`,
|
|
127
|
+
operation: "operator-matches-get",
|
|
128
|
+
headers: await this.http.requiredAuthHeaders(),
|
|
129
|
+
...(signal ? { signal } : {})
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=operators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../src/modules/operators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA2CH,2DAA2D;AAC3D,MAAM,OAAO,qBAAqB;IACH;IAA7B,YAA6B,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;IAAG,CAAC;IAElD;;;;;;OAMG;IACH,KAAK,CAAC,kBAAkB,CAAC,QAAgB,EAAE,MAAoB;QAC7D,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAA+B;YACxE,IAAI,EAAE,iBAAiB,kBAAkB,CAAC,QAAQ,CAAC,UAAU;YAC7D,SAAS,EAAE,sBAAsB;YACjC,OAAO,EAAE,MAAM,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC9C,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC9B,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,qBAAqB,CACzB,QAAgB,EAChB,KAAiC,EACjC,UAA0C,EAAE;QAE5C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,EA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,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACnE,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QACjF,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAsB;YAC5C,IAAI,EAAE,iBAAiB,kBAAkB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;YAClF,SAAS,EAAE,sBAAsB;YACjC,OAAO,EAAE,MAAM,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC9C,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider quote + execution, including the x402 payment-required flow.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import { type HttpContext } from "../utils.js";
|
|
7
|
+
import type { X402PaymentRequirement, X402PaymentResponse } from "../types.js";
|
|
8
|
+
/** Provider capabilities that can be quoted and executed. */
|
|
9
|
+
export type ProviderCapability = "inference" | "browser" | "search" | "storage" | "notifications";
|
|
10
|
+
/** A provider quote — price discovery for a capability. */
|
|
11
|
+
export interface ProviderQuote {
|
|
12
|
+
quoteId: string;
|
|
13
|
+
workspaceSlug: string;
|
|
14
|
+
identity: string;
|
|
15
|
+
capability: ProviderCapability;
|
|
16
|
+
providerKey: string;
|
|
17
|
+
units: number;
|
|
18
|
+
vendorCostUsdCents: number;
|
|
19
|
+
customerPriceUsdCents: number;
|
|
20
|
+
marginRatio: number;
|
|
21
|
+
pricingVersion?: string | null;
|
|
22
|
+
expiresAt: number;
|
|
23
|
+
status: "active" | "executed" | "expired";
|
|
24
|
+
createdAt: number;
|
|
25
|
+
executedAt?: number | null;
|
|
26
|
+
metadata: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** A completed provider-execution record. */
|
|
29
|
+
export interface ProviderExecutionRecord {
|
|
30
|
+
executionId: string;
|
|
31
|
+
workspaceSlug: string;
|
|
32
|
+
identity: string;
|
|
33
|
+
quoteId: string;
|
|
34
|
+
capability: ProviderCapability;
|
|
35
|
+
providerKey: string;
|
|
36
|
+
units: number;
|
|
37
|
+
vendorCostUsdCents: number;
|
|
38
|
+
customerPriceUsdCents: number;
|
|
39
|
+
marginRatio: number;
|
|
40
|
+
pricingVersion?: string | null;
|
|
41
|
+
envelopeId: string;
|
|
42
|
+
providerReceiptRef: string;
|
|
43
|
+
settlementId: string;
|
|
44
|
+
status: "pending" | "completed" | "failed" | "reconciled" | "refunded";
|
|
45
|
+
createdAt: number;
|
|
46
|
+
updatedAt: number;
|
|
47
|
+
completedAt?: number | null;
|
|
48
|
+
failureCode?: string | null;
|
|
49
|
+
result: Record<string, unknown>;
|
|
50
|
+
metadata: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
/** Result of {@link ProvidersClient.createQuote}. */
|
|
53
|
+
export interface CreateProviderQuoteResult {
|
|
54
|
+
quote: ProviderQuote;
|
|
55
|
+
/** Present when a staging unit-economics guardrail decision applies. */
|
|
56
|
+
stagingGuardrail?: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Result of {@link ProvidersClient.executeQuote} (direct, non-x402 path).
|
|
60
|
+
*
|
|
61
|
+
* `settlement` and `lineage` carry the billing audit trail; their detailed
|
|
62
|
+
* shapes are intentionally left open (`Record<string, unknown>`) — the
|
|
63
|
+
* control-plane settlement schema evolves independently of the SDK.
|
|
64
|
+
*/
|
|
65
|
+
export interface ExecuteProviderQuoteResult {
|
|
66
|
+
execution: ProviderExecutionRecord;
|
|
67
|
+
/** The spend envelope after the execution draw-down. */
|
|
68
|
+
envelope: Record<string, unknown>;
|
|
69
|
+
/** Billing settlement record, or `null` if not yet recorded. */
|
|
70
|
+
settlement: Record<string, unknown> | null;
|
|
71
|
+
/** Execution → settlement lineage envelope. */
|
|
72
|
+
lineage: Record<string, unknown>;
|
|
73
|
+
stagingGuardrail?: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
/** Result of an x402-aware provider execution. */
|
|
76
|
+
export interface ProviderX402Result {
|
|
77
|
+
/** The payment requirement the server issued (null if none was needed). */
|
|
78
|
+
requirement: X402PaymentRequirement | null;
|
|
79
|
+
/** The payment response header returned after settlement (null if not provided). */
|
|
80
|
+
paymentResponse: X402PaymentResponse | null;
|
|
81
|
+
/** The parsed JSON body of the successful execution response. */
|
|
82
|
+
result: unknown;
|
|
83
|
+
}
|
|
84
|
+
/** Provider marketplace client — quote, execute, x402 flow. */
|
|
85
|
+
export declare class ProvidersClient {
|
|
86
|
+
private readonly http;
|
|
87
|
+
constructor(http: HttpContext);
|
|
88
|
+
/**
|
|
89
|
+
* Create a provider quote (price discovery for a capability).
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const { quote } = await providers.createQuote("ws_1", actorSessionToken, {
|
|
94
|
+
* capability: "inference",
|
|
95
|
+
* units: 1
|
|
96
|
+
* });
|
|
97
|
+
* console.log(quote.customerPriceUsdCents, quote.quoteId);
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
createQuote(workspaceSlug: string, actorSessionToken: string, input: Record<string, unknown>, idempotencyKey?: string): Promise<CreateProviderQuoteResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Execute a provider quote on the direct path (no x402 negotiation). Use
|
|
103
|
+
* {@link executeQuoteWithX402} when the provider may demand a payment.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const { execution } = await providers.executeQuote("ws_1", actorSessionToken, quoteId, {});
|
|
108
|
+
* console.log(execution.status, execution.providerReceiptRef);
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
executeQuote(workspaceSlug: string, actorSessionToken: string, quoteId: string, input: Record<string, unknown>, idempotencyKey?: string): Promise<ExecuteProviderQuoteResult>;
|
|
112
|
+
/**
|
|
113
|
+
* Execute a provider quote, negotiating an x402 payment-required handshake
|
|
114
|
+
* when the server demands one.
|
|
115
|
+
*
|
|
116
|
+
* - If the first call returns 2xx, the result is returned directly.
|
|
117
|
+
* - If it returns 402, the caller's `providePayment` callback is invoked
|
|
118
|
+
* with the parsed {@link X402PaymentRequirement} and must return the
|
|
119
|
+
* `PAYMENT` header value. The SDK then retries with a fresh idempotency key
|
|
120
|
+
* and returns the settled result.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* await providers.executeQuoteWithX402({
|
|
125
|
+
* workspaceSlug,
|
|
126
|
+
* actorSessionToken,
|
|
127
|
+
* quoteId,
|
|
128
|
+
* providePayment: (req) => wallet.sign(req)
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
executeQuoteWithX402(input: {
|
|
133
|
+
workspaceSlug: string;
|
|
134
|
+
actorSessionToken: string;
|
|
135
|
+
quoteId: string;
|
|
136
|
+
metadata?: Record<string, unknown>;
|
|
137
|
+
idempotencyKey?: string;
|
|
138
|
+
providePayment: (requirement: X402PaymentRequirement) => Promise<string> | string;
|
|
139
|
+
}): Promise<ProviderX402Result>;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/modules/providers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AACrB,O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C,IAAI;gBAAJ,IAAI,EAAE,WAAW;IAE9C;;;;;;;;;;;OAWG;IACG,WAAW,CACf,aAAa,EAAE,MAAM,EACrB,iBAAiB,EAAE,MAAM,EACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,yBAAyB,CAAC;IAUrC;;;;;;;;;OASG;IACG,YAAY,CAChB,aAAa,EAAE,MAAM,EACrB,iBAAiB,EAAE,MAAM,EACzB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,0BAA0B,CAAC;IAUtC;;;;;;;;;;;;;;;;;;;OAmBG;IACG,oBAAoB,CAAC,KAAK,EAAE;QAChC,aAAa,EAAE,MAAM,CAAC;QACtB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnC,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,cAAc,EAAE,CAAC,WAAW,EAAE,sBAAsB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;KACnF,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA4ChC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider quote + execution, including the x402 payment-required flow.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import { expectJson, parseX402PaymentRequired, parseX402PaymentResponse, readJson } from "../utils.js";
|
|
7
|
+
function idempotencyHeader(key) {
|
|
8
|
+
return key ? { "idempotency-key": key } : {};
|
|
9
|
+
}
|
|
10
|
+
/** Provider marketplace client — quote, execute, x402 flow. */
|
|
11
|
+
export class ProvidersClient {
|
|
12
|
+
http;
|
|
13
|
+
constructor(http) {
|
|
14
|
+
this.http = http;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a provider quote (price discovery for a capability).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const { quote } = await providers.createQuote("ws_1", actorSessionToken, {
|
|
22
|
+
* capability: "inference",
|
|
23
|
+
* units: 1
|
|
24
|
+
* });
|
|
25
|
+
* console.log(quote.customerPriceUsdCents, quote.quoteId);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
async createQuote(workspaceSlug, actorSessionToken, input, idempotencyKey) {
|
|
29
|
+
return this.http.request({
|
|
30
|
+
path: `/v1/workspaces/${encodeURIComponent(workspaceSlug)}/providers/quotes`,
|
|
31
|
+
method: "POST",
|
|
32
|
+
operation: "provider-quote-create",
|
|
33
|
+
headers: this.http.bearerHeaders(actorSessionToken, idempotencyHeader(idempotencyKey)),
|
|
34
|
+
body: input
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Execute a provider quote on the direct path (no x402 negotiation). Use
|
|
39
|
+
* {@link executeQuoteWithX402} when the provider may demand a payment.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const { execution } = await providers.executeQuote("ws_1", actorSessionToken, quoteId, {});
|
|
44
|
+
* console.log(execution.status, execution.providerReceiptRef);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
async executeQuote(workspaceSlug, actorSessionToken, quoteId, input, idempotencyKey) {
|
|
48
|
+
return this.http.request({
|
|
49
|
+
path: `/v1/workspaces/${encodeURIComponent(workspaceSlug)}/providers/quotes/${encodeURIComponent(quoteId)}/execute`,
|
|
50
|
+
method: "POST",
|
|
51
|
+
operation: "provider-quote-execute",
|
|
52
|
+
headers: this.http.bearerHeaders(actorSessionToken, idempotencyHeader(idempotencyKey)),
|
|
53
|
+
body: input
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Execute a provider quote, negotiating an x402 payment-required handshake
|
|
58
|
+
* when the server demands one.
|
|
59
|
+
*
|
|
60
|
+
* - If the first call returns 2xx, the result is returned directly.
|
|
61
|
+
* - If it returns 402, the caller's `providePayment` callback is invoked
|
|
62
|
+
* with the parsed {@link X402PaymentRequirement} and must return the
|
|
63
|
+
* `PAYMENT` header value. The SDK then retries with a fresh idempotency key
|
|
64
|
+
* and returns the settled result.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* await providers.executeQuoteWithX402({
|
|
69
|
+
* workspaceSlug,
|
|
70
|
+
* actorSessionToken,
|
|
71
|
+
* quoteId,
|
|
72
|
+
* providePayment: (req) => wallet.sign(req)
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
async executeQuoteWithX402(input) {
|
|
77
|
+
const path = `/v1/workspaces/${encodeURIComponent(input.workspaceSlug)}/providers/quotes/${encodeURIComponent(input.quoteId)}/execute`;
|
|
78
|
+
const body = input.metadata ? { metadata: input.metadata } : {};
|
|
79
|
+
const firstResponse = await this.http.rawRequest({
|
|
80
|
+
path,
|
|
81
|
+
method: "POST",
|
|
82
|
+
operation: "provider-quote-execute-x402",
|
|
83
|
+
headers: this.http.bearerHeaders(input.actorSessionToken, idempotencyHeader(input.idempotencyKey)),
|
|
84
|
+
body
|
|
85
|
+
});
|
|
86
|
+
if (firstResponse.status !== 402) {
|
|
87
|
+
return {
|
|
88
|
+
requirement: parseX402PaymentRequired(firstResponse),
|
|
89
|
+
paymentResponse: parseX402PaymentResponse(firstResponse),
|
|
90
|
+
result: await expectJson(firstResponse, "provider-quote-execute-x402-initial")
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const headerRequirement = parseX402PaymentRequired(firstResponse);
|
|
94
|
+
const firstPayload = await readJson(firstResponse);
|
|
95
|
+
const requirement = headerRequirement ?? parseX402PaymentRequired(firstPayload);
|
|
96
|
+
if (!requirement) {
|
|
97
|
+
throw new Error("[provider-quote-execute-x402] missing PAYMENT-REQUIRED challenge.");
|
|
98
|
+
}
|
|
99
|
+
const paymentHeaderValue = await input.providePayment(requirement);
|
|
100
|
+
const retryKey = `${input.idempotencyKey ?? `provider-x402:${input.quoteId}`}:retry`;
|
|
101
|
+
const retryResponse = await this.http.rawRequest({
|
|
102
|
+
path,
|
|
103
|
+
method: "POST",
|
|
104
|
+
operation: "provider-quote-execute-x402-retry",
|
|
105
|
+
headers: this.http.bearerHeaders(input.actorSessionToken, {
|
|
106
|
+
"idempotency-key": retryKey,
|
|
107
|
+
PAYMENT: paymentHeaderValue
|
|
108
|
+
}),
|
|
109
|
+
body
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
requirement,
|
|
113
|
+
paymentResponse: parseX402PaymentResponse(retryResponse),
|
|
114
|
+
result: await expectJson(retryResponse, "provider-quote-execute-x402-retry")
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/modules/providers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,UAAU,EACV,wBAAwB,EACxB,wBAAwB,EACxB,QAAQ,EAET,MAAM,aAAa,CAAC;AAGrB,SAAS,iBAAiB,CAAC,GAAY;IACrC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/C,CAAC;AAoFD,+DAA+D;AAC/D,MAAM,OAAO,eAAe;IACG;IAA7B,YAA6B,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;IAAG,CAAC;IAElD;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,WAAW,CACf,aAAqB,EACrB,iBAAyB,EACzB,KAA8B,EAC9B,cAA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