@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.
Files changed (143) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +129 -0
  3. package/dist/client-quick-join.d.ts +38 -0
  4. package/dist/client-quick-join.d.ts.map +1 -0
  5. package/dist/client-quick-join.js +141 -0
  6. package/dist/client-quick-join.js.map +1 -0
  7. package/dist/client.d.ts +134 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +190 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/errors.d.ts +126 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +330 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +47 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +47 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/modules/a2a.d.ts +42 -0
  20. package/dist/modules/a2a.d.ts.map +1 -0
  21. package/dist/modules/a2a.js +47 -0
  22. package/dist/modules/a2a.js.map +1 -0
  23. package/dist/modules/agents.d.ts +100 -0
  24. package/dist/modules/agents.d.ts.map +1 -0
  25. package/dist/modules/agents.js +85 -0
  26. package/dist/modules/agents.js.map +1 -0
  27. package/dist/modules/auth.d.ts +49 -0
  28. package/dist/modules/auth.d.ts.map +1 -0
  29. package/dist/modules/auth.js +69 -0
  30. package/dist/modules/auth.js.map +1 -0
  31. package/dist/modules/billing.d.ts +254 -0
  32. package/dist/modules/billing.d.ts.map +1 -0
  33. package/dist/modules/billing.js +203 -0
  34. package/dist/modules/billing.js.map +1 -0
  35. package/dist/modules/clans.d.ts +73 -0
  36. package/dist/modules/clans.d.ts.map +1 -0
  37. package/dist/modules/clans.js +94 -0
  38. package/dist/modules/clans.js.map +1 -0
  39. package/dist/modules/compliance.d.ts +97 -0
  40. package/dist/modules/compliance.d.ts.map +1 -0
  41. package/dist/modules/compliance.js +227 -0
  42. package/dist/modules/compliance.js.map +1 -0
  43. package/dist/modules/cross-plane.d.ts +164 -0
  44. package/dist/modules/cross-plane.d.ts.map +1 -0
  45. package/dist/modules/cross-plane.js +195 -0
  46. package/dist/modules/cross-plane.js.map +1 -0
  47. package/dist/modules/dashboard.d.ts +130 -0
  48. package/dist/modules/dashboard.d.ts.map +1 -0
  49. package/dist/modules/dashboard.js +120 -0
  50. package/dist/modules/dashboard.js.map +1 -0
  51. package/dist/modules/degradation.d.ts +120 -0
  52. package/dist/modules/degradation.d.ts.map +1 -0
  53. package/dist/modules/degradation.js +205 -0
  54. package/dist/modules/degradation.js.map +1 -0
  55. package/dist/modules/diagnostics-checks.d.ts +32 -0
  56. package/dist/modules/diagnostics-checks.d.ts.map +1 -0
  57. package/dist/modules/diagnostics-checks.js +231 -0
  58. package/dist/modules/diagnostics-checks.js.map +1 -0
  59. package/dist/modules/diagnostics-types.d.ts +118 -0
  60. package/dist/modules/diagnostics-types.d.ts.map +1 -0
  61. package/dist/modules/diagnostics-types.js +16 -0
  62. package/dist/modules/diagnostics-types.js.map +1 -0
  63. package/dist/modules/diagnostics.d.ts +64 -0
  64. package/dist/modules/diagnostics.d.ts.map +1 -0
  65. package/dist/modules/diagnostics.js +206 -0
  66. package/dist/modules/diagnostics.js.map +1 -0
  67. package/dist/modules/discovery.d.ts +152 -0
  68. package/dist/modules/discovery.d.ts.map +1 -0
  69. package/dist/modules/discovery.js +100 -0
  70. package/dist/modules/discovery.js.map +1 -0
  71. package/dist/modules/fleets.d.ts +82 -0
  72. package/dist/modules/fleets.d.ts.map +1 -0
  73. package/dist/modules/fleets.js +33 -0
  74. package/dist/modules/fleets.js.map +1 -0
  75. package/dist/modules/lease-manager.d.ts +119 -0
  76. package/dist/modules/lease-manager.d.ts.map +1 -0
  77. package/dist/modules/lease-manager.js +242 -0
  78. package/dist/modules/lease-manager.js.map +1 -0
  79. package/dist/modules/leases.d.ts +70 -0
  80. package/dist/modules/leases.d.ts.map +1 -0
  81. package/dist/modules/leases.js +51 -0
  82. package/dist/modules/leases.js.map +1 -0
  83. package/dist/modules/operators.d.ts +176 -0
  84. package/dist/modules/operators.d.ts.map +1 -0
  85. package/dist/modules/operators.js +133 -0
  86. package/dist/modules/operators.js.map +1 -0
  87. package/dist/modules/providers.d.ts +141 -0
  88. package/dist/modules/providers.d.ts.map +1 -0
  89. package/dist/modules/providers.js +118 -0
  90. package/dist/modules/providers.js.map +1 -0
  91. package/dist/modules/quota.d.ts +102 -0
  92. package/dist/modules/quota.d.ts.map +1 -0
  93. package/dist/modules/quota.js +135 -0
  94. package/dist/modules/quota.js.map +1 -0
  95. package/dist/modules/reactions.d.ts +141 -0
  96. package/dist/modules/reactions.d.ts.map +1 -0
  97. package/dist/modules/reactions.js +122 -0
  98. package/dist/modules/reactions.js.map +1 -0
  99. package/dist/modules/register.d.ts +159 -0
  100. package/dist/modules/register.d.ts.map +1 -0
  101. package/dist/modules/register.js +239 -0
  102. package/dist/modules/register.js.map +1 -0
  103. package/dist/modules/sandbox.d.ts +106 -0
  104. package/dist/modules/sandbox.d.ts.map +1 -0
  105. package/dist/modules/sandbox.js +224 -0
  106. package/dist/modules/sandbox.js.map +1 -0
  107. package/dist/modules/streams.d.ts +81 -0
  108. package/dist/modules/streams.d.ts.map +1 -0
  109. package/dist/modules/streams.js +292 -0
  110. package/dist/modules/streams.js.map +1 -0
  111. package/dist/modules/tasks.d.ts +145 -0
  112. package/dist/modules/tasks.d.ts.map +1 -0
  113. package/dist/modules/tasks.js +165 -0
  114. package/dist/modules/tasks.js.map +1 -0
  115. package/dist/modules/telemetry.d.ts +137 -0
  116. package/dist/modules/telemetry.d.ts.map +1 -0
  117. package/dist/modules/telemetry.js +203 -0
  118. package/dist/modules/telemetry.js.map +1 -0
  119. package/dist/modules/workspace.d.ts +180 -0
  120. package/dist/modules/workspace.d.ts.map +1 -0
  121. package/dist/modules/workspace.js +157 -0
  122. package/dist/modules/workspace.js.map +1 -0
  123. package/dist/quickstart-join.d.ts +56 -0
  124. package/dist/quickstart-join.d.ts.map +1 -0
  125. package/dist/quickstart-join.js +116 -0
  126. package/dist/quickstart-join.js.map +1 -0
  127. package/dist/quickstart.d.ts +137 -0
  128. package/dist/quickstart.d.ts.map +1 -0
  129. package/dist/quickstart.js +292 -0
  130. package/dist/quickstart.js.map +1 -0
  131. package/dist/retry.d.ts +88 -0
  132. package/dist/retry.d.ts.map +1 -0
  133. package/dist/retry.js +152 -0
  134. package/dist/retry.js.map +1 -0
  135. package/dist/types.d.ts +447 -0
  136. package/dist/types.d.ts.map +1 -0
  137. package/dist/types.js +10 -0
  138. package/dist/types.js.map +1 -0
  139. package/dist/utils.d.ts +88 -0
  140. package/dist/utils.d.ts.map +1 -0
  141. package/dist/utils.js +199 -0
  142. package/dist/utils.js.map +1 -0
  143. package/package.json +215 -0
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Workspace discovery + directory client.
3
+ *
4
+ * Lists the public workspace directory and converts the filter object into
5
+ * properly-encoded query-string parameters.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { type HttpContext } from "../utils.js";
10
+ import type { DirectoryFilterInput, WorkspaceDirectoryResponse } from "../types.js";
11
+ /** Per-meter-type usage rollup shared by load + metering reports. */
12
+ export interface UsageMeterSummary {
13
+ totalUnits: number;
14
+ byMeterType: Record<"lease" | "action" | "stream" | "bootstrap", number>;
15
+ uniqueIdentities: number;
16
+ entryCount: number;
17
+ }
18
+ /** Shape returned by `GET /v1/workspaces/:slug/load`. */
19
+ export interface WorkspaceLoadReport {
20
+ workspace: {
21
+ slug: string;
22
+ runtimeMode?: "in_memory" | "spacetimedb";
23
+ spacetimeDatabaseId?: string | null;
24
+ };
25
+ windowSeconds: number;
26
+ runtimeStatus: {
27
+ runtimeMode: "in_memory" | "spacetimedb";
28
+ spacetimeDatabaseId?: string;
29
+ authoritative: boolean;
30
+ fallbackObserved: boolean;
31
+ lastRuntimeErrorCode?: string;
32
+ };
33
+ load: {
34
+ activeLeaseRatio: number;
35
+ completionRate: number;
36
+ taskBacklogPressure: number;
37
+ activeLeases: number;
38
+ openTasks: number;
39
+ claimedTasks: number;
40
+ completedTasks: number;
41
+ activeAgentMembers: number;
42
+ pendingLeaseIntents: number;
43
+ receiptThroughputWindow: number;
44
+ };
45
+ metering: UsageMeterSummary;
46
+ }
47
+ /** A single usage-meter entry returned by the metering export. */
48
+ export interface UsageMeterEntry {
49
+ entryId: string;
50
+ workspaceSlug: string;
51
+ identity: string;
52
+ meterType: "lease" | "action" | "stream" | "bootstrap";
53
+ units: number;
54
+ pricingVersion?: string | null;
55
+ detail: Record<string, unknown>;
56
+ dedupeKey?: string | null;
57
+ createdAt: number;
58
+ }
59
+ /** Shape returned by `GET /v1/workspaces/:slug/metering/summary`. */
60
+ export interface WorkspaceMeteringSummary {
61
+ workspace: string;
62
+ window: {
63
+ from: number | null;
64
+ to: number | null;
65
+ };
66
+ summary: UsageMeterSummary;
67
+ /** Latest autoscale decision for the workspace, or `null` if none recorded. */
68
+ latestAutoscaleDecision: Record<string, unknown> | null;
69
+ }
70
+ /** Shape returned by `GET /v1/workspaces/:slug/metering/export`. */
71
+ export interface WorkspaceMeteringExport {
72
+ workspace: string;
73
+ /** Epoch ms the export was produced. */
74
+ exportedAt: number;
75
+ exportedBy: string;
76
+ count: number;
77
+ entries: UsageMeterEntry[];
78
+ }
79
+ /** Shape returned by `GET /v1/workspaces/:slug/capabilities`. */
80
+ export interface WorkspaceCapabilitiesReport {
81
+ workspace: {
82
+ slug: string;
83
+ runtimeMode?: "in_memory" | "spacetimedb";
84
+ spacetimeDatabaseId?: string | null;
85
+ version?: number;
86
+ };
87
+ capabilities: {
88
+ roles: Array<"governor" | "agent" | "spectator">;
89
+ actionMatrix: Record<string, string[]>;
90
+ reducerActions: string[];
91
+ discovery?: Record<string, unknown>;
92
+ invitePolicy?: Record<string, unknown>;
93
+ autoApprovePolicy?: Record<string, unknown>;
94
+ billing?: Record<string, unknown>;
95
+ providerExecution?: Record<string, unknown>;
96
+ leaseTiers: ReadonlyArray<{
97
+ tier: string;
98
+ minProofLevel: string;
99
+ defaultRateLimit: number;
100
+ defaultSpendCap: number;
101
+ }>;
102
+ };
103
+ observedPolicy: {
104
+ activeLeaseCount: number;
105
+ observedAllowlist: string[];
106
+ maxRateLimit: number;
107
+ maxSpendCap: number;
108
+ };
109
+ }
110
+ /** Client for the public workspace directory. */
111
+ export declare class WorkspaceClient {
112
+ private readonly http;
113
+ constructor(http: HttpContext);
114
+ /**
115
+ * List workspaces matching the given filters.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const { workspaces } = await workspace.list({
120
+ * category: "research",
121
+ * minOpenTasks: 1,
122
+ * region: "US"
123
+ * });
124
+ * ```
125
+ */
126
+ list(input?: DirectoryFilterInput): Promise<WorkspaceDirectoryResponse>;
127
+ /**
128
+ * Fetch the workspace capability + observed-lease policy snapshot.
129
+ *
130
+ * Useful for preflight and for showing agents their effective action
131
+ * matrix, active-lease count, max rate-limit, and max spend-cap.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * const caps = await workspace.getCapabilities("ws_1");
136
+ * console.log(caps.observedPolicy.maxRateLimit);
137
+ * ```
138
+ */
139
+ getCapabilities(workspaceSlug: string): Promise<WorkspaceCapabilitiesReport>;
140
+ /**
141
+ * Fetch the workspace load/activity snapshot (agent session required).
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const report = await workspace.getLoad("ws_1");
146
+ * console.log(report.load.openTasks, report.load.activeLeaseRatio);
147
+ * ```
148
+ */
149
+ getLoad(workspaceSlug: string, windowSeconds?: number): Promise<WorkspaceLoadReport>;
150
+ /**
151
+ * Get the workspace metering summary for an optional time window.
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * const { summary } = await workspace.getMeteringSummary({ workspaceSlug: "ws_1" });
156
+ * console.log(summary.totalUnits, summary.byMeterType.action);
157
+ * ```
158
+ */
159
+ getMeteringSummary(input: {
160
+ workspaceSlug: string;
161
+ from?: number;
162
+ to?: number;
163
+ }): Promise<WorkspaceMeteringSummary>;
164
+ /**
165
+ * Export raw metering entries for the given window.
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * const { entries } = await workspace.exportMetering({ workspaceSlug: "ws_1", limit: 500 });
170
+ * for (const entry of entries) console.log(entry.meterType, entry.units);
171
+ * ```
172
+ */
173
+ exportMetering(input: {
174
+ workspaceSlug: string;
175
+ from?: number;
176
+ to?: number;
177
+ limit?: number;
178
+ }): Promise<WorkspaceMeteringExport>;
179
+ }
180
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/modules/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EACV,oBAAoB,EAEpB,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AAErB,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,EAAE,MAAM,CAAC,CAAC;IACzE,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC;QAC1C,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACrC,CAAC;IACF,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE;QACb,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC;QACzC,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,aAAa,EAAE,OAAO,CAAC;QACvB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B,CAAC;IAC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jD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,WAAW;IAE9C;;;;;;;;;;;OAWG;IACG,IAAI,CAAC,KAAK,GAAE,oBAAyB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAkBjF;;;;;;;;;;;OAWG;IACG,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAQlF;;;;;;;;OAQG;IACG,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,SAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IASvF;;;;;;;;OAQG;IACG,kBAAkB,CAAC,KAAK,EAAE;QAC9B,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAYrC;;;;;;;;OAQG;IACG,cAAc,CAAC,KAAK,EAAE;QAC1B,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAYrC"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Workspace discovery + directory client.
3
+ *
4
+ * Lists the public workspace directory and converts the filter object into
5
+ * properly-encoded query-string parameters.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { expectJson } from "../utils.js";
10
+ function isRecord(value) {
11
+ return typeof value === "object" && value !== null;
12
+ }
13
+ function buildDirectoryParams(input = {}) {
14
+ const params = new URLSearchParams();
15
+ if (input.category)
16
+ params.set("category", input.category);
17
+ if (input.runtimeMode)
18
+ params.set("runtimeMode", input.runtimeMode);
19
+ if (input.joinMode)
20
+ params.set("joinMode", input.joinMode);
21
+ if (input.billingMode)
22
+ params.set("billingMode", input.billingMode);
23
+ if (input.adapterKind)
24
+ params.set("adapterKind", input.adapterKind);
25
+ if (input.capability)
26
+ params.set("capability", input.capability);
27
+ if (input.region)
28
+ params.set("region", input.region);
29
+ if (input.qualityStatus)
30
+ params.set("qualityStatus", input.qualityStatus);
31
+ if (input.minOpenTasks !== undefined)
32
+ params.set("minOpenTasks", String(input.minOpenTasks));
33
+ if (input.minActivity24h !== undefined)
34
+ params.set("minActivity24h", String(input.minActivity24h));
35
+ if (input.limit !== undefined)
36
+ params.set("limit", String(input.limit));
37
+ return params;
38
+ }
39
+ /** Client for the public workspace directory. */
40
+ export class WorkspaceClient {
41
+ http;
42
+ constructor(http) {
43
+ this.http = http;
44
+ }
45
+ /**
46
+ * List workspaces matching the given filters.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const { workspaces } = await workspace.list({
51
+ * category: "research",
52
+ * minOpenTasks: 1,
53
+ * region: "US"
54
+ * });
55
+ * ```
56
+ */
57
+ async list(input = {}) {
58
+ const response = await this.http.rawRequest({
59
+ path: "/v1/workspaces/directory",
60
+ operation: "workspace-directory",
61
+ headers: await this.http.optionalAuthHeaders(),
62
+ params: buildDirectoryParams(input)
63
+ });
64
+ const payload = await expectJson(response, "workspace-directory");
65
+ if (!isRecord(payload) || !Array.isArray(payload.workspaces)) {
66
+ throw new Error("[workspace-directory] invalid response payload.");
67
+ }
68
+ return {
69
+ ...(typeof payload.generatedAt === "string" ? { generatedAt: payload.generatedAt } : {}),
70
+ ...(isRecord(payload.filters) ? { filters: payload.filters } : {}),
71
+ workspaces: payload.workspaces
72
+ };
73
+ }
74
+ /**
75
+ * Fetch the workspace capability + observed-lease policy snapshot.
76
+ *
77
+ * Useful for preflight and for showing agents their effective action
78
+ * matrix, active-lease count, max rate-limit, and max spend-cap.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const caps = await workspace.getCapabilities("ws_1");
83
+ * console.log(caps.observedPolicy.maxRateLimit);
84
+ * ```
85
+ */
86
+ async getCapabilities(workspaceSlug) {
87
+ return this.http.request({
88
+ path: `/v1/workspaces/${encodeURIComponent(workspaceSlug)}/capabilities`,
89
+ operation: "workspace-capabilities",
90
+ headers: await this.http.optionalAuthHeaders()
91
+ });
92
+ }
93
+ /**
94
+ * Fetch the workspace load/activity snapshot (agent session required).
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const report = await workspace.getLoad("ws_1");
99
+ * console.log(report.load.openTasks, report.load.activeLeaseRatio);
100
+ * ```
101
+ */
102
+ async getLoad(workspaceSlug, windowSeconds = 900) {
103
+ return this.http.request({
104
+ path: `/v1/workspaces/${encodeURIComponent(workspaceSlug)}/load`,
105
+ operation: "workspace-load",
106
+ headers: await this.http.requiredAuthHeaders(),
107
+ params: new URLSearchParams({ windowSeconds: String(windowSeconds) })
108
+ });
109
+ }
110
+ /**
111
+ * Get the workspace metering summary for an optional time window.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * const { summary } = await workspace.getMeteringSummary({ workspaceSlug: "ws_1" });
116
+ * console.log(summary.totalUnits, summary.byMeterType.action);
117
+ * ```
118
+ */
119
+ async getMeteringSummary(input) {
120
+ const params = new URLSearchParams();
121
+ if (input.from !== undefined)
122
+ params.set("from", String(input.from));
123
+ if (input.to !== undefined)
124
+ params.set("to", String(input.to));
125
+ return this.http.request({
126
+ path: `/v1/workspaces/${encodeURIComponent(input.workspaceSlug)}/metering/summary`,
127
+ operation: "metering-summary",
128
+ headers: await this.http.requiredAuthHeaders(),
129
+ params
130
+ });
131
+ }
132
+ /**
133
+ * Export raw metering entries for the given window.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const { entries } = await workspace.exportMetering({ workspaceSlug: "ws_1", limit: 500 });
138
+ * for (const entry of entries) console.log(entry.meterType, entry.units);
139
+ * ```
140
+ */
141
+ async exportMetering(input) {
142
+ const params = new URLSearchParams();
143
+ if (input.from !== undefined)
144
+ params.set("from", String(input.from));
145
+ if (input.to !== undefined)
146
+ params.set("to", String(input.to));
147
+ if (input.limit !== undefined)
148
+ params.set("limit", String(input.limit));
149
+ return this.http.request({
150
+ path: `/v1/workspaces/${encodeURIComponent(input.workspaceSlug)}/metering/export`,
151
+ operation: "metering-export",
152
+ headers: await this.http.requiredAuthHeaders(),
153
+ params
154
+ });
155
+ }
156
+ }
157
+ //# sourceMappingURL=workspace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../src/modules/workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAoB,MAAM,aAAa,CAAC;AA6G3D,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,SAAS,oBAAoB,CAAC,QAA8B,EAAE;IAC5D,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,IAAI,KAAK,CAAC,QAAQ;QAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3D,IAAI,KAAK,CAAC,WAAW;QAAE,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IACpE,IAAI,KAAK,CAAC,QAAQ;QAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3D,IAAI,KAAK,CAAC,WAAW;QAAE,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IACpE,IAAI,KAAK,CAAC,WAAW;QAAE,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IACpE,IAAI,KAAK,CAAC,UAAU;QAAE,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACjE,IAAI,KAAK,CAAC,MAAM;QAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EA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+1,56 @@
1
+ /**
2
+ * `quickStart` workspace-join resolution helpers.
3
+ *
4
+ * Extracted from {@link quickStart} (`quickstart.ts`) to keep each SDK module
5
+ * file under the 400-line ceiling (CLAUDE.md §"Agent DX Rules"). These helpers
6
+ * are internal to `quickStart` — none are part of the public API surface.
7
+ *
8
+ * Responsibilities:
9
+ * - {@link resolveJoinInput} — build the `quickJoin` input, filling in defaults
10
+ * from self-register + discovery when the caller omits them.
11
+ * - {@link pickJoinableWorkspaceSlug} — choose a workspace slug from ranked
12
+ * recommendations, preferring invite-less workspaces when no token is held.
13
+ * - {@link runQuickJoin} — invoke `quickJoin`, converting the bare invite-token
14
+ * `invalid_request` rejection into a typed {@link CapabilityError}.
15
+ * - {@link isInviteTokenPreconditionError} — detect that rejection.
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ import { ShardLinkError } from "./errors.js";
20
+ import type { AgentSdkClient } from "./client.js";
21
+ import type { QuickStartConfig } from "./quickstart.js";
22
+ import type { WorkspaceRecommendation } from "./modules/register.js";
23
+ import type { QuickJoinInput, QuickJoinResult } from "./types.js";
24
+ /**
25
+ * Run `quickJoin`, converting the control-plane's bare invite-token
26
+ * `invalid_request` rejection into a typed {@link CapabilityError} that names
27
+ * the precondition.
28
+ *
29
+ * The control-plane rejects an invite-less bootstrap of a non-curated-open
30
+ * workspace with `invalid_request: "inviteToken is required for first-time
31
+ * workspace bootstrap."`. On its own that 400 surfaces as an opaque
32
+ * `ValidationError` mid-flow; this wrapper rethrows a `CapabilityError` whose
33
+ * message tells the agent exactly how to resolve it.
34
+ */
35
+ export declare function runQuickJoin(client: AgentSdkClient, joinInput: QuickJoinInput): Promise<QuickJoinResult>;
36
+ /** True when an error is the control-plane's invite-token-required rejection. */
37
+ export declare function isInviteTokenPreconditionError(error: unknown): error is ShardLinkError;
38
+ /**
39
+ * Build the `quickJoin` input — filling in `runtime`, `identity`, and
40
+ * `workspaceSlug` defaults from the self-register result and the `discover`
41
+ * recommendation inputs when the caller omits them.
42
+ */
43
+ export declare function resolveJoinInput(client: AgentSdkClient, config: QuickStartConfig, selfRegister: Awaited<ReturnType<AgentSdkClient["register"]["selfRegister"]>> | null): Promise<QuickJoinInput>;
44
+ /**
45
+ * Choose a workspace slug from ranked recommendations.
46
+ *
47
+ * `quickStart` bootstraps with no invite token unless the caller supplied
48
+ * one. Only `curated_open_sandbox` workspaces permit invite-less bootstrap —
49
+ * an `invite_only` workspace makes the control-plane reject the bootstrap with
50
+ * `invalid_request: "inviteToken is required..."`. So when no invite token is
51
+ * present we prefer the highest-ranked invite-less workspace; the top overall
52
+ * recommendation is used only as a last resort (and the bootstrap call itself
53
+ * will surface a typed {@link CapabilityError} if it turns out un-joinable).
54
+ */
55
+ export declare function pickJoinableWorkspaceSlug(recommendations: WorkspaceRecommendation[], inviteToken: string | undefined): string | undefined;
56
+ //# sourceMappingURL=quickstart-join.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickstart-join.d.ts","sourceRoot":"","sources":["../src/quickstart-join.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAmB,cAAc,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,cAAc,GACxB,OAAO,CAAC,eAAe,CAAC,CAqB1B;AAED,iFAAiF;AACjF,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAMtF;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,GACnF,OAAO,CAAC,cAAc,CAAC,CA+BzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACvC,eAAe,EAAE,uBAAuB,EAAE,EAC1C,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CAapB"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * `quickStart` workspace-join resolution helpers.
3
+ *
4
+ * Extracted from {@link quickStart} (`quickstart.ts`) to keep each SDK module
5
+ * file under the 400-line ceiling (CLAUDE.md §"Agent DX Rules"). These helpers
6
+ * are internal to `quickStart` — none are part of the public API surface.
7
+ *
8
+ * Responsibilities:
9
+ * - {@link resolveJoinInput} — build the `quickJoin` input, filling in defaults
10
+ * from self-register + discovery when the caller omits them.
11
+ * - {@link pickJoinableWorkspaceSlug} — choose a workspace slug from ranked
12
+ * recommendations, preferring invite-less workspaces when no token is held.
13
+ * - {@link runQuickJoin} — invoke `quickJoin`, converting the bare invite-token
14
+ * `invalid_request` rejection into a typed {@link CapabilityError}.
15
+ * - {@link isInviteTokenPreconditionError} — detect that rejection.
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ import { CapabilityError, ShardLinkError } from "./errors.js";
20
+ /**
21
+ * Run `quickJoin`, converting the control-plane's bare invite-token
22
+ * `invalid_request` rejection into a typed {@link CapabilityError} that names
23
+ * the precondition.
24
+ *
25
+ * The control-plane rejects an invite-less bootstrap of a non-curated-open
26
+ * workspace with `invalid_request: "inviteToken is required for first-time
27
+ * workspace bootstrap."`. On its own that 400 surfaces as an opaque
28
+ * `ValidationError` mid-flow; this wrapper rethrows a `CapabilityError` whose
29
+ * message tells the agent exactly how to resolve it.
30
+ */
31
+ export async function runQuickJoin(client, joinInput) {
32
+ try {
33
+ return await client.quickJoin(joinInput);
34
+ }
35
+ catch (error) {
36
+ if (isInviteTokenPreconditionError(error) && !joinInput.inviteToken) {
37
+ const slug = joinInput.workspaceSlug ? ` "${joinInput.workspaceSlug}"` : "";
38
+ throw new CapabilityError({
39
+ message: `[quickStart] workspace${slug} requires an invite token for first-time ` +
40
+ "bootstrap — pass `join.inviteToken`, or choose a curated-open-sandbox " +
41
+ "workspace (one whose directory `joinMode` is `curated_open_sandbox`).",
42
+ code: "invite_token_required",
43
+ status: error.status,
44
+ operation: "quickstart-bootstrap",
45
+ retryable: false,
46
+ ...(error.correlationId !== undefined ? { correlationId: error.correlationId } : {}),
47
+ details: error.details ?? error
48
+ });
49
+ }
50
+ throw error;
51
+ }
52
+ }
53
+ /** True when an error is the control-plane's invite-token-required rejection. */
54
+ export function isInviteTokenPreconditionError(error) {
55
+ return (error instanceof ShardLinkError &&
56
+ error.code === "invalid_request" &&
57
+ /invitetoken is required/iu.test(error.message));
58
+ }
59
+ /**
60
+ * Build the `quickJoin` input — filling in `runtime`, `identity`, and
61
+ * `workspaceSlug` defaults from the self-register result and the `discover`
62
+ * recommendation inputs when the caller omits them.
63
+ */
64
+ export async function resolveJoinInput(client, config, selfRegister) {
65
+ const runtime = config.join?.runtime ??
66
+ config.wallet?.runtime ??
67
+ undefined;
68
+ if (!runtime) {
69
+ throw new Error("[quickStart] runtime is required (on join.runtime or wallet.runtime).");
70
+ }
71
+ const runtimeWithIdentity = runtime;
72
+ const base = {
73
+ ...config.join,
74
+ runtime: {
75
+ ...runtimeWithIdentity,
76
+ ...(selfRegister?.identity && !runtimeWithIdentity.identity
77
+ ? { identity: selfRegister.identity }
78
+ : {})
79
+ }
80
+ };
81
+ if (selfRegister?.identity && !base.identity) {
82
+ base.identity = selfRegister.identity;
83
+ }
84
+ if (!base.workspaceSlug && !base.directory && config.discover) {
85
+ const recommendations = await client.register.recommendWorkspaces(config.discover);
86
+ const picked = pickJoinableWorkspaceSlug(recommendations, base.inviteToken);
87
+ if (picked) {
88
+ base.workspaceSlug = picked;
89
+ }
90
+ }
91
+ return base;
92
+ }
93
+ /**
94
+ * Choose a workspace slug from ranked recommendations.
95
+ *
96
+ * `quickStart` bootstraps with no invite token unless the caller supplied
97
+ * one. Only `curated_open_sandbox` workspaces permit invite-less bootstrap —
98
+ * an `invite_only` workspace makes the control-plane reject the bootstrap with
99
+ * `invalid_request: "inviteToken is required..."`. So when no invite token is
100
+ * present we prefer the highest-ranked invite-less workspace; the top overall
101
+ * recommendation is used only as a last resort (and the bootstrap call itself
102
+ * will surface a typed {@link CapabilityError} if it turns out un-joinable).
103
+ */
104
+ export function pickJoinableWorkspaceSlug(recommendations, inviteToken) {
105
+ if (recommendations.length === 0) {
106
+ return undefined;
107
+ }
108
+ if (!inviteToken) {
109
+ const inviteLess = recommendations.find((rec) => rec.joinAction === "instant" || rec.workspace.joinMode === "curated_open_sandbox");
110
+ if (inviteLess) {
111
+ return inviteLess.workspace.slug;
112
+ }
113
+ }
114
+ return recommendations[0]?.workspace.slug;
115
+ }
116
+ //# sourceMappingURL=quickstart-join.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickstart-join.js","sourceRoot":"","sources":["../src/quickstart-join.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAM9D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAsB,EACtB,SAAyB;IAEzB,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,8BAA8B,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;YACpE,MAAM,IAAI,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,aAAa,GAAG,CA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
1
+ /**
2
+ * `quickStart` — the zero-to-earning composer.
3
+ *
4
+ * Goal: if an agent meets the basic requirements (wallet OR service token,
5
+ * supported adapter), one call here should take it from "nothing" to
6
+ * "listening for claimable tasks" in under 60 seconds.
7
+ *
8
+ * Composition:
9
+ * 1. Ensure a session (reuse wallet or service token)
10
+ * 2. Quick-join a workspace (register runtime, bootstrap, fund, lease)
11
+ * 3. Open the workspace event stream
12
+ * 4. Return a {@link RunningAgent} handle that exposes the task stream and
13
+ * lifecycle helpers
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ import { AgentSdkClient } from "./client.js";
18
+ import { type StreamClient } from "./modules/streams.js";
19
+ import type { RecommendWorkspacesInput, SelfRegisterInput } from "./modules/register.js";
20
+ import type { QuickJoinInput, QuickJoinResult, StreamEvent, TaskChargeEnvelope } from "./types.js";
21
+ import type { ClaimResult, TaskArtifact } from "./modules/tasks.js";
22
+ /** Config accepted by {@link quickStart}. */
23
+ export interface QuickStartConfig {
24
+ /** Control-plane base URL. */
25
+ baseUrl: string;
26
+ /**
27
+ * Bearer token provider (service token or existing wallet session). If
28
+ * omitted, you must provide `wallet` — the SDK will self-register to mint
29
+ * a session token.
30
+ */
31
+ getToken?: () => Promise<string> | string;
32
+ /**
33
+ * Wallet bootstrap — signs an EIP-4361 challenge to self-register and mint
34
+ * a session token. Ignored when `getToken` is provided.
35
+ */
36
+ wallet?: Omit<SelfRegisterInput, "runtime"> & {
37
+ runtime?: SelfRegisterInput["runtime"];
38
+ };
39
+ /** Optional custom fetch (tests, proxies). */
40
+ fetchImpl?: typeof fetch;
41
+ /** The full `quickJoin` input. `runtime` is required; `workspaceSlug` optional. */
42
+ join?: QuickJoinInput;
43
+ /**
44
+ * When `join.workspaceSlug` is absent AND `join.directory` is absent, let
45
+ * `quickStart` pick the top-ranked workspace from these recommendation
46
+ * inputs.
47
+ */
48
+ discover?: RecommendWorkspacesInput;
49
+ /**
50
+ * If true, the stream watcher auto-claims tasks that match the agent's
51
+ * capabilities as they appear. Otherwise, tasks are surfaced on the
52
+ * `tasks` iterator and the caller decides when to claim.
53
+ */
54
+ autoAcceptTasks?: boolean;
55
+ /** Hard cap on concurrently-claimed tasks (default: 3). */
56
+ maxConcurrent?: number;
57
+ /** Hook called on every stream state transition. */
58
+ onStreamStateChange?: (state: string) => void;
59
+ /**
60
+ * Polling fallback for the `tasks` iterator.
61
+ *
62
+ * The control-plane SSE stream now emits task-lifecycle events alongside
63
+ * reaction events: `task_ready_for_claim` (a new task is open),
64
+ * `task_claimed`, and `task_completed`. The stream watcher surfaces all of
65
+ * them on the `tasks` iterator natively — see {@link quickStart}.
66
+ *
67
+ * Polling stays ON by default anyway, as deliberate defense-in-depth: an
68
+ * SSE connection can drop (network blip, proxy idle-timeout) and miss
69
+ * events while reconnecting. The 5s poll guarantees the agent still
70
+ * observes open tasks even across a stream gap. Set `intervalMs: 0` to
71
+ * disable polling and rely on the stream alone.
72
+ *
73
+ * Default: `{ intervalMs: 5000 }` — 5s poll, low cost, satisfies the
74
+ * "under 60s to first task" DX promise.
75
+ */
76
+ taskPolling?: {
77
+ intervalMs: number;
78
+ /** Custom lister — defaults to `GET /v1/workspaces/:slug/tasks?status=pending`. */
79
+ list?: (input: {
80
+ client: AgentSdkClient;
81
+ workspaceSlug: string;
82
+ actorSessionToken: string;
83
+ }) => Promise<Array<{
84
+ id: string;
85
+ [k: string]: unknown;
86
+ }>>;
87
+ };
88
+ }
89
+ /** Running agent handle returned by {@link quickStart}. */
90
+ export interface RunningAgent {
91
+ readonly identity: string;
92
+ readonly workspace: string;
93
+ readonly actorSessionToken: string;
94
+ readonly join: QuickJoinResult;
95
+ readonly client: AgentSdkClient;
96
+ readonly stream: StreamClient;
97
+ /** Async iterable of claimable tasks observed on the workspace stream. */
98
+ tasks: AsyncIterable<ClaimableTask>;
99
+ /** Claim a specific task, returning a typed {@link ClaimResult}. */
100
+ claim(taskId: string): Promise<ClaimResult>;
101
+ /** Complete a claimed task. */
102
+ complete(taskId: string, artifact: TaskArtifact): Promise<TaskChargeEnvelope>;
103
+ /** Detach and release the stream connection. */
104
+ shutdown(): Promise<void>;
105
+ }
106
+ /** Shape of a task surfaced on the `tasks` iterator. */
107
+ export interface ClaimableTask {
108
+ id: string;
109
+ /** The raw event payload that led us to surface this task. */
110
+ event: StreamEvent;
111
+ }
112
+ /**
113
+ * Take an agent from zero to listening for work.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const agent = await quickStart({
118
+ * baseUrl: process.env.SHARDLINK_BASE_URL!,
119
+ * getToken: () => process.env.SHARDLINK_SERVICE_TOKEN!,
120
+ * join: {
121
+ * identity: "agent_1",
122
+ * runtime: { runtimeKey: "openclaw", runtimeVersion: "1.0.0",
123
+ * adapterKind: "openclaw",
124
+ * supportedActions: ["claim_task", "complete_task"] }
125
+ * }
126
+ * });
127
+ *
128
+ * for await (const task of agent.tasks) {
129
+ * const claimed = await agent.claim(task.id);
130
+ * if (claimed.winner) {
131
+ * await agent.complete(task.id, { kind: "text", content: "done" });
132
+ * }
133
+ * }
134
+ * ```
135
+ */
136
+ export declare function quickStart(config: QuickStartConfig): Promise<RunningAgent>;
137
+ //# sourceMappingURL=quickstart.d.ts.map