@xopcai/extension-ui-sdk 0.0.150 → 0.0.152
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 +4 -1
- package/src/client.test.ts +36 -0
- package/src/client.ts +16 -0
- package/src/index.ts +1 -0
- package/src/types.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xopcai/extension-ui-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.152",
|
|
4
4
|
"description": "Gateway Console extension UI SDK (iframe postMessage client)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"license": "MIT",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@xopcai/gateway-contract": "0.0.0"
|
|
21
|
+
},
|
|
19
22
|
"devDependencies": {
|
|
20
23
|
"typedoc": "^0.28.19",
|
|
21
24
|
"typedoc-plugin-markdown": "^4.11.0",
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createExtensionClient } from './client.js';
|
|
4
|
+
import type { Transport } from './transport.js';
|
|
5
|
+
|
|
6
|
+
describe('extension client product navigation', () => {
|
|
7
|
+
it('opens first-class product references through the host router', async () => {
|
|
8
|
+
const request = vi.fn(async () => undefined);
|
|
9
|
+
const transport = {
|
|
10
|
+
ready: Promise.resolve(),
|
|
11
|
+
request,
|
|
12
|
+
emit: vi.fn(),
|
|
13
|
+
on: vi.fn(() => () => undefined),
|
|
14
|
+
} as unknown as Transport;
|
|
15
|
+
const client = createExtensionClient({ transport });
|
|
16
|
+
|
|
17
|
+
await client.ui.openProduct({ kind: 'note', id: 'note/1' });
|
|
18
|
+
|
|
19
|
+
expect(request).toHaveBeenCalledWith('ui.navigate', {
|
|
20
|
+
path: '/notes/note%2F1',
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('rejects references without a routable product surface', async () => {
|
|
25
|
+
const transport = {
|
|
26
|
+
ready: Promise.resolve(),
|
|
27
|
+
request: vi.fn(),
|
|
28
|
+
emit: vi.fn(),
|
|
29
|
+
on: vi.fn(() => () => undefined),
|
|
30
|
+
} as unknown as Transport;
|
|
31
|
+
const client = createExtensionClient({ transport });
|
|
32
|
+
|
|
33
|
+
await expect(client.ui.openProduct({ kind: 'file', id: '/tmp/result.md' }))
|
|
34
|
+
.rejects.toThrow('cannot be opened');
|
|
35
|
+
});
|
|
36
|
+
});
|
package/src/client.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
productReferenceRoute,
|
|
3
|
+
type ProductReferenceLocator,
|
|
4
|
+
} from '@xopcai/gateway-contract';
|
|
5
|
+
|
|
1
6
|
import { Transport } from './transport.js';
|
|
2
7
|
import type { ExtensionClient, StreamHandler, ThemeInfo } from './types.js';
|
|
3
8
|
|
|
@@ -88,6 +93,17 @@ export function createExtensionClient(options?: CreateExtensionClientOptions): E
|
|
|
88
93
|
async navigate(path: string) {
|
|
89
94
|
await transport.request('ui.navigate', { path });
|
|
90
95
|
},
|
|
96
|
+
async openProduct(reference: ProductReferenceLocator) {
|
|
97
|
+
const path = productReferenceRoute({
|
|
98
|
+
...reference,
|
|
99
|
+
title: reference.id,
|
|
100
|
+
capabilities: ['open'],
|
|
101
|
+
});
|
|
102
|
+
if (!path) {
|
|
103
|
+
throw new Error(`Product kind cannot be opened by route: ${reference.kind}`);
|
|
104
|
+
}
|
|
105
|
+
await transport.request('ui.navigate', { path });
|
|
106
|
+
},
|
|
91
107
|
onWidgetResult(handler: (data: unknown) => void) {
|
|
92
108
|
return transport.on('widget.data', handler);
|
|
93
109
|
},
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -97,6 +97,7 @@ export interface ExtensionClient {
|
|
|
97
97
|
}): Promise<void>;
|
|
98
98
|
closePanel(): void;
|
|
99
99
|
navigate(path: string): Promise<void>;
|
|
100
|
+
openProduct(reference: ProductReferenceLocator): Promise<void>;
|
|
100
101
|
/** Chat/tool widget iframe: host sends the tool result via `widget.data` after load. */
|
|
101
102
|
onWidgetResult(handler: (data: unknown) => void): () => void;
|
|
102
103
|
};
|
|
@@ -107,3 +108,4 @@ export interface ExtensionClient {
|
|
|
107
108
|
onDispose(handler: () => void): () => void;
|
|
108
109
|
onDidChangeVisibility(handler: (visible: boolean) => void): () => void;
|
|
109
110
|
}
|
|
111
|
+
import type { ProductReferenceLocator } from '@xopcai/gateway-contract';
|