@kaoruisaac/pedelec 0.1.5 → 0.1.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 +9 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +55 -0
- package/dist/index.type-test.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,6 +150,15 @@ const status = await pedelec.getApprovalStatus();
|
|
|
150
150
|
console.log(status.installed, status.approved, status.origin);
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
+
For a complete Extension, approval, and Desktop readiness probe, use `checkAvailability()`. It never creates/resumes a session or opens approval. When approved it validates Desktop by calling `getSettings()`, which may invoke the existing Native Host auto-launch fallback.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
const availability = await pedelec.checkAvailability();
|
|
157
|
+
if (availability.available) startUi();
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
An unavailable extension may be disconnected rather than absent. `desktop.launchAttempted` means the settings probe was sent, not that Desktop was confirmed to have launched. Invalid settings responses also count as Desktop unavailable in this probe.
|
|
161
|
+
|
|
153
162
|
### Specifying Provider and Model
|
|
154
163
|
|
|
155
164
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,21 @@ export type ApprovalStatus = {
|
|
|
110
110
|
approved: boolean;
|
|
111
111
|
origin: string | null;
|
|
112
112
|
};
|
|
113
|
+
export type PedelecAvailability = {
|
|
114
|
+
available: boolean;
|
|
115
|
+
extension: {
|
|
116
|
+
available: boolean;
|
|
117
|
+
};
|
|
118
|
+
approval: {
|
|
119
|
+
approved: boolean;
|
|
120
|
+
origin: string | null;
|
|
121
|
+
};
|
|
122
|
+
desktop: {
|
|
123
|
+
available: boolean;
|
|
124
|
+
launchAttempted: boolean;
|
|
125
|
+
};
|
|
126
|
+
error?: PedelecError;
|
|
127
|
+
};
|
|
113
128
|
export type PedelecError = {
|
|
114
129
|
code: string;
|
|
115
130
|
message: string;
|
|
@@ -220,6 +235,7 @@ export declare class Pedelec {
|
|
|
220
235
|
request<T>(type: string, payload?: Record<string, unknown>): Promise<T>;
|
|
221
236
|
unregisterSession(sessionId: string): void;
|
|
222
237
|
private resolveCreateSessionInput;
|
|
238
|
+
checkAvailability(): Promise<PedelecAvailability>;
|
|
223
239
|
private resolveDefaultCreateSessionInput;
|
|
224
240
|
private resolveProviderOnlyCreateSessionInput;
|
|
225
241
|
private assertDefaultProviderAvailable;
|
package/dist/index.js
CHANGED
|
@@ -264,6 +264,58 @@ export class Pedelec {
|
|
|
264
264
|
autoEndOnDisconnect,
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
|
+
async checkAvailability() {
|
|
268
|
+
const origin = getCurrentOrigin(this.pageWindow);
|
|
269
|
+
let approval;
|
|
270
|
+
try {
|
|
271
|
+
approval = await this.getApprovalStatus();
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
const error = normalizeError(err, "SDK_TRANSPORT_ERROR", "Could not read Pedelec approval status.");
|
|
275
|
+
return {
|
|
276
|
+
available: false,
|
|
277
|
+
extension: { available: !isExtensionUnavailableError(error) },
|
|
278
|
+
approval: { approved: false, origin },
|
|
279
|
+
desktop: { available: false, launchAttempted: false },
|
|
280
|
+
error,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
if (!approval.installed) {
|
|
284
|
+
return {
|
|
285
|
+
available: false,
|
|
286
|
+
extension: { available: false },
|
|
287
|
+
approval: { approved: false, origin: approval.origin ?? origin },
|
|
288
|
+
desktop: { available: false, launchAttempted: false },
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
if (!approval.approved) {
|
|
292
|
+
return {
|
|
293
|
+
available: false,
|
|
294
|
+
extension: { available: true },
|
|
295
|
+
approval: { approved: false, origin: approval.origin },
|
|
296
|
+
desktop: { available: false, launchAttempted: false },
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
await this.getSettings();
|
|
301
|
+
return {
|
|
302
|
+
available: true,
|
|
303
|
+
extension: { available: true },
|
|
304
|
+
approval: { approved: true, origin: approval.origin },
|
|
305
|
+
desktop: { available: true, launchAttempted: true },
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
catch (err) {
|
|
309
|
+
const error = normalizeError(err, "SDK_TRANSPORT_ERROR", "Could not reach Pedelec Desktop.");
|
|
310
|
+
return {
|
|
311
|
+
available: false,
|
|
312
|
+
extension: { available: true },
|
|
313
|
+
approval: { approved: true, origin: approval.origin },
|
|
314
|
+
desktop: { available: false, launchAttempted: true },
|
|
315
|
+
error,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
267
319
|
async resolveDefaultCreateSessionInput(normalizedSkills, autoEndOnDisconnect) {
|
|
268
320
|
const settings = await this.getSettings();
|
|
269
321
|
if (!settings.defaultProvider) {
|
|
@@ -908,6 +960,9 @@ function getCurrentOrigin(pageWindow) {
|
|
|
908
960
|
const origin = pageWindow?.location?.origin;
|
|
909
961
|
return typeof origin === "string" && origin ? origin : null;
|
|
910
962
|
}
|
|
963
|
+
function isExtensionUnavailableError(error) {
|
|
964
|
+
return error.code === "EXTENSION_UNAVAILABLE" || error.code === "EXTENSION_DISCONNECTED";
|
|
965
|
+
}
|
|
911
966
|
function normalizeError(err, fallbackCode, fallbackMessage) {
|
|
912
967
|
if (!err)
|
|
913
968
|
return makeError(fallbackCode, fallbackMessage);
|
package/dist/index.type-test.js
CHANGED
|
@@ -96,10 +96,18 @@ async function listAssetsHasPublicTypes() {
|
|
|
96
96
|
const path = assets[0].path;
|
|
97
97
|
path;
|
|
98
98
|
}
|
|
99
|
+
async function availabilityHasPublicType() {
|
|
100
|
+
const pedelec = new Pedelec();
|
|
101
|
+
const availability = await pedelec.checkAvailability();
|
|
102
|
+
const promise = pedelec.checkAvailability();
|
|
103
|
+
void availability;
|
|
104
|
+
void promise;
|
|
105
|
+
}
|
|
99
106
|
void typedOnToolNameFromCreateSession;
|
|
100
107
|
void resumedSessionFallsBackToString;
|
|
101
108
|
void noSkillsFallsBackToString;
|
|
102
109
|
void listAssetsHasPublicTypes;
|
|
110
|
+
void availabilityHasPublicType;
|
|
103
111
|
const baseContext = {
|
|
104
112
|
sessionId: "thread_1",
|
|
105
113
|
provider: "codex",
|