@pptb/types 1.2.7-beta.5 → 1.2.7-beta.7
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 +53 -0
- package/package.json +2 -2
- package/toolboxAPI.d.ts +23 -0
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ TypeScript type definitions for Power Platform ToolBox APIs, plus a built-in CLI
|
|
|
18
18
|
- [Connections](#connections)
|
|
19
19
|
- [Utilities](#utilities)
|
|
20
20
|
- [Terminal Operations](#terminal-operations)
|
|
21
|
+
- [Native Workers](#native-workers)
|
|
21
22
|
- [Events](#events)
|
|
22
23
|
- [Inter-Tool Invocation](#inter-tool-invocation)
|
|
23
24
|
- [Caller: launching another tool with prefill data](#caller-launching-another-tool-with-prefill-data)
|
|
@@ -42,6 +43,7 @@ TypeScript type definitions for Power Platform ToolBox APIs, plus a built-in CLI
|
|
|
42
43
|
- [Connections](#connections-1)
|
|
43
44
|
- [Utils](#utils)
|
|
44
45
|
- [Terminal](#terminal)
|
|
46
|
+
- [Workers](#workers)
|
|
45
47
|
- [Events](#events-1)
|
|
46
48
|
- [Invocation](#invocation)
|
|
47
49
|
- [Dataverse API (`window.dataverseAPI`)](#dataverse-api-windowdataverseapi)
|
|
@@ -351,6 +353,42 @@ const terminals = await toolboxAPI.terminal.list();
|
|
|
351
353
|
await toolboxAPI.terminal.close(terminal.id);
|
|
352
354
|
```
|
|
353
355
|
|
|
356
|
+
### Native Workers
|
|
357
|
+
|
|
358
|
+
If a tool declares a .NET worker in `pptb.config.json`, connect to it through
|
|
359
|
+
`toolboxAPI.workers.connect()`. PPTB owns process startup, consent, JSON-RPC
|
|
360
|
+
framing, readiness, request correlation, cancellation and cleanup. Tool code only
|
|
361
|
+
registers any worker-to-tool callbacks it needs, then calls worker methods by
|
|
362
|
+
name:
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
const worker = await toolboxAPI.workers.connect("sample", {
|
|
366
|
+
requests: {
|
|
367
|
+
"dataverse/fetchXml": async (params, context) => {
|
|
368
|
+
if (context.isCancellationRequested) throw new Error("Request cancelled");
|
|
369
|
+
const fetchXml = String(params);
|
|
370
|
+
const result = await dataverseAPI.fetchXmlQuery(fetchXml);
|
|
371
|
+
if (context.isCancellationRequested) throw new Error("Request cancelled");
|
|
372
|
+
return { value: result.value };
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
notifications: {
|
|
376
|
+
progress: (message) => setStatus(String(message)),
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
await worker.ready;
|
|
381
|
+
const result = await worker.request("query", fetchXml);
|
|
382
|
+
await worker.stop();
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
Use `worker.cancel()` to cancel outstanding requests. `worker.stop()` waits for
|
|
386
|
+
PPTB's verified process cleanup; if it rejects, keep the session and let the user
|
|
387
|
+
retry stop rather than claiming the worker was stopped. Workers are trusted
|
|
388
|
+
native code running as the current OS user, not sandboxed. Do not send tokens or
|
|
389
|
+
credential material to them; implement narrowly scoped reverse requests through
|
|
390
|
+
PPTB APIs instead.
|
|
391
|
+
|
|
354
392
|
### Events
|
|
355
393
|
|
|
356
394
|
```typescript
|
|
@@ -769,6 +807,21 @@ Core platform features organized into namespaces:
|
|
|
769
807
|
- **setVisibility(terminalId: string, visible: boolean)**: Promise<void>
|
|
770
808
|
- Shows or hides the terminal UI for the specified terminal id
|
|
771
809
|
|
|
810
|
+
#### Workers
|
|
811
|
+
|
|
812
|
+
- **connect(workerId: string, options?: WorkerSessionOptions)**: Promise<WorkerSession>
|
|
813
|
+
- Starts the declared worker and returns a JSON-RPC session. `ready` resolves after the protocol initialize handshake.
|
|
814
|
+
- `options.requests` registers worker-initiated requests handled by the tool; `options.notifications` handles worker notifications; `options.onExit` observes process termination.
|
|
815
|
+
- **WorkerSession.request<Result>(method: string, params?: unknown)**: Promise<Result>
|
|
816
|
+
- Sends a named request to the worker and resolves with its result.
|
|
817
|
+
- **WorkerSession.notify(method: string, params?: unknown)**: Promise<void>
|
|
818
|
+
- Sends a notification to the worker.
|
|
819
|
+
- **WorkerSession.cancel()**: void
|
|
820
|
+
- Requests cancellation of outstanding requests. Worker and callback cancellation is cooperative.
|
|
821
|
+
- **WorkerSession.stop() / dispose()**: Promise<void>
|
|
822
|
+
- Stops the worker and waits for verified cleanup. A failed stop must remain visible and retryable.
|
|
823
|
+
- **WorkerSessionOptions.requests** handlers receive `(params, context)`, where `context.isCancellationRequested` and `context.onCancellationRequested()` expose cancellation without exposing transport details.
|
|
824
|
+
|
|
772
825
|
#### Events
|
|
773
826
|
|
|
774
827
|
- **getHistory(limit?: number)**: Promise<ToolBoxEventPayload[]>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pptb/types",
|
|
3
|
-
"version": "1.2.7-beta.
|
|
3
|
+
"version": "1.2.7-beta.7",
|
|
4
4
|
"description": "Type definitions for Power Platform ToolBox APIs and validity checks for tool packages",
|
|
5
5
|
"main": "index.d.ts",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"pptb-validate": "./bin/pptb-validate.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@pptb/validate": "1.0.
|
|
26
|
+
"@pptb/validate": "1.0.5"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"index.d.ts",
|
package/toolboxAPI.d.ts
CHANGED
|
@@ -188,7 +188,28 @@ declare namespace ToolBoxAPI {
|
|
|
188
188
|
ready: Promise<void>;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
export interface WorkerRequestContext {
|
|
192
|
+
readonly isCancellationRequested: boolean;
|
|
193
|
+
onCancellationRequested(callback: () => void): { dispose(): void };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface WorkerSessionOptions {
|
|
197
|
+
requests?: Record<string, (params: unknown, context: WorkerRequestContext) => unknown | Promise<unknown>>;
|
|
198
|
+
notifications?: Record<string, (params: unknown) => void>;
|
|
199
|
+
onExit?: (snapshot: WorkerSnapshot) => void;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface WorkerSession {
|
|
203
|
+
readonly ready: Promise<void>;
|
|
204
|
+
request<Result = unknown>(method: string, params?: unknown): Promise<Result>;
|
|
205
|
+
notify(method: string, params?: unknown): Promise<void>;
|
|
206
|
+
cancel(): void;
|
|
207
|
+
stop(): Promise<void>;
|
|
208
|
+
dispose(): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
|
|
191
211
|
export interface WorkersAPI {
|
|
212
|
+
connect(workerId: string, options?: WorkerSessionOptions): Promise<WorkerSession>;
|
|
192
213
|
start(workerId: string): Promise<WorkerStart>;
|
|
193
214
|
send(handle: WorkerHandle, message: WorkerRpcMessage): Promise<void>;
|
|
194
215
|
onMessage(handle: WorkerHandle, callback: (message: WorkerRpcMessage) => void): () => void;
|
|
@@ -642,11 +663,13 @@ declare global {
|
|
|
642
663
|
/**
|
|
643
664
|
* The organized ToolBox API for tools
|
|
644
665
|
*/
|
|
666
|
+
// @ts-expect-error App-renderer and tool windows expose different global API contracts.
|
|
645
667
|
toolboxAPI: ToolBoxAPI.API;
|
|
646
668
|
|
|
647
669
|
/**
|
|
648
670
|
* Tool context available at startup
|
|
649
671
|
*/
|
|
672
|
+
// @ts-expect-error App-renderer and tool windows expose distinct context contracts.
|
|
650
673
|
TOOLBOX_CONTEXT?: ToolBoxAPI.ToolContext;
|
|
651
674
|
}
|
|
652
675
|
}
|