@xopcai/extension-ui-sdk 0.0.450 → 0.0.452
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/package.json +1 -1
- package/src/client.test.ts +6 -0
- package/src/client.ts +1 -0
- package/src/transport.ts +8 -2
- package/src/types.ts +2 -0
package/package.json
CHANGED
package/src/client.test.ts
CHANGED
|
@@ -4,6 +4,12 @@ import { createExtensionClient } from './client.js';
|
|
|
4
4
|
import type { Transport } from './transport.js';
|
|
5
5
|
|
|
6
6
|
describe('extension client product navigation', () => {
|
|
7
|
+
it('requests permission review without sending grants or identity', async () => {
|
|
8
|
+
const request = vi.fn(async () => undefined);
|
|
9
|
+
const client = createExtensionClient({ transport: { request } as unknown as Transport });
|
|
10
|
+
await client.ui.reviewPermissions();
|
|
11
|
+
expect(request).toHaveBeenCalledWith('ui.reviewPermissions');
|
|
12
|
+
});
|
|
7
13
|
it('forwards the pinned capability contract without attaching caller authority', async () => {
|
|
8
14
|
const request = vi.fn(async () => ({ status: 'succeeded', releaseId: 'release', data: {} }));
|
|
9
15
|
const client = createExtensionClient({ transport: { request } as unknown as Transport });
|
package/src/client.ts
CHANGED
package/src/transport.ts
CHANGED
|
@@ -24,14 +24,18 @@ export class Transport {
|
|
|
24
24
|
private initPromise: Promise<HostInit>;
|
|
25
25
|
private disposed = false;
|
|
26
26
|
private readonly timeout: number;
|
|
27
|
+
private readonly delegationTimeout: number;
|
|
27
28
|
private requestCounter = 0;
|
|
28
29
|
|
|
29
30
|
constructor(options?: TransportOptions) {
|
|
30
31
|
this.timeout = options?.timeout ?? 10_000;
|
|
32
|
+
this.delegationTimeout = options?.timeout ?? 35_000;
|
|
31
33
|
this.initPromise = new Promise<HostInit>((resolve) => {
|
|
32
34
|
this.initResolve = resolve;
|
|
33
35
|
});
|
|
34
36
|
window.addEventListener('message', this.handleMessage);
|
|
37
|
+
// A module can await whenReady before window.load. Request init instead of waiting for load.
|
|
38
|
+
window.parent.postMessage({ source: 'xopc-extension', extensionId: '', type: 'event', event: 'ui.connect' }, '*');
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
get ready(): Promise<HostInit> {
|
|
@@ -60,6 +64,8 @@ export class Transport {
|
|
|
60
64
|
throw new Error('Transport disposed');
|
|
61
65
|
}
|
|
62
66
|
const requestId = this.nextRequestId();
|
|
67
|
+
const timeout = method === 'capability.call' && params && typeof params === 'object'
|
|
68
|
+
&& 'id' in params && params.id === 'xopc.agent.delegate' ? this.delegationTimeout : this.timeout;
|
|
63
69
|
const message: ExtensionRequest = {
|
|
64
70
|
source: 'xopc-extension',
|
|
65
71
|
extensionId: this.extensionId,
|
|
@@ -71,8 +77,8 @@ export class Transport {
|
|
|
71
77
|
return new Promise<T>((resolve, reject) => {
|
|
72
78
|
const timer = setTimeout(() => {
|
|
73
79
|
this.pending.delete(requestId);
|
|
74
|
-
reject(new Error(`Request '${method}' timed out after ${
|
|
75
|
-
},
|
|
80
|
+
reject(new Error(`Request '${method}' timed out after ${timeout}ms`));
|
|
81
|
+
}, timeout);
|
|
76
82
|
this.pending.set(requestId, {
|
|
77
83
|
resolve: resolve as (v: unknown) => void,
|
|
78
84
|
reject,
|
package/src/types.ts
CHANGED
|
@@ -95,6 +95,8 @@ export interface ExtensionClient {
|
|
|
95
95
|
keys(): Promise<string[]>;
|
|
96
96
|
};
|
|
97
97
|
ui: {
|
|
98
|
+
/** Open the host's permission review. This never grants access automatically. */
|
|
99
|
+
reviewPermissions(): Promise<void>;
|
|
98
100
|
resize(height: number): void;
|
|
99
101
|
showNotification(options: {
|
|
100
102
|
type?: 'success' | 'error' | 'info';
|