@xopcai/extension-ui-sdk 0.0.452 → 0.0.456
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 +25 -1
- package/package.json +1 -1
- package/src/client.test.ts +19 -0
- package/src/client.ts +21 -0
- package/src/transport.ts +5 -2
- package/src/types.ts +9 -0
package/README.md
CHANGED
|
@@ -92,7 +92,19 @@ Installed Local Apps may declare `ui.capabilities` entries with an exact `id`,
|
|
|
92
92
|
`majorVersion`, and `descriptorDigest` from the authenticated Gateway catalog.
|
|
93
93
|
Currently supported bindings are `xopc.notes.get`, `xopc.notes.list`,
|
|
94
94
|
`xopc.tasks.get`, and `xopc.tasks.list` for reads, plus `xopc.notes.create`,
|
|
95
|
-
`xopc.notes.update`, and `xopc.notes.append` for local writes.
|
|
95
|
+
`xopc.notes.update`, and `xopc.notes.append` for local writes. `xopc.agent.delegate`
|
|
96
|
+
provides bounded text or validated JSON inference (128–4096 output tokens, with a 1024-token default),
|
|
97
|
+
without tools or implicit context. `xopc.automations.list`, `get`, `run`, `get_run` and `cancel`
|
|
98
|
+
provide scoped automation summaries and execution of individually reviewed configurations.
|
|
99
|
+
Run results and cancellation are restricted to runs submitted by the same app. These capabilities
|
|
100
|
+
do not directly create or alter automation definitions. Apps may additionally declare
|
|
101
|
+
`xopc.automations.simulate`, `propose` and `get_proposal` to submit immutable changes for
|
|
102
|
+
`client.automation.reviewProposal(proposalId)` in the host. `history` and `run_events` support
|
|
103
|
+
`client.automation.watchRun(runId, handler)` and reopening an app after a run starts.
|
|
104
|
+
Execution approvals separately bound tools, writes, external delivery, expiry, run count and model
|
|
105
|
+
reservation costs. Shell, browser, MCP and nested delegation are excluded from bounded app runs. AI and automation calls are unavailable
|
|
106
|
+
in previews. See [execution boundaries](../../docs/local-app-automations.md).
|
|
107
|
+
Wildcards, duplicate
|
|
96
108
|
IDs, undeclared operations, and supplied implementation code are rejected.
|
|
97
109
|
|
|
98
110
|
Bindings are included in the release source hash and permission review. Obtain a
|
|
@@ -127,3 +139,15 @@ external writes are not exposed by these bindings.
|
|
|
127
139
|
Release validation and installation reject stale host contract digests; refresh
|
|
128
140
|
the binding and repeat acceptance before publishing. Rollback verifies the stored
|
|
129
141
|
artifact source hash and contract compatibility without reversing business data.
|
|
142
|
+
|
|
143
|
+
### Scoped projects, tasks, connectors and files
|
|
144
|
+
|
|
145
|
+
The `capability` namespace also exposes approved project metadata/progress, backlog task capture/editing, selected-file reads and installed connector actions. Declare each pinned contract in the manifest and request its resource scope in the host permission review. New scopes default to denied. Task capture does not start execution.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
const attachment = await client.files.pickAttachment(); // Separate import grant + user choice, max 512 KiB.
|
|
149
|
+
// For a request returned by xopc.files.propose_export or xopc.connectors.propose_write:
|
|
150
|
+
await client.requests.review(request.id); // Opens host review; does not approve or execute by itself.
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Connector grants bind the exact action, account, connection and contract revision. Writes always require individual host review. Exports are browser downloads after host approval. See [Local Apps P1](../../docs/local-app-p1.md) for limits and execution boundaries.
|
package/package.json
CHANGED
package/src/client.test.ts
CHANGED
|
@@ -4,6 +4,25 @@ import { createExtensionClient } from './client.js';
|
|
|
4
4
|
import type { Transport } from './transport.js';
|
|
5
5
|
|
|
6
6
|
describe('extension client product navigation', () => {
|
|
7
|
+
it('shares run subscriptions and stops only after the final listener is removed', async () => {
|
|
8
|
+
const request = vi.fn(async () => undefined), off = vi.fn();
|
|
9
|
+
const on = vi.fn(() => off);
|
|
10
|
+
const client = createExtensionClient({ transport: { request, on } as unknown as Transport });
|
|
11
|
+
const [first, second] = await Promise.all([client.automation.watchRun('run', vi.fn()), client.automation.watchRun('run', vi.fn())]);
|
|
12
|
+
expect(request.mock.calls).toEqual([['automation.watchRun', { runId: 'run' }]]);
|
|
13
|
+
first(); first(); expect(request).toHaveBeenCalledTimes(1);
|
|
14
|
+
second(); expect(request.mock.calls[1]).toEqual(['automation.unwatchRun', { runId: 'run' }]);
|
|
15
|
+
expect(off).toHaveBeenCalledTimes(2);
|
|
16
|
+
await client.automation.reviewProposal('proposal');
|
|
17
|
+
expect(request).toHaveBeenLastCalledWith('automation.reviewProposal', { proposalId: 'proposal' });
|
|
18
|
+
});
|
|
19
|
+
it('opens host attachment and resource review without supplying authority', async () => {
|
|
20
|
+
const request = vi.fn(async () => undefined);
|
|
21
|
+
const client = createExtensionClient({ transport: { request } as unknown as Transport });
|
|
22
|
+
await client.files.pickAttachment();
|
|
23
|
+
await client.requests.review('request');
|
|
24
|
+
expect(request.mock.calls).toEqual([['files.pickAttachment'], ['apps.reviewRequest', { requestId: 'request' }]]);
|
|
25
|
+
});
|
|
7
26
|
it('requests permission review without sending grants or identity', async () => {
|
|
8
27
|
const request = vi.fn(async () => undefined);
|
|
9
28
|
const client = createExtensionClient({ transport: { request } as unknown as Transport });
|
package/src/client.ts
CHANGED
|
@@ -12,8 +12,29 @@ export type CreateExtensionClientOptions = {
|
|
|
12
12
|
|
|
13
13
|
export function createExtensionClient(options?: CreateExtensionClientOptions): ExtensionClient {
|
|
14
14
|
const transport = options?.transport ?? new Transport();
|
|
15
|
+
const runWatchers = new Map<string, { count: number; ready: Promise<unknown> }>();
|
|
15
16
|
|
|
16
17
|
const client: ExtensionClient = {
|
|
18
|
+
files: { pickAttachment: () => transport.request('files.pickAttachment') },
|
|
19
|
+
requests: { async review(requestId) { await transport.request('apps.reviewRequest', { requestId }); } },
|
|
20
|
+
automation: {
|
|
21
|
+
async watchRun(runId, handler) {
|
|
22
|
+
const off = transport.on(`automation.run.${runId}`, handler);
|
|
23
|
+
let entry = runWatchers.get(runId);
|
|
24
|
+
if (!entry) { entry = { count: 0, ready: transport.request('automation.watchRun', { runId }) }; runWatchers.set(runId, entry); }
|
|
25
|
+
entry.count++;
|
|
26
|
+
try { await entry.ready; }
|
|
27
|
+
catch (error) { off(); if (--entry.count === 0 && runWatchers.get(runId) === entry) runWatchers.delete(runId); throw error; }
|
|
28
|
+
let stopped = false;
|
|
29
|
+
return () => {
|
|
30
|
+
if (stopped) return; stopped = true; off();
|
|
31
|
+
if (--entry.count === 0 && runWatchers.get(runId) === entry) {
|
|
32
|
+
runWatchers.delete(runId); void transport.request('automation.unwatchRun', { runId }).catch(() => {});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
async reviewProposal(proposalId) { await transport.request('automation.reviewProposal', { proposalId }); },
|
|
37
|
+
},
|
|
17
38
|
capability: {
|
|
18
39
|
describe: id => transport.request('capability.describe', { id }),
|
|
19
40
|
call: (id, call) => transport.request('capability.call', { id, call }),
|
package/src/transport.ts
CHANGED
|
@@ -25,11 +25,13 @@ export class Transport {
|
|
|
25
25
|
private disposed = false;
|
|
26
26
|
private readonly timeout: number;
|
|
27
27
|
private readonly delegationTimeout: number;
|
|
28
|
+
private readonly interactionTimeout: number;
|
|
28
29
|
private requestCounter = 0;
|
|
29
30
|
|
|
30
31
|
constructor(options?: TransportOptions) {
|
|
31
32
|
this.timeout = options?.timeout ?? 10_000;
|
|
32
33
|
this.delegationTimeout = options?.timeout ?? 35_000;
|
|
34
|
+
this.interactionTimeout = options?.timeout ?? 125_000;
|
|
33
35
|
this.initPromise = new Promise<HostInit>((resolve) => {
|
|
34
36
|
this.initResolve = resolve;
|
|
35
37
|
});
|
|
@@ -64,8 +66,9 @@ export class Transport {
|
|
|
64
66
|
throw new Error('Transport disposed');
|
|
65
67
|
}
|
|
66
68
|
const requestId = this.nextRequestId();
|
|
67
|
-
const timeout = method === '
|
|
68
|
-
|
|
69
|
+
const timeout = method === 'files.pickAttachment' ? this.interactionTimeout
|
|
70
|
+
: method === 'capability.call' && params && typeof params === 'object' && 'id' in params
|
|
71
|
+
&& typeof params.id === 'string' && (params.id === 'xopc.agent.delegate' || params.id.startsWith('xopc.connectors.')) ? this.delegationTimeout : this.timeout;
|
|
69
72
|
const message: ExtensionRequest = {
|
|
70
73
|
source: 'xopc-extension',
|
|
71
74
|
extensionId: this.extensionId,
|
package/src/types.ts
CHANGED
|
@@ -64,6 +64,15 @@ export type ExtensionToHostMessage = ExtensionRequest | ExtensionEventMessage;
|
|
|
64
64
|
export type StreamHandler = (payload: unknown) => void;
|
|
65
65
|
|
|
66
66
|
export interface ExtensionClient {
|
|
67
|
+
files: {
|
|
68
|
+
pickAttachment(): Promise<{ name: string; mimeType: string; size: number; encoding: 'base64'; content: string }>;
|
|
69
|
+
};
|
|
70
|
+
requests: { review(requestId: string): Promise<void> };
|
|
71
|
+
automation: {
|
|
72
|
+
/** Reconnectable host subscription; resumes with a current snapshot and bounded event history. */
|
|
73
|
+
watchRun(runId: string, handler: StreamHandler): Promise<() => void>;
|
|
74
|
+
reviewProposal(proposalId: string): Promise<void>;
|
|
75
|
+
};
|
|
67
76
|
capability: {
|
|
68
77
|
describe(id: string): Promise<CapabilityDescriptor>;
|
|
69
78
|
call(id: string, call: CapabilityCall): Promise<{ status: 'succeeded'; releaseId: string; data: unknown }>;
|