@mindburn/helm-ai-kernel 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -0
- package/dist/adapters/agent-frameworks.d.ts +160 -0
- package/dist/adapters/agent-frameworks.js +289 -0
- package/dist/adapters/agent-frameworks.test.d.ts +1 -0
- package/dist/adapters/agent-frameworks.test.js +196 -0
- package/dist/client.d.ts +244 -0
- package/dist/client.js +371 -0
- package/dist/generated/google/protobuf/duration.d.ts +99 -0
- package/dist/generated/google/protobuf/duration.js +89 -0
- package/dist/generated/google/protobuf/timestamp.d.ts +129 -0
- package/dist/generated/google/protobuf/timestamp.js +89 -0
- package/dist/generated/helm/authority/v1/authority.d.ts +93 -0
- package/dist/generated/helm/authority/v1/authority.js +583 -0
- package/dist/generated/helm/effects/v1/effects.d.ts +115 -0
- package/dist/generated/helm/effects/v1/effects.js +983 -0
- package/dist/generated/helm/intervention/v1/intervention.d.ts +107 -0
- package/dist/generated/helm/intervention/v1/intervention.js +990 -0
- package/dist/generated/helm/kernel/v1/helm.d.ts +269 -0
- package/dist/generated/helm/kernel/v1/helm.js +2258 -0
- package/dist/generated/helm/truth/v1/truth.d.ts +151 -0
- package/dist/generated/helm/truth/v1/truth.js +1096 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +297 -0
- package/dist/types.gen.d.ts +6348 -0
- package/dist/types.gen.js +4174 -0
- package/package.json +47 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
// HELM SDK — TypeScript Client
|
|
2
|
+
// Ergonomic wrapper over generated types. Uses native fetch. Zero deps.
|
|
3
|
+
/** Thrown when the HELM API returns a non-2xx response. */
|
|
4
|
+
export class HelmApiError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
reasonCode;
|
|
7
|
+
details;
|
|
8
|
+
body;
|
|
9
|
+
constructor(status, body) {
|
|
10
|
+
const helmBody = isHelmError(body) ? body : undefined;
|
|
11
|
+
const message = helmBody?.error.message ?? `HELM API request failed with HTTP ${status}`;
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'HelmApiError';
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.reasonCode = helmBody?.error.reason_code ?? 'ERROR_INTERNAL';
|
|
16
|
+
this.details = helmBody?.error.details;
|
|
17
|
+
this.body = body;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function isHelmError(body) {
|
|
21
|
+
return typeof body === 'object'
|
|
22
|
+
&& body !== null
|
|
23
|
+
&& 'error' in body
|
|
24
|
+
&& typeof body.error === 'object'
|
|
25
|
+
&& body.error !== null
|
|
26
|
+
&& 'message' in (body.error)
|
|
27
|
+
&& 'reason_code' in (body.error);
|
|
28
|
+
}
|
|
29
|
+
export class HelmClient {
|
|
30
|
+
baseUrl;
|
|
31
|
+
headers;
|
|
32
|
+
timeout;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
35
|
+
this.timeout = config.timeout ?? 30_000;
|
|
36
|
+
this.headers = { 'Content-Type': 'application/json' };
|
|
37
|
+
if (config.apiKey) {
|
|
38
|
+
this.headers['Authorization'] = `Bearer ${config.apiKey}`;
|
|
39
|
+
}
|
|
40
|
+
if (config.tenantId) {
|
|
41
|
+
this.headers['X-Helm-Tenant-ID'] = config.tenantId;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// ── Internal ─────────────────────────────────────
|
|
45
|
+
async request(method, path, body) {
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
50
|
+
method,
|
|
51
|
+
headers: this.headers,
|
|
52
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
53
|
+
signal: controller.signal,
|
|
54
|
+
});
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const err = (await res.json());
|
|
57
|
+
throw new HelmApiError(res.status, err);
|
|
58
|
+
}
|
|
59
|
+
return (await res.json());
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// ── OpenAI Proxy ─────────────────────────────────
|
|
66
|
+
async chatCompletions(req) {
|
|
67
|
+
return this.request('POST', '/v1/chat/completions', req);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Send a chat completion request and extract kernel-issued governance metadata
|
|
71
|
+
* from X-Helm-* response headers. Use this instead of chatCompletions() when
|
|
72
|
+
* you need the kernel receipt.
|
|
73
|
+
*/
|
|
74
|
+
async chatCompletionsWithReceipt(req) {
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
77
|
+
try {
|
|
78
|
+
const res = await fetch(`${this.baseUrl}/v1/chat/completions`, {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
headers: this.headers,
|
|
81
|
+
body: JSON.stringify(req),
|
|
82
|
+
signal: controller.signal,
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok) {
|
|
85
|
+
const err = (await res.json());
|
|
86
|
+
throw new HelmApiError(res.status, err);
|
|
87
|
+
}
|
|
88
|
+
const response = (await res.json());
|
|
89
|
+
const governance = {
|
|
90
|
+
receiptId: res.headers.get('X-Helm-Receipt-ID') ?? '',
|
|
91
|
+
status: res.headers.get('X-Helm-Status') ?? '',
|
|
92
|
+
outputHash: res.headers.get('X-Helm-Output-Hash') ?? '',
|
|
93
|
+
lamportClock: parseInt(res.headers.get('X-Helm-Lamport-Clock') ?? '0', 10),
|
|
94
|
+
reasonCode: res.headers.get('X-Helm-Reason-Code') ?? '',
|
|
95
|
+
decisionId: res.headers.get('X-Helm-Decision-ID') ?? '',
|
|
96
|
+
proofGraphNode: res.headers.get('X-Helm-ProofGraph-Node') ?? '',
|
|
97
|
+
signature: res.headers.get('X-Helm-Signature') ?? '',
|
|
98
|
+
toolCalls: parseInt(res.headers.get('X-Helm-Tool-Calls') ?? '0', 10),
|
|
99
|
+
};
|
|
100
|
+
return { response, governance };
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// ── Decision Evaluation ──────────────────────────
|
|
107
|
+
async evaluateDecision(req) {
|
|
108
|
+
return this.request('POST', '/api/v1/evaluate', req);
|
|
109
|
+
}
|
|
110
|
+
async runPublicDemo(actionId, args = {}) {
|
|
111
|
+
return this.request('POST', '/api/demo/run', {
|
|
112
|
+
action_id: actionId,
|
|
113
|
+
policy_id: 'agent_tool_call_boundary',
|
|
114
|
+
args,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async verifyPublicDemoReceipt(receipt, expectedReceiptHash) {
|
|
118
|
+
return this.request('POST', '/api/demo/verify', {
|
|
119
|
+
receipt,
|
|
120
|
+
expected_receipt_hash: expectedReceiptHash,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// ── Approval Ceremony ────────────────────────────
|
|
124
|
+
async approveIntent(req) {
|
|
125
|
+
return this.request('POST', '/api/v1/kernel/approve', req);
|
|
126
|
+
}
|
|
127
|
+
// ── ProofGraph ───────────────────────────────────
|
|
128
|
+
async listSessions(limit = 50, offset = 0) {
|
|
129
|
+
return this.request('GET', `/api/v1/proofgraph/sessions?limit=${limit}&offset=${offset}`);
|
|
130
|
+
}
|
|
131
|
+
async getReceipts(sessionId) {
|
|
132
|
+
return this.request('GET', `/api/v1/proofgraph/sessions/${sessionId}/receipts`);
|
|
133
|
+
}
|
|
134
|
+
async getReceipt(receiptHash) {
|
|
135
|
+
return this.request('GET', `/api/v1/proofgraph/receipts/${receiptHash}`);
|
|
136
|
+
}
|
|
137
|
+
// ── Evidence ─────────────────────────────────────
|
|
138
|
+
async exportEvidence(sessionId) {
|
|
139
|
+
const controller = new AbortController();
|
|
140
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
141
|
+
try {
|
|
142
|
+
const res = await fetch(`${this.baseUrl}/api/v1/evidence/export`, {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: this.headers,
|
|
145
|
+
body: JSON.stringify({ session_id: sessionId, format: 'tar.gz' }),
|
|
146
|
+
signal: controller.signal,
|
|
147
|
+
});
|
|
148
|
+
if (!res.ok)
|
|
149
|
+
throw new HelmApiError(res.status, (await res.json()));
|
|
150
|
+
return res.blob();
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async verifyEvidence(bundle) {
|
|
157
|
+
const form = new FormData();
|
|
158
|
+
form.append('bundle', bundle);
|
|
159
|
+
const controller = new AbortController();
|
|
160
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
161
|
+
try {
|
|
162
|
+
const res = await fetch(`${this.baseUrl}/api/v1/evidence/verify`, {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
body: form,
|
|
165
|
+
signal: controller.signal,
|
|
166
|
+
});
|
|
167
|
+
if (!res.ok)
|
|
168
|
+
throw new HelmApiError(res.status, (await res.json()));
|
|
169
|
+
return (await res.json());
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async replayVerify(bundle) {
|
|
176
|
+
const form = new FormData();
|
|
177
|
+
form.append('bundle', bundle);
|
|
178
|
+
const controller = new AbortController();
|
|
179
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
180
|
+
try {
|
|
181
|
+
const res = await fetch(`${this.baseUrl}/api/v1/replay/verify`, {
|
|
182
|
+
method: 'POST',
|
|
183
|
+
body: form,
|
|
184
|
+
signal: controller.signal,
|
|
185
|
+
});
|
|
186
|
+
if (!res.ok)
|
|
187
|
+
throw new HelmApiError(res.status, (await res.json()));
|
|
188
|
+
return (await res.json());
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
clearTimeout(timer);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async createEvidenceEnvelopeManifest(req) {
|
|
195
|
+
return this.request('POST', '/api/v1/evidence/envelopes', req);
|
|
196
|
+
}
|
|
197
|
+
async listEvidenceEnvelopeManifests() {
|
|
198
|
+
return this.request('GET', '/api/v1/evidence/envelopes');
|
|
199
|
+
}
|
|
200
|
+
async getEvidenceEnvelopeManifest(manifestId) {
|
|
201
|
+
return this.request('GET', `/api/v1/evidence/envelopes/${encodeURIComponent(manifestId)}`);
|
|
202
|
+
}
|
|
203
|
+
async verifyEvidenceEnvelopeManifest(manifestId) {
|
|
204
|
+
return this.request('POST', `/api/v1/evidence/envelopes/${encodeURIComponent(manifestId)}/verify`);
|
|
205
|
+
}
|
|
206
|
+
async getEvidenceEnvelopePayload(manifestId) {
|
|
207
|
+
return this.request('GET', `/api/v1/evidence/envelopes/${encodeURIComponent(manifestId)}/payload`);
|
|
208
|
+
}
|
|
209
|
+
// ── Execution Boundary ───────────────────────────
|
|
210
|
+
async getBoundaryStatus() {
|
|
211
|
+
return this.request('GET', '/api/v1/boundary/status');
|
|
212
|
+
}
|
|
213
|
+
async listBoundaryCapabilities() {
|
|
214
|
+
return this.request('GET', '/api/v1/boundary/capabilities');
|
|
215
|
+
}
|
|
216
|
+
async listBoundaryRecords(query) {
|
|
217
|
+
const params = new URLSearchParams();
|
|
218
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
219
|
+
if (value !== undefined && value !== '')
|
|
220
|
+
params.set(key, String(value));
|
|
221
|
+
}
|
|
222
|
+
const qs = params.toString();
|
|
223
|
+
return this.request('GET', `/api/v1/boundary/records${qs ? `?${qs}` : ''}`);
|
|
224
|
+
}
|
|
225
|
+
async getBoundaryRecord(recordId) {
|
|
226
|
+
return this.request('GET', `/api/v1/boundary/records/${encodeURIComponent(recordId)}`);
|
|
227
|
+
}
|
|
228
|
+
async verifyBoundaryRecord(recordId) {
|
|
229
|
+
return this.request('POST', `/api/v1/boundary/records/${encodeURIComponent(recordId)}/verify`);
|
|
230
|
+
}
|
|
231
|
+
async listBoundaryCheckpoints() {
|
|
232
|
+
return this.request('GET', '/api/v1/boundary/checkpoints');
|
|
233
|
+
}
|
|
234
|
+
async createBoundaryCheckpoint() {
|
|
235
|
+
return this.request('POST', '/api/v1/boundary/checkpoints');
|
|
236
|
+
}
|
|
237
|
+
async verifyBoundaryCheckpoint(checkpointId) {
|
|
238
|
+
return this.request('POST', `/api/v1/boundary/checkpoints/${encodeURIComponent(checkpointId)}/verify`);
|
|
239
|
+
}
|
|
240
|
+
// ── Conformance ──────────────────────────────────
|
|
241
|
+
async conformanceRun(req) {
|
|
242
|
+
return this.request('POST', '/api/v1/conformance/run', req);
|
|
243
|
+
}
|
|
244
|
+
async getConformanceReport(reportId) {
|
|
245
|
+
return this.request('GET', `/api/v1/conformance/reports/${reportId}`);
|
|
246
|
+
}
|
|
247
|
+
async listConformanceReports() {
|
|
248
|
+
return this.request('GET', '/api/v1/conformance/reports');
|
|
249
|
+
}
|
|
250
|
+
async listConformanceVectors() {
|
|
251
|
+
return this.request('GET', '/api/v1/conformance/vectors');
|
|
252
|
+
}
|
|
253
|
+
async listNegativeConformanceVectors() {
|
|
254
|
+
return this.request('GET', '/api/v1/conformance/negative');
|
|
255
|
+
}
|
|
256
|
+
// ── MCP Registry ─────────────────────────────────
|
|
257
|
+
async listMcpRegistry() {
|
|
258
|
+
return this.request('GET', '/api/v1/mcp/registry');
|
|
259
|
+
}
|
|
260
|
+
async discoverMcpServer(req) {
|
|
261
|
+
return this.request('POST', '/api/v1/mcp/registry', req);
|
|
262
|
+
}
|
|
263
|
+
async approveMcpServer(req) {
|
|
264
|
+
return this.request('POST', '/api/v1/mcp/registry/approve', req);
|
|
265
|
+
}
|
|
266
|
+
async getMcpRegistryRecord(serverId) {
|
|
267
|
+
return this.request('GET', `/api/v1/mcp/registry/${encodeURIComponent(serverId)}`);
|
|
268
|
+
}
|
|
269
|
+
async approveMcpRegistryRecord(serverId, req) {
|
|
270
|
+
return this.request('POST', `/api/v1/mcp/registry/${encodeURIComponent(serverId)}/approve`, req);
|
|
271
|
+
}
|
|
272
|
+
async revokeMcpRegistryRecord(serverId, reason) {
|
|
273
|
+
return this.request('POST', `/api/v1/mcp/registry/${encodeURIComponent(serverId)}/revoke`, { reason });
|
|
274
|
+
}
|
|
275
|
+
async scanMcpServer(req) {
|
|
276
|
+
return this.request('POST', '/api/v1/mcp/scan', req);
|
|
277
|
+
}
|
|
278
|
+
async listMcpAuthProfiles() {
|
|
279
|
+
return this.request('GET', '/api/v1/mcp/auth-profiles');
|
|
280
|
+
}
|
|
281
|
+
async putMcpAuthProfile(profileId, profile) {
|
|
282
|
+
return this.request('PUT', `/api/v1/mcp/auth-profiles/${encodeURIComponent(profileId)}`, profile);
|
|
283
|
+
}
|
|
284
|
+
async authorizeMcpCall(req) {
|
|
285
|
+
return this.request('POST', '/api/v1/mcp/authorize-call', req);
|
|
286
|
+
}
|
|
287
|
+
async inspectSandboxGrants(runtime, profile, policyEpoch) {
|
|
288
|
+
const params = new URLSearchParams();
|
|
289
|
+
if (runtime)
|
|
290
|
+
params.set('runtime', runtime);
|
|
291
|
+
if (profile)
|
|
292
|
+
params.set('profile', profile);
|
|
293
|
+
if (policyEpoch)
|
|
294
|
+
params.set('policy_epoch', policyEpoch);
|
|
295
|
+
const query = params.toString();
|
|
296
|
+
return this.request('GET', `/api/v1/sandbox/grants/inspect${query ? `?${query}` : ''}`);
|
|
297
|
+
}
|
|
298
|
+
async listSandboxProfiles() {
|
|
299
|
+
return this.request('GET', '/api/v1/sandbox/profiles');
|
|
300
|
+
}
|
|
301
|
+
async listSandboxGrants() {
|
|
302
|
+
return this.request('GET', '/api/v1/sandbox/grants');
|
|
303
|
+
}
|
|
304
|
+
async createSandboxGrant(req) {
|
|
305
|
+
return this.request('POST', '/api/v1/sandbox/grants', req);
|
|
306
|
+
}
|
|
307
|
+
async getSandboxGrant(grantId) {
|
|
308
|
+
return this.request('GET', `/api/v1/sandbox/grants/${encodeURIComponent(grantId)}`);
|
|
309
|
+
}
|
|
310
|
+
async verifySandboxGrant(grantId) {
|
|
311
|
+
return this.request('POST', `/api/v1/sandbox/grants/${encodeURIComponent(grantId)}/verify`);
|
|
312
|
+
}
|
|
313
|
+
async preflightSandboxGrant(req) {
|
|
314
|
+
return this.request('POST', '/api/v1/sandbox/preflight', req);
|
|
315
|
+
}
|
|
316
|
+
// ── Identity, Authz, Approvals, Budgets ──────────
|
|
317
|
+
async listAgentIdentities() {
|
|
318
|
+
return this.request('GET', '/api/v1/identity/agents');
|
|
319
|
+
}
|
|
320
|
+
async getAuthzHealth() {
|
|
321
|
+
return this.request('GET', '/api/v1/authz/health');
|
|
322
|
+
}
|
|
323
|
+
async checkAuthz(req) {
|
|
324
|
+
return this.request('POST', '/api/v1/authz/check', req);
|
|
325
|
+
}
|
|
326
|
+
async listAuthzSnapshots() {
|
|
327
|
+
return this.request('GET', '/api/v1/authz/snapshots');
|
|
328
|
+
}
|
|
329
|
+
async getAuthzSnapshot(snapshotId) {
|
|
330
|
+
return this.request('GET', `/api/v1/authz/snapshots/${encodeURIComponent(snapshotId)}`);
|
|
331
|
+
}
|
|
332
|
+
async listApprovalCeremonies() {
|
|
333
|
+
return this.request('GET', '/api/v1/approvals');
|
|
334
|
+
}
|
|
335
|
+
async createApprovalCeremony(req) {
|
|
336
|
+
return this.request('POST', '/api/v1/approvals', req);
|
|
337
|
+
}
|
|
338
|
+
async transitionApprovalCeremony(approvalId, action, req = {}) {
|
|
339
|
+
return this.request('POST', `/api/v1/approvals/${encodeURIComponent(approvalId)}/${action}`, req);
|
|
340
|
+
}
|
|
341
|
+
async createApprovalWebAuthnChallenge(approvalId, req = {}) {
|
|
342
|
+
return this.request('POST', `/api/v1/approvals/${encodeURIComponent(approvalId)}/webauthn/challenge`, req);
|
|
343
|
+
}
|
|
344
|
+
async assertApprovalWebAuthnChallenge(approvalId, req) {
|
|
345
|
+
return this.request('POST', `/api/v1/approvals/${encodeURIComponent(approvalId)}/webauthn/assert`, req);
|
|
346
|
+
}
|
|
347
|
+
async listBudgetCeilings() {
|
|
348
|
+
return this.request('GET', '/api/v1/budgets');
|
|
349
|
+
}
|
|
350
|
+
async putBudgetCeiling(budgetId, req) {
|
|
351
|
+
return this.request('PUT', `/api/v1/budgets/${encodeURIComponent(budgetId)}`, req);
|
|
352
|
+
}
|
|
353
|
+
// ── Telemetry and Coexistence ────────────────────
|
|
354
|
+
async getCoexistenceCapabilities() {
|
|
355
|
+
return this.request('GET', '/api/v1/coexistence/capabilities');
|
|
356
|
+
}
|
|
357
|
+
async getTelemetryOTelConfig() {
|
|
358
|
+
return this.request('GET', '/api/v1/telemetry/otel/config');
|
|
359
|
+
}
|
|
360
|
+
async exportTelemetry(req) {
|
|
361
|
+
return this.request('POST', '/api/v1/telemetry/export', req);
|
|
362
|
+
}
|
|
363
|
+
// ── System ───────────────────────────────────────
|
|
364
|
+
async health() {
|
|
365
|
+
return this.request('GET', '/healthz');
|
|
366
|
+
}
|
|
367
|
+
async version() {
|
|
368
|
+
return this.request('GET', '/version');
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
export default HelmClient;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
2
|
+
export declare const protobufPackage = "google.protobuf";
|
|
3
|
+
/**
|
|
4
|
+
* A Duration represents a signed, fixed-length span of time represented
|
|
5
|
+
* as a count of seconds and fractions of seconds at nanosecond
|
|
6
|
+
* resolution. It is independent of any calendar and concepts like "day"
|
|
7
|
+
* or "month". It is related to Timestamp in that the difference between
|
|
8
|
+
* two Timestamp values is a Duration and it can be added or subtracted
|
|
9
|
+
* from a Timestamp. Range is approximately +-10,000 years.
|
|
10
|
+
*
|
|
11
|
+
* # Examples
|
|
12
|
+
*
|
|
13
|
+
* Example 1: Compute Duration from two Timestamps in pseudo code.
|
|
14
|
+
*
|
|
15
|
+
* Timestamp start = ...;
|
|
16
|
+
* Timestamp end = ...;
|
|
17
|
+
* Duration duration = ...;
|
|
18
|
+
*
|
|
19
|
+
* duration.seconds = end.seconds - start.seconds;
|
|
20
|
+
* duration.nanos = end.nanos - start.nanos;
|
|
21
|
+
*
|
|
22
|
+
* if (duration.seconds < 0 && duration.nanos > 0) {
|
|
23
|
+
* duration.seconds += 1;
|
|
24
|
+
* duration.nanos -= 1000000000;
|
|
25
|
+
* } else if (duration.seconds > 0 && duration.nanos < 0) {
|
|
26
|
+
* duration.seconds -= 1;
|
|
27
|
+
* duration.nanos += 1000000000;
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
|
|
31
|
+
*
|
|
32
|
+
* Timestamp start = ...;
|
|
33
|
+
* Duration duration = ...;
|
|
34
|
+
* Timestamp end = ...;
|
|
35
|
+
*
|
|
36
|
+
* end.seconds = start.seconds + duration.seconds;
|
|
37
|
+
* end.nanos = start.nanos + duration.nanos;
|
|
38
|
+
*
|
|
39
|
+
* if (end.nanos < 0) {
|
|
40
|
+
* end.seconds -= 1;
|
|
41
|
+
* end.nanos += 1000000000;
|
|
42
|
+
* } else if (end.nanos >= 1000000000) {
|
|
43
|
+
* end.seconds += 1;
|
|
44
|
+
* end.nanos -= 1000000000;
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* Example 3: Compute Duration from datetime.timedelta in Python.
|
|
48
|
+
*
|
|
49
|
+
* td = datetime.timedelta(days=3, minutes=10)
|
|
50
|
+
* duration = Duration()
|
|
51
|
+
* duration.FromTimedelta(td)
|
|
52
|
+
*
|
|
53
|
+
* # JSON Mapping
|
|
54
|
+
*
|
|
55
|
+
* In JSON format, the Duration type is encoded as a string rather than an
|
|
56
|
+
* object, where the string ends in the suffix "s" (indicating seconds) and
|
|
57
|
+
* is preceded by the number of seconds, with nanoseconds expressed as
|
|
58
|
+
* fractional seconds. For example, 3 seconds with 0 nanoseconds should be
|
|
59
|
+
* encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
|
|
60
|
+
* be expressed in JSON format as "3.000000001s", and 3 seconds and 1
|
|
61
|
+
* microsecond should be expressed in JSON format as "3.000001s".
|
|
62
|
+
*/
|
|
63
|
+
export interface Duration {
|
|
64
|
+
/**
|
|
65
|
+
* Signed seconds of the span of time. Must be from -315,576,000,000
|
|
66
|
+
* to +315,576,000,000 inclusive. Note: these bounds are computed from:
|
|
67
|
+
* 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
|
|
68
|
+
*/
|
|
69
|
+
seconds: number;
|
|
70
|
+
/**
|
|
71
|
+
* Signed fractions of a second at nanosecond resolution of the span
|
|
72
|
+
* of time. Durations less than one second are represented with a 0
|
|
73
|
+
* `seconds` field and a positive or negative `nanos` field. For durations
|
|
74
|
+
* of one second or more, a non-zero value for the `nanos` field must be
|
|
75
|
+
* of the same sign as the `seconds` field. Must be from -999,999,999
|
|
76
|
+
* to +999,999,999 inclusive.
|
|
77
|
+
*/
|
|
78
|
+
nanos: number;
|
|
79
|
+
}
|
|
80
|
+
export declare const Duration: MessageFns<Duration>;
|
|
81
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
82
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
83
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
84
|
+
} : Partial<T>;
|
|
85
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
86
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
87
|
+
[K in keyof P]: Exact<P[K], I[K]>;
|
|
88
|
+
} & {
|
|
89
|
+
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
|
90
|
+
};
|
|
91
|
+
export interface MessageFns<T> {
|
|
92
|
+
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
|
93
|
+
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
|
94
|
+
fromJSON(object: any): T;
|
|
95
|
+
toJSON(message: T): unknown;
|
|
96
|
+
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
|
|
97
|
+
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
|
|
98
|
+
}
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
2
|
+
// versions:
|
|
3
|
+
// protoc-gen-ts_proto v2.11.6
|
|
4
|
+
// protoc v7.34.1
|
|
5
|
+
// source: google/protobuf/duration.proto
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
8
|
+
export const protobufPackage = "google.protobuf";
|
|
9
|
+
function createBaseDuration() {
|
|
10
|
+
return { seconds: 0, nanos: 0 };
|
|
11
|
+
}
|
|
12
|
+
export const Duration = {
|
|
13
|
+
encode(message, writer = new BinaryWriter()) {
|
|
14
|
+
if (message.seconds !== 0) {
|
|
15
|
+
writer.uint32(8).int64(message.seconds);
|
|
16
|
+
}
|
|
17
|
+
if (message.nanos !== 0) {
|
|
18
|
+
writer.uint32(16).int32(message.nanos);
|
|
19
|
+
}
|
|
20
|
+
return writer;
|
|
21
|
+
},
|
|
22
|
+
decode(input, length) {
|
|
23
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
24
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
25
|
+
const message = createBaseDuration();
|
|
26
|
+
while (reader.pos < end) {
|
|
27
|
+
const tag = reader.uint32();
|
|
28
|
+
switch (tag >>> 3) {
|
|
29
|
+
case 1: {
|
|
30
|
+
if (tag !== 8) {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
message.seconds = longToNumber(reader.int64());
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
case 2: {
|
|
37
|
+
if (tag !== 16) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
message.nanos = reader.int32();
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
reader.skip(tag & 7);
|
|
48
|
+
}
|
|
49
|
+
return message;
|
|
50
|
+
},
|
|
51
|
+
fromJSON(object) {
|
|
52
|
+
return {
|
|
53
|
+
seconds: isSet(object.seconds) ? globalThis.Number(object.seconds) : 0,
|
|
54
|
+
nanos: isSet(object.nanos) ? globalThis.Number(object.nanos) : 0,
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
toJSON(message) {
|
|
58
|
+
const obj = {};
|
|
59
|
+
if (message.seconds !== 0) {
|
|
60
|
+
obj.seconds = Math.round(message.seconds);
|
|
61
|
+
}
|
|
62
|
+
if (message.nanos !== 0) {
|
|
63
|
+
obj.nanos = Math.round(message.nanos);
|
|
64
|
+
}
|
|
65
|
+
return obj;
|
|
66
|
+
},
|
|
67
|
+
create(base) {
|
|
68
|
+
return Duration.fromPartial(base ?? {});
|
|
69
|
+
},
|
|
70
|
+
fromPartial(object) {
|
|
71
|
+
const message = createBaseDuration();
|
|
72
|
+
message.seconds = object.seconds ?? 0;
|
|
73
|
+
message.nanos = object.nanos ?? 0;
|
|
74
|
+
return message;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
function longToNumber(int64) {
|
|
78
|
+
const num = globalThis.Number(int64.toString());
|
|
79
|
+
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
|
|
80
|
+
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
|
|
81
|
+
}
|
|
82
|
+
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
|
|
83
|
+
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
|
|
84
|
+
}
|
|
85
|
+
return num;
|
|
86
|
+
}
|
|
87
|
+
function isSet(value) {
|
|
88
|
+
return value !== null && value !== undefined;
|
|
89
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
2
|
+
export declare const protobufPackage = "google.protobuf";
|
|
3
|
+
/**
|
|
4
|
+
* A Timestamp represents a point in time independent of any time zone or local
|
|
5
|
+
* calendar, encoded as a count of seconds and fractions of seconds at
|
|
6
|
+
* nanosecond resolution. The count is relative to an epoch at UTC midnight on
|
|
7
|
+
* January 1, 1970, in the proleptic Gregorian calendar which extends the
|
|
8
|
+
* Gregorian calendar backwards to year one.
|
|
9
|
+
*
|
|
10
|
+
* All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
|
|
11
|
+
* second table is needed for interpretation, using a [24-hour linear
|
|
12
|
+
* smear](https://developers.google.com/time/smear).
|
|
13
|
+
*
|
|
14
|
+
* The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
|
|
15
|
+
* restricting to that range, we ensure that we can convert to and from [RFC
|
|
16
|
+
* 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
|
|
17
|
+
*
|
|
18
|
+
* # Examples
|
|
19
|
+
*
|
|
20
|
+
* Example 1: Compute Timestamp from POSIX `time()`.
|
|
21
|
+
*
|
|
22
|
+
* Timestamp timestamp;
|
|
23
|
+
* timestamp.set_seconds(time(NULL));
|
|
24
|
+
* timestamp.set_nanos(0);
|
|
25
|
+
*
|
|
26
|
+
* Example 2: Compute Timestamp from POSIX `gettimeofday()`.
|
|
27
|
+
*
|
|
28
|
+
* struct timeval tv;
|
|
29
|
+
* gettimeofday(&tv, NULL);
|
|
30
|
+
*
|
|
31
|
+
* Timestamp timestamp;
|
|
32
|
+
* timestamp.set_seconds(tv.tv_sec);
|
|
33
|
+
* timestamp.set_nanos(tv.tv_usec * 1000);
|
|
34
|
+
*
|
|
35
|
+
* Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
|
|
36
|
+
*
|
|
37
|
+
* FILETIME ft;
|
|
38
|
+
* GetSystemTimeAsFileTime(&ft);
|
|
39
|
+
* UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
|
|
40
|
+
*
|
|
41
|
+
* // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
|
|
42
|
+
* // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
|
|
43
|
+
* Timestamp timestamp;
|
|
44
|
+
* timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
|
|
45
|
+
* timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
|
|
46
|
+
*
|
|
47
|
+
* Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
|
|
48
|
+
*
|
|
49
|
+
* long millis = System.currentTimeMillis();
|
|
50
|
+
*
|
|
51
|
+
* Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
|
|
52
|
+
* .setNanos((int) ((millis % 1000) * 1000000)).build();
|
|
53
|
+
*
|
|
54
|
+
* Example 5: Compute Timestamp from Java `Instant.now()`.
|
|
55
|
+
*
|
|
56
|
+
* Instant now = Instant.now();
|
|
57
|
+
*
|
|
58
|
+
* Timestamp timestamp =
|
|
59
|
+
* Timestamp.newBuilder().setSeconds(now.getEpochSecond())
|
|
60
|
+
* .setNanos(now.getNano()).build();
|
|
61
|
+
*
|
|
62
|
+
* Example 6: Compute Timestamp from current time in Python.
|
|
63
|
+
*
|
|
64
|
+
* timestamp = Timestamp()
|
|
65
|
+
* timestamp.GetCurrentTime()
|
|
66
|
+
*
|
|
67
|
+
* # JSON Mapping
|
|
68
|
+
*
|
|
69
|
+
* In JSON format, the Timestamp type is encoded as a string in the
|
|
70
|
+
* [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
|
|
71
|
+
* format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
|
|
72
|
+
* where {year} is always expressed using four digits while {month}, {day},
|
|
73
|
+
* {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
|
|
74
|
+
* seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
|
|
75
|
+
* are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
|
|
76
|
+
* is required. A ProtoJSON serializer should always use UTC (as indicated by
|
|
77
|
+
* "Z") when printing the Timestamp type and a ProtoJSON parser should be
|
|
78
|
+
* able to accept both UTC and other timezones (as indicated by an offset).
|
|
79
|
+
*
|
|
80
|
+
* For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
|
|
81
|
+
* 01:30 UTC on January 15, 2017.
|
|
82
|
+
*
|
|
83
|
+
* In JavaScript, one can convert a Date object to this format using the
|
|
84
|
+
* standard
|
|
85
|
+
* [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
|
|
86
|
+
* method. In Python, a standard `datetime.datetime` object can be converted
|
|
87
|
+
* to this format using
|
|
88
|
+
* [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
|
|
89
|
+
* the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
|
|
90
|
+
* the Joda Time's [`ISODateTimeFormat.dateTime()`](
|
|
91
|
+
* http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
|
|
92
|
+
* ) to obtain a formatter capable of generating timestamps in this format.
|
|
93
|
+
*/
|
|
94
|
+
export interface Timestamp {
|
|
95
|
+
/**
|
|
96
|
+
* Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must
|
|
97
|
+
* be between -62135596800 and 253402300799 inclusive (which corresponds to
|
|
98
|
+
* 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z).
|
|
99
|
+
*/
|
|
100
|
+
seconds: number;
|
|
101
|
+
/**
|
|
102
|
+
* Non-negative fractions of a second at nanosecond resolution. This field is
|
|
103
|
+
* the nanosecond portion of the duration, not an alternative to seconds.
|
|
104
|
+
* Negative second values with fractions must still have non-negative nanos
|
|
105
|
+
* values that count forward in time. Must be between 0 and 999,999,999
|
|
106
|
+
* inclusive.
|
|
107
|
+
*/
|
|
108
|
+
nanos: number;
|
|
109
|
+
}
|
|
110
|
+
export declare const Timestamp: MessageFns<Timestamp>;
|
|
111
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
112
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
113
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
114
|
+
} : Partial<T>;
|
|
115
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
116
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
117
|
+
[K in keyof P]: Exact<P[K], I[K]>;
|
|
118
|
+
} & {
|
|
119
|
+
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
|
120
|
+
};
|
|
121
|
+
export interface MessageFns<T> {
|
|
122
|
+
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
|
123
|
+
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
|
124
|
+
fromJSON(object: any): T;
|
|
125
|
+
toJSON(message: T): unknown;
|
|
126
|
+
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
|
|
127
|
+
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
|
|
128
|
+
}
|
|
129
|
+
export {};
|