@sekuire/sdk 0.1.23 → 0.1.24
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/dist/a2a-client.d.ts +8 -0
- package/dist/a2a-delegator.d.ts +2 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.esm.js +35 -11
- package/dist/index.js +35 -11
- package/dist/sdk.d.ts +3 -0
- package/package.json +1 -1
package/dist/a2a-client.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export interface A2AClientOptions {
|
|
|
13
13
|
timeout?: number;
|
|
14
14
|
/** Optional device fingerprint for API-key auth on task endpoints */
|
|
15
15
|
deviceFingerprint?: string;
|
|
16
|
+
/** Optional runtime token resolver for per-request credential sync */
|
|
17
|
+
tokenResolver?: () => string | undefined;
|
|
18
|
+
/** Optional callback to refresh credentials after runtime-token 401 */
|
|
19
|
+
onUnauthorized?: () => Promise<void>;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* A2A Protocol Client
|
|
@@ -45,6 +49,8 @@ export declare class A2AClient {
|
|
|
45
49
|
private runtimeToken;
|
|
46
50
|
private timeout;
|
|
47
51
|
private deviceFingerprint;
|
|
52
|
+
private tokenResolver?;
|
|
53
|
+
private onUnauthorized?;
|
|
48
54
|
constructor(options: A2AClientOptions);
|
|
49
55
|
setRuntimeToken(token: string): void;
|
|
50
56
|
/**
|
|
@@ -110,6 +116,8 @@ export declare class A2AClient {
|
|
|
110
116
|
private jsonRpc;
|
|
111
117
|
private fetch;
|
|
112
118
|
private fetchTask;
|
|
119
|
+
private doFetchTask;
|
|
120
|
+
private resolveRuntimeToken;
|
|
113
121
|
private taskAuthHeaders;
|
|
114
122
|
private isLikelyJwt;
|
|
115
123
|
}
|
package/dist/a2a-delegator.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface DelegatorConfig {
|
|
|
17
17
|
retryDelayMs?: number;
|
|
18
18
|
retryBackoffMultiplier?: number;
|
|
19
19
|
policyGateway?: PolicyGateway;
|
|
20
|
+
tokenResolver?: () => string | undefined;
|
|
21
|
+
onUnauthorized?: () => Promise<void>;
|
|
20
22
|
}
|
|
21
23
|
export interface DelegationRequest {
|
|
22
24
|
skill: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -305,6 +305,8 @@ interface DelegatorConfig {
|
|
|
305
305
|
retryDelayMs?: number;
|
|
306
306
|
retryBackoffMultiplier?: number;
|
|
307
307
|
policyGateway?: PolicyGateway;
|
|
308
|
+
tokenResolver?: () => string | undefined;
|
|
309
|
+
onUnauthorized?: () => Promise<void>;
|
|
308
310
|
}
|
|
309
311
|
interface DelegationRequest {
|
|
310
312
|
skill: string;
|
|
@@ -1079,6 +1081,9 @@ declare class SekuireSDK {
|
|
|
1079
1081
|
createDelegator(options?: {
|
|
1080
1082
|
timeout?: number;
|
|
1081
1083
|
pollInterval?: number;
|
|
1084
|
+
maxRetries?: number;
|
|
1085
|
+
retryDelayMs?: number;
|
|
1086
|
+
retryBackoffMultiplier?: number;
|
|
1082
1087
|
}): A2ATaskDelegator;
|
|
1083
1088
|
/**
|
|
1084
1089
|
* Get the agent ID.
|
|
@@ -3362,6 +3367,10 @@ interface A2AClientOptions {
|
|
|
3362
3367
|
timeout?: number;
|
|
3363
3368
|
/** Optional device fingerprint for API-key auth on task endpoints */
|
|
3364
3369
|
deviceFingerprint?: string;
|
|
3370
|
+
/** Optional runtime token resolver for per-request credential sync */
|
|
3371
|
+
tokenResolver?: () => string | undefined;
|
|
3372
|
+
/** Optional callback to refresh credentials after runtime-token 401 */
|
|
3373
|
+
onUnauthorized?: () => Promise<void>;
|
|
3365
3374
|
}
|
|
3366
3375
|
/**
|
|
3367
3376
|
* A2A Protocol Client
|
|
@@ -3394,6 +3403,8 @@ declare class A2AClient {
|
|
|
3394
3403
|
private runtimeToken;
|
|
3395
3404
|
private timeout;
|
|
3396
3405
|
private deviceFingerprint;
|
|
3406
|
+
private tokenResolver?;
|
|
3407
|
+
private onUnauthorized?;
|
|
3397
3408
|
constructor(options: A2AClientOptions);
|
|
3398
3409
|
setRuntimeToken(token: string): void;
|
|
3399
3410
|
/**
|
|
@@ -3459,6 +3470,8 @@ declare class A2AClient {
|
|
|
3459
3470
|
private jsonRpc;
|
|
3460
3471
|
private fetch;
|
|
3461
3472
|
private fetchTask;
|
|
3473
|
+
private doFetchTask;
|
|
3474
|
+
private resolveRuntimeToken;
|
|
3462
3475
|
private taskAuthHeaders;
|
|
3463
3476
|
private isLikelyJwt;
|
|
3464
3477
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -69,6 +69,8 @@ class A2AClient {
|
|
|
69
69
|
options.deviceFingerprint ||
|
|
70
70
|
process.env.SEKUIRE_DEVICE_FINGERPRINT ||
|
|
71
71
|
"sekuire-typescript-sdk";
|
|
72
|
+
this.tokenResolver = options.tokenResolver;
|
|
73
|
+
this.onUnauthorized = options.onUnauthorized;
|
|
72
74
|
}
|
|
73
75
|
setRuntimeToken(token) {
|
|
74
76
|
this.runtimeToken = token;
|
|
@@ -78,7 +80,7 @@ class A2AClient {
|
|
|
78
80
|
* The API will find an agent with the matching skill and forward the task.
|
|
79
81
|
*/
|
|
80
82
|
async sendBySkill(request) {
|
|
81
|
-
const response = await this.
|
|
83
|
+
const response = await this.fetchTask("/a2a/route", {
|
|
82
84
|
method: "POST",
|
|
83
85
|
body: JSON.stringify(request),
|
|
84
86
|
});
|
|
@@ -291,19 +293,37 @@ class A2AClient {
|
|
|
291
293
|
});
|
|
292
294
|
}
|
|
293
295
|
async fetchTask(path, init) {
|
|
296
|
+
const runtimeToken = this.resolveRuntimeToken();
|
|
297
|
+
const response = await this.doFetchTask(path, init, runtimeToken);
|
|
298
|
+
const usedRuntimeToken = !!runtimeToken && runtimeToken.startsWith("srt_");
|
|
299
|
+
if (response.status === 401 && usedRuntimeToken && this.onUnauthorized) {
|
|
300
|
+
try {
|
|
301
|
+
await this.onUnauthorized();
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
return response;
|
|
305
|
+
}
|
|
306
|
+
return this.doFetchTask(path, init, this.resolveRuntimeToken());
|
|
307
|
+
}
|
|
308
|
+
return response;
|
|
309
|
+
}
|
|
310
|
+
async doFetchTask(path, init, runtimeToken) {
|
|
294
311
|
return fetch(`${this.baseUrl}${path}`, {
|
|
295
312
|
...init,
|
|
296
313
|
headers: {
|
|
297
314
|
"Content-Type": "application/json",
|
|
298
|
-
...this.taskAuthHeaders(),
|
|
315
|
+
...this.taskAuthHeaders(runtimeToken),
|
|
299
316
|
...init.headers,
|
|
300
317
|
},
|
|
301
318
|
signal: AbortSignal.timeout(this.timeout),
|
|
302
319
|
});
|
|
303
320
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
321
|
+
resolveRuntimeToken() {
|
|
322
|
+
return this.tokenResolver?.() ?? this.runtimeToken;
|
|
323
|
+
}
|
|
324
|
+
taskAuthHeaders(runtimeToken) {
|
|
325
|
+
if (runtimeToken) {
|
|
326
|
+
return { Authorization: `Bearer ${runtimeToken}` };
|
|
307
327
|
}
|
|
308
328
|
if (this.isLikelyJwt(this.authToken)) {
|
|
309
329
|
return { Authorization: `Bearer ${this.authToken}` };
|
|
@@ -396,6 +416,8 @@ class A2ATaskDelegator {
|
|
|
396
416
|
baseUrl: config.apiUrl,
|
|
397
417
|
authToken: config.authToken,
|
|
398
418
|
timeout: this.config.timeout,
|
|
419
|
+
tokenResolver: config.tokenResolver,
|
|
420
|
+
onUnauthorized: config.onUnauthorized,
|
|
399
421
|
});
|
|
400
422
|
}
|
|
401
423
|
setRuntimeToken(token) {
|
|
@@ -3601,20 +3623,22 @@ class SekuireSDK {
|
|
|
3601
3623
|
* task registration/completion can use runtime token if bootstrapped.
|
|
3602
3624
|
*/
|
|
3603
3625
|
createDelegator(options) {
|
|
3604
|
-
|
|
3605
|
-
const delegator = new A2ATaskDelegator({
|
|
3626
|
+
return new A2ATaskDelegator({
|
|
3606
3627
|
apiUrl: this.config.apiUrl,
|
|
3607
3628
|
authToken: this.config.apiKey || "",
|
|
3608
3629
|
workspaceId: this.config.workspaceId,
|
|
3609
3630
|
agentId: this.config.agentId,
|
|
3610
3631
|
timeout: options?.timeout,
|
|
3611
3632
|
pollInterval: options?.pollInterval,
|
|
3633
|
+
maxRetries: options?.maxRetries,
|
|
3634
|
+
retryDelayMs: options?.retryDelayMs,
|
|
3635
|
+
retryBackoffMultiplier: options?.retryBackoffMultiplier,
|
|
3612
3636
|
policyGateway: this.policyGateway ?? undefined,
|
|
3637
|
+
tokenResolver: () => this.credentialsStore.getRuntimeToken(),
|
|
3638
|
+
onUnauthorized: async () => {
|
|
3639
|
+
await this.credentialsStore.refreshRuntimeToken("A2AClient");
|
|
3640
|
+
},
|
|
3613
3641
|
});
|
|
3614
|
-
if (credentials?.runtimeToken) {
|
|
3615
|
-
delegator.setRuntimeToken(credentials.runtimeToken);
|
|
3616
|
-
}
|
|
3617
|
-
return delegator;
|
|
3618
3642
|
}
|
|
3619
3643
|
/**
|
|
3620
3644
|
* Get the agent ID.
|
package/dist/index.js
CHANGED
|
@@ -93,6 +93,8 @@ class A2AClient {
|
|
|
93
93
|
options.deviceFingerprint ||
|
|
94
94
|
process.env.SEKUIRE_DEVICE_FINGERPRINT ||
|
|
95
95
|
"sekuire-typescript-sdk";
|
|
96
|
+
this.tokenResolver = options.tokenResolver;
|
|
97
|
+
this.onUnauthorized = options.onUnauthorized;
|
|
96
98
|
}
|
|
97
99
|
setRuntimeToken(token) {
|
|
98
100
|
this.runtimeToken = token;
|
|
@@ -102,7 +104,7 @@ class A2AClient {
|
|
|
102
104
|
* The API will find an agent with the matching skill and forward the task.
|
|
103
105
|
*/
|
|
104
106
|
async sendBySkill(request) {
|
|
105
|
-
const response = await this.
|
|
107
|
+
const response = await this.fetchTask("/a2a/route", {
|
|
106
108
|
method: "POST",
|
|
107
109
|
body: JSON.stringify(request),
|
|
108
110
|
});
|
|
@@ -315,19 +317,37 @@ class A2AClient {
|
|
|
315
317
|
});
|
|
316
318
|
}
|
|
317
319
|
async fetchTask(path, init) {
|
|
320
|
+
const runtimeToken = this.resolveRuntimeToken();
|
|
321
|
+
const response = await this.doFetchTask(path, init, runtimeToken);
|
|
322
|
+
const usedRuntimeToken = !!runtimeToken && runtimeToken.startsWith("srt_");
|
|
323
|
+
if (response.status === 401 && usedRuntimeToken && this.onUnauthorized) {
|
|
324
|
+
try {
|
|
325
|
+
await this.onUnauthorized();
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
return response;
|
|
329
|
+
}
|
|
330
|
+
return this.doFetchTask(path, init, this.resolveRuntimeToken());
|
|
331
|
+
}
|
|
332
|
+
return response;
|
|
333
|
+
}
|
|
334
|
+
async doFetchTask(path, init, runtimeToken) {
|
|
318
335
|
return fetch(`${this.baseUrl}${path}`, {
|
|
319
336
|
...init,
|
|
320
337
|
headers: {
|
|
321
338
|
"Content-Type": "application/json",
|
|
322
|
-
...this.taskAuthHeaders(),
|
|
339
|
+
...this.taskAuthHeaders(runtimeToken),
|
|
323
340
|
...init.headers,
|
|
324
341
|
},
|
|
325
342
|
signal: AbortSignal.timeout(this.timeout),
|
|
326
343
|
});
|
|
327
344
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
345
|
+
resolveRuntimeToken() {
|
|
346
|
+
return this.tokenResolver?.() ?? this.runtimeToken;
|
|
347
|
+
}
|
|
348
|
+
taskAuthHeaders(runtimeToken) {
|
|
349
|
+
if (runtimeToken) {
|
|
350
|
+
return { Authorization: `Bearer ${runtimeToken}` };
|
|
331
351
|
}
|
|
332
352
|
if (this.isLikelyJwt(this.authToken)) {
|
|
333
353
|
return { Authorization: `Bearer ${this.authToken}` };
|
|
@@ -420,6 +440,8 @@ class A2ATaskDelegator {
|
|
|
420
440
|
baseUrl: config.apiUrl,
|
|
421
441
|
authToken: config.authToken,
|
|
422
442
|
timeout: this.config.timeout,
|
|
443
|
+
tokenResolver: config.tokenResolver,
|
|
444
|
+
onUnauthorized: config.onUnauthorized,
|
|
423
445
|
});
|
|
424
446
|
}
|
|
425
447
|
setRuntimeToken(token) {
|
|
@@ -3625,20 +3647,22 @@ class SekuireSDK {
|
|
|
3625
3647
|
* task registration/completion can use runtime token if bootstrapped.
|
|
3626
3648
|
*/
|
|
3627
3649
|
createDelegator(options) {
|
|
3628
|
-
|
|
3629
|
-
const delegator = new A2ATaskDelegator({
|
|
3650
|
+
return new A2ATaskDelegator({
|
|
3630
3651
|
apiUrl: this.config.apiUrl,
|
|
3631
3652
|
authToken: this.config.apiKey || "",
|
|
3632
3653
|
workspaceId: this.config.workspaceId,
|
|
3633
3654
|
agentId: this.config.agentId,
|
|
3634
3655
|
timeout: options?.timeout,
|
|
3635
3656
|
pollInterval: options?.pollInterval,
|
|
3657
|
+
maxRetries: options?.maxRetries,
|
|
3658
|
+
retryDelayMs: options?.retryDelayMs,
|
|
3659
|
+
retryBackoffMultiplier: options?.retryBackoffMultiplier,
|
|
3636
3660
|
policyGateway: this.policyGateway ?? undefined,
|
|
3661
|
+
tokenResolver: () => this.credentialsStore.getRuntimeToken(),
|
|
3662
|
+
onUnauthorized: async () => {
|
|
3663
|
+
await this.credentialsStore.refreshRuntimeToken("A2AClient");
|
|
3664
|
+
},
|
|
3637
3665
|
});
|
|
3638
|
-
if (credentials?.runtimeToken) {
|
|
3639
|
-
delegator.setRuntimeToken(credentials.runtimeToken);
|
|
3640
|
-
}
|
|
3641
|
-
return delegator;
|
|
3642
3666
|
}
|
|
3643
3667
|
/**
|
|
3644
3668
|
* Get the agent ID.
|
package/dist/sdk.d.ts
CHANGED
|
@@ -205,6 +205,9 @@ export declare class SekuireSDK {
|
|
|
205
205
|
createDelegator(options?: {
|
|
206
206
|
timeout?: number;
|
|
207
207
|
pollInterval?: number;
|
|
208
|
+
maxRetries?: number;
|
|
209
|
+
retryDelayMs?: number;
|
|
210
|
+
retryBackoffMultiplier?: number;
|
|
208
211
|
}): A2ATaskDelegator;
|
|
209
212
|
/**
|
|
210
213
|
* Get the agent ID.
|