@immediately-run/sdk 0.85.0 → 0.89.0
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/dist/catalog.cjs +2 -7
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.js +2 -7
- package/dist/catalog.js.map +1 -1
- package/dist/llm.cjs +11 -2
- package/dist/llm.cjs.map +1 -1
- package/dist/llm.d.cts +5 -0
- package/dist/llm.d.ts +5 -0
- package/dist/llm.js +11 -2
- package/dist/llm.js.map +1 -1
- package/dist/protocolRefusal.cjs +1 -0
- package/dist/protocolRefusal.cjs.map +1 -1
- package/dist/protocolRefusal.d.cts +17 -21
- package/dist/protocolRefusal.d.ts +17 -21
- package/dist/protocolRefusal.js +1 -0
- package/dist/protocolRefusal.js.map +1 -1
- package/dist/providerIcons/NOTICE.md +37 -0
- package/dist/providerIcons/ProviderIcon.cjs +61 -0
- package/dist/providerIcons/ProviderIcon.cjs.map +1 -0
- package/dist/providerIcons/ProviderIcon.d.cts +13 -0
- package/dist/providerIcons/ProviderIcon.d.ts +13 -0
- package/dist/providerIcons/ProviderIcon.js +38 -0
- package/dist/providerIcons/ProviderIcon.js.map +1 -0
- package/dist/providerIcons/sprite.generated.cjs +138 -0
- package/dist/providerIcons/sprite.generated.cjs.map +1 -0
- package/dist/providerIcons/sprite.generated.d.cts +8 -0
- package/dist/providerIcons/sprite.generated.d.ts +8 -0
- package/dist/providerIcons/sprite.generated.js +114 -0
- package/dist/providerIcons/sprite.generated.js.map +1 -0
- package/dist/providerIcons.cjs +32 -0
- package/dist/providerIcons.cjs.map +1 -0
- package/dist/providerIcons.d.cts +3 -0
- package/dist/providerIcons.d.ts +3 -0
- package/dist/providerIcons.js +8 -0
- package/dist/providerIcons.js.map +1 -0
- package/dist/recents.cjs +2 -5
- package/dist/recents.cjs.map +1 -1
- package/dist/recents.js +2 -5
- package/dist/recents.js.map +1 -1
- package/dist/routing.cjs +2 -1
- package/dist/routing.cjs.map +1 -1
- package/dist/routing.d.cts +1 -0
- package/dist/routing.d.ts +1 -0
- package/dist/routing.js +2 -1
- package/dist/routing.js.map +1 -1
- package/dist/tasks.cjs +2 -5
- package/dist/tasks.cjs.map +1 -1
- package/dist/tasks.js +2 -5
- package/dist/tasks.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** An error carrying a stable, host-supplied `code` the app can branch on. */
|
|
2
2
|
interface CodedRefusalError<C extends string = string> extends Error {
|
|
3
3
|
code: C;
|
|
4
|
+
/** A provider rate-limit's wait in seconds, when the refusal carried one (R3-954). */
|
|
5
|
+
retryAfter?: number;
|
|
4
6
|
}
|
|
5
7
|
/**
|
|
6
8
|
* Throw a typed, coded error unless the host's reply envelope says the call succeeded.
|
|
@@ -9,18 +11,19 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
9
11
|
* the code when it refused without one — a refusal is never reported as a success just
|
|
10
12
|
* because it arrived under-specified.
|
|
11
13
|
*
|
|
12
|
-
* `code` and `message` must be STRINGS to be used.
|
|
13
|
-
* **
|
|
14
|
-
* helper in R3-708
|
|
15
|
-
*
|
|
14
|
+
* `code` and `message` must be STRINGS to be used. Twenty-three sites call this;
|
|
15
|
+
* **eighteen** had an inline copy it replaced (`spacesMode.ts` was written against the
|
|
16
|
+
* helper in R3-708, `openBundle.ts` against it in R3-808, and `catalog.ts` folded in
|
|
17
|
+
* R3-1089 once the helper learned `retryAfter` — the one site R3-954's copy had kept
|
|
18
|
+
* out). They tested for PRESENCE, in **three** shapes:
|
|
16
19
|
*
|
|
17
20
|
* - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —
|
|
18
21
|
* `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;
|
|
19
|
-
* - **seven** used the `in` operator
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* - **
|
|
23
|
-
* `ipc.
|
|
22
|
+
* - **seven** used the `in` operator: `((res && 'code' in res ? res.code : undefined) as
|
|
23
|
+
* Code) ?? 'unknown'` — `openExternal` and `openRepository` (folded in R3-708) and
|
|
24
|
+
* `feed`, `netFetch` and `theme` (×3) (folded in R3-817, #192);
|
|
25
|
+
* - **four** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —
|
|
26
|
+
* `ipc` (×2), `recents`, `tasks` (folded in R3-816).
|
|
24
27
|
*
|
|
25
28
|
* Every one of them let a host sending `code: 42` surface `err.code === 42` on a field
|
|
26
29
|
* declared `string`, and turned `message: 42` into the string `"42"`. Both now fall back,
|
|
@@ -47,11 +50,11 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
47
50
|
* `openExternal` and `openRepository` did.
|
|
48
51
|
*
|
|
49
52
|
* The mechanism is worth more than the correction, because it is repeatable. `'code' in
|
|
50
|
-
* res` is
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
53
|
+
* res` is GONE from `main` — R3-817 (merged as #192, 0.74.3) folded the five sites that
|
|
54
|
+
* carried it (`feed`, `netFetch`, `theme` ×3), beside R3-708's two (`openExternal`,
|
|
55
|
+
* `openRepository`). A grep of `main` today finds the form only in this file's comments
|
|
56
|
+
* and in test files. The tree that shows the form at the sites is the one before the
|
|
57
|
+
* folds, `d4b07cc1^`. Read that before rewriting this paragraph again.
|
|
55
58
|
*
|
|
56
59
|
* It is an ASSERTION function, not a `void` one, because the inline form it replaced
|
|
57
60
|
* narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read
|
|
@@ -59,13 +62,6 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
59
62
|
* the throw can ignore the narrowing; one that reads the payload gets it for free. (TS
|
|
60
63
|
* requires the call target to be an explicitly-typed declared name — this is why it is a
|
|
61
64
|
* `function` declaration and not an arrow const.)
|
|
62
|
-
*
|
|
63
|
-
* R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,
|
|
64
|
-
* `theme.ts` ×3) folded onto this — removing a latent defect with them: their
|
|
65
|
-
* `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a
|
|
66
|
-
* bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`
|
|
67
|
-
* branch an app wrote. This function reads `typeof r?.code === 'string'` and
|
|
68
|
-
* cannot throw on any input; the TypeError path no longer exists.
|
|
69
65
|
*/
|
|
70
66
|
declare function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is {
|
|
71
67
|
ok: true;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** An error carrying a stable, host-supplied `code` the app can branch on. */
|
|
2
2
|
interface CodedRefusalError<C extends string = string> extends Error {
|
|
3
3
|
code: C;
|
|
4
|
+
/** A provider rate-limit's wait in seconds, when the refusal carried one (R3-954). */
|
|
5
|
+
retryAfter?: number;
|
|
4
6
|
}
|
|
5
7
|
/**
|
|
6
8
|
* Throw a typed, coded error unless the host's reply envelope says the call succeeded.
|
|
@@ -9,18 +11,19 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
9
11
|
* the code when it refused without one — a refusal is never reported as a success just
|
|
10
12
|
* because it arrived under-specified.
|
|
11
13
|
*
|
|
12
|
-
* `code` and `message` must be STRINGS to be used.
|
|
13
|
-
* **
|
|
14
|
-
* helper in R3-708
|
|
15
|
-
*
|
|
14
|
+
* `code` and `message` must be STRINGS to be used. Twenty-three sites call this;
|
|
15
|
+
* **eighteen** had an inline copy it replaced (`spacesMode.ts` was written against the
|
|
16
|
+
* helper in R3-708, `openBundle.ts` against it in R3-808, and `catalog.ts` folded in
|
|
17
|
+
* R3-1089 once the helper learned `retryAfter` — the one site R3-954's copy had kept
|
|
18
|
+
* out). They tested for PRESENCE, in **three** shapes:
|
|
16
19
|
*
|
|
17
20
|
* - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —
|
|
18
21
|
* `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;
|
|
19
|
-
* - **seven** used the `in` operator
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* - **
|
|
23
|
-
* `ipc.
|
|
22
|
+
* - **seven** used the `in` operator: `((res && 'code' in res ? res.code : undefined) as
|
|
23
|
+
* Code) ?? 'unknown'` — `openExternal` and `openRepository` (folded in R3-708) and
|
|
24
|
+
* `feed`, `netFetch` and `theme` (×3) (folded in R3-817, #192);
|
|
25
|
+
* - **four** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —
|
|
26
|
+
* `ipc` (×2), `recents`, `tasks` (folded in R3-816).
|
|
24
27
|
*
|
|
25
28
|
* Every one of them let a host sending `code: 42` surface `err.code === 42` on a field
|
|
26
29
|
* declared `string`, and turned `message: 42` into the string `"42"`. Both now fall back,
|
|
@@ -47,11 +50,11 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
47
50
|
* `openExternal` and `openRepository` did.
|
|
48
51
|
*
|
|
49
52
|
* The mechanism is worth more than the correction, because it is repeatable. `'code' in
|
|
50
|
-
* res` is
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
53
|
+
* res` is GONE from `main` — R3-817 (merged as #192, 0.74.3) folded the five sites that
|
|
54
|
+
* carried it (`feed`, `netFetch`, `theme` ×3), beside R3-708's two (`openExternal`,
|
|
55
|
+
* `openRepository`). A grep of `main` today finds the form only in this file's comments
|
|
56
|
+
* and in test files. The tree that shows the form at the sites is the one before the
|
|
57
|
+
* folds, `d4b07cc1^`. Read that before rewriting this paragraph again.
|
|
55
58
|
*
|
|
56
59
|
* It is an ASSERTION function, not a `void` one, because the inline form it replaced
|
|
57
60
|
* narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read
|
|
@@ -59,13 +62,6 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
59
62
|
* the throw can ignore the narrowing; one that reads the payload gets it for free. (TS
|
|
60
63
|
* requires the call target to be an explicitly-typed declared name — this is why it is a
|
|
61
64
|
* `function` declaration and not an arrow const.)
|
|
62
|
-
*
|
|
63
|
-
* R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,
|
|
64
|
-
* `theme.ts` ×3) folded onto this — removing a latent defect with them: their
|
|
65
|
-
* `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a
|
|
66
|
-
* bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`
|
|
67
|
-
* branch an app wrote. This function reads `typeof r?.code === 'string'` and
|
|
68
|
-
* cannot throw on any input; the TypeError path no longer exists.
|
|
69
65
|
*/
|
|
70
66
|
declare function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is {
|
|
71
67
|
ok: true;
|
package/dist/protocolRefusal.js
CHANGED
|
@@ -4,6 +4,7 @@ function throwOnRefusal(res, fallbackMessage) {
|
|
|
4
4
|
if (r && r.ok === true) return;
|
|
5
5
|
const err = new Error(typeof r?.message === "string" ? r.message : fallbackMessage);
|
|
6
6
|
err.code = typeof r?.code === "string" ? r.code : "unknown";
|
|
7
|
+
if (Number.isFinite(r?.retryAfter)) err.retryAfter = r.retryAfter;
|
|
7
8
|
throw err;
|
|
8
9
|
}
|
|
9
10
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — miscounted four times. COUNT THE GREP, and say which unit.\n// ---------------------------------------------------------------------------\n//\n// R3-708's review said three copies, then five, then \"ten across eight files\". This file\n// then said ten while the list beneath it summed to twelve, and a fourth reviewer caught\n// that. The count is:\n//\n// **eighteen CALL SITES across thirteen FILES** — `grep -n 'throwOnRefusal(' src/*.ts`,\n// minus the declaration here and minus `*.test.*`:\n//\n// dnd.ts · editor.ts · feed.ts · ipc.ts (×2) · mounts.ts (×3) · netFetch.ts ·\n// openBundle.ts · openExternal.ts · openRepository.ts · secrets.ts · spacesMode.ts · theme.ts (×3) ·\n// vcs.ts\n//\n// Every miscount came from the same two mistakes: reading files instead of counting the\n// grep, and never saying which unit was being counted. `mounts.ts` has three separate\n// request helpers, each with its own copy; R3-780 touched five FILES and seven SITES.\n// \"Ten\" was neither.\n//\n// Not folded, deliberately, and the reason is NOT that they are all unalike — that was the\n// previous excuse and it was false for three of them:\n//\n// · `catalog.ts`, `recents.ts`, `tasks.ts` are pure copies of the shape `ipc.ts` had\n// until R3-780 folded it — untyped `Error & { code?: string }`, `res?.code ??\n// 'unknown'`. (`recents.ts` casts `code` as required rather than optional; immaterial,\n// the cast erases.) They are foldable and nothing here argues otherwise;\n// · `feed.ts`, `netFetch.ts` and `theme.ts` (×3) read `res && 'code' in res`, which\n// THREW `TypeError: Cannot use 'in' operator` on a string reply — FOLDED in R3-817\n// (0.74.3), a behaviour change reviewed as its own item, exactly as this bullet\n// prescribed;\n// · `launch.ts` folds `!res.data?.launchId` into the same condition and RETURNS\n// `{ ok: false, code }` instead of throwing. Different control flow entirely.\n//\n// So the remaining work is two items, not one, and they are not the same size.\n//\n// `check:clones` cannot help with any of this: minLines 6, minTokens 50, and no identifier\n// normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// THIS FILE'S OWN TEST IS LOAD-BEARING FOR ALL EIGHTEEN SITES\n// ---------------------------------------------------------------------------\n//\n// Measured: changing the guard to `r.ok !== false` compiles clean and leaves **ten of the\n// eighteen SITES** green — seven of the thirteen files: `dnd`, `editor`, `ipc`, `mounts`,\n// `secrets`, `spacesMode` and `vcs`. Every one of them stubs an explicit `{ ok: false }`,\n// so they pin \"throws on a refusal envelope\" and nothing about a malformed or absent\n// reply. The catchers: `openBundle`, `openExternal`, `openRepository`, the five R3-817 sites (whose\n// string-reply tests reject on a non-envelope — the mutation never throws), plus\n// `protocolRefusal.test.ts`. (Re-run 2026-09-30 on the post-fold tree: suites red —\n// feed, netFetch, theme, openExternal, openRepository, protocolRefusal; the seven\n// families green. `openBundle`, the eighteenth site, was added 2026-10-05 and re-run alone\n// under the same mutation: red.)\n//\n// (An earlier version of this paragraph said \"nine of the twelve sites' suites\", which\n// mixes sites with suites — the exact mistake the census block above is headed about —\n// and omitted `secrets` and `spacesMode` from the green list.)\n//\n// Each inline form this replaced carried its own `!res ||` guard, visible at the call site.\n// That guarantee now lives here alone. Do not weaken `protocolRefusal.test.ts` on the\n// grounds that \"the consumers cover it\" — they do not, and eighteen near-duplicate malformed\n// -reply tests would be the duplication this extraction exists to remove.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers did this until R3-778 closed it (site-main; audited sdk#184 round 2, 2026-09-25; fixed 2026-09-28 — both now throw, and a dispatcher assertion reddens on the shape):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reported that to the app as a successful open, until R3-778 closed it. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That was a live defect in site-main's handlers until R3-778 closed it (2026-09-28), not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. Eighteen sites call this;\n * **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the\n * helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**\n * shapes:\n *\n * - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —\n * `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;\n * - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;\n * folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,\n * the TypeError fix disclosed above);\n * - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —\n * `ipc.ts`.\n *\n * Every one of them let a host sending `code: 42` surface `err.code === 42` on a field\n * declared `string`, and turned `message: 42` into the string `\"42\"`. Both now fall back,\n * to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by\n * `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is\n * where a consumer learns of it.\n *\n * The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL\n * and `CodedRefusalError` requires it. No runtime difference for a missing code — the old\n * code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back\n * too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`\n * can stop.\n *\n * Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`\n * throws on a string reply.\n *\n * ONE revision of this paragraph got that backwards, and this is the fourth attempt to\n * describe it accurately. The original text was right FOR ITS REFERENT — it named\n * `'code' in res` as a shape replaced, without saying which sites, and at the time the\n * sites it referred to were R3-708's four, two of which used that form. R3-780 then folded\n * five DIFFERENT files and inherited the sentence unchanged, so it became false in place\n * without anyone editing it. That silent shift is the likeliest reason the next revision\n * \"corrected\" it to say NO replaced site used it — which is false the other way:\n * `openExternal` and `openRepository` did.\n *\n * The mechanism is worth more than the correction, because it is repeatable. `'code' in\n * res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who\n * greps `main` finds nothing, and this paragraph is the record of where it lived and why\n * it misread twice before. What a grep of `main` cannot show is that the\n * form was ALSO at two sites R3-708 folded. The tree that answers the question is the one\n * before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n *\n * R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,\n * `theme.ts` ×3) folded onto this — removing a latent defect with them: their\n * `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a\n * bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`\n * branch an app wrote. This function reads `typeof r?.code === 'string'` and\n * cannot throw on any input; the TypeError path no longer exists.\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";AAiLO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — miscounted four times. COUNT THE GREP, and say which unit.\n// ---------------------------------------------------------------------------\n//\n// R3-708's review said three copies, then five, then \"ten across eight files\". This file\n// then said ten while the list beneath it summed to twelve, and a fourth reviewer caught\n// that. After R3-816 folded the pure copies, and R3-1089 folded `catalog.ts` (the helper\n// learned `retryAfter` for it — the fold's premise holds again), the count is:\n//\n// **twenty-one CALL SITES across sixteen FILES** — `grep -n 'throwOnRefusal(' src/*.ts`,\n// minus the declaration here, minus `*.test.*`, and minus this census's own mention of\n// the pattern (the recipe's literal matches it):\n//\n// catalog.ts · dnd.ts · editor.ts · feed.ts · ipc.ts (×2) · mounts.ts (×3) · netFetch.ts ·\n// openBundle.ts · openExternal.ts · openRepository.ts · recents.ts · secrets.ts ·\n// spacesMode.ts · tasks.ts · theme.ts (×3) · vcs.ts\n//\n// Every miscount came from the same two mistakes: reading files instead of counting the\n// grep, and never saying which unit was being counted. `mounts.ts` has three separate\n// request helpers, each with its own copy; R3-780 touched five FILES and seven SITES.\n// \"Ten\" was neither.\n//\n// R3-816 folded the pure copies of the shape `ipc.ts` had until R3-780 — `recents` and\n// `tasks` here (two of the three the item named; the third, `catalog`, is the exemption\n// above) — and the fold changed nothing observable. R3-817 (merged as #192, 0.74.3) then\n// folded the `res && 'code' in res` family — `openExternal`, `openRepository`, `feed`,\n// `netFetch` and `theme` (×3) — fixing the `TypeError: Cannot use 'in' operator` a string\n// reply used to throw there. That form is gone from main; nothing remains to fold in\n// either family.\n//\n// Still deliberately NOT folded:\n//\n// · `launch.ts` — it folds `!res.data?.launchId` into the same condition and RETURNS\n// `{ ok: false, code }` instead of throwing. Different control flow entirely.\n//\n// (`catalog.ts` folded in R3-1089 — the helper now builds R3-954's `retryAfter`, so the\n// exemption's premise is gone.)\n//\n// `check:clones` cannot help with any of this: minLines 6, minTokens 50, and no identifier\n// normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// THIS FILE'S OWN TEST IS LOAD-BEARING FOR ALL TWENTY SITES\n// ---------------------------------------------------------------------------\n//\n// Measured on this tree (2026-10-07, the take-over's re-run — the recipe, not the\n// history: apply the injection in a scratch copy and run the suite):\n//\n// - guard weakened to `r.ok === false` (a REFUSAL stops throwing and a success starts\n// throwing; an absent reply still throws through the `r &&` short-circuit):\n// **120 of 1002** tests redden, across **17 suites**;\n// - the FULL no-op neuter (the helper's body replaced by a bare return): **90 tests**\n// redden across **17 failed suites** — the sharper probe, and the one the\n// absent-reply cases redden under (they stay green under the guard-weakening,\n// which is the reason they exist).\n//\n// (An earlier take-over draft recorded 86 across 42 — a broken probe whose import\n// errors failed suites before their tests ran; the 90/17 pair is the stable re-run,\n// twice.)\n//\n// (An earlier version of this paragraph said \"nine of the twelve sites' suites\", which\n// mixes sites with suites — the exact mistake the census block above is headed about —\n// and omitted `secrets` and `spacesMode` from the green list.)\n//\n// Each inline form this replaced carried its own `!res ||` guard, visible at the call site.\n// That guarantee now lives here alone. Do not weaken `protocolRefusal.test.ts` on the\n// grounds that \"the consumers cover it\" — they do not, and fifteen near-duplicate\n// malformed-reply tests would be the duplication this extraction exists to remove.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers did this until R3-778 closed it (site-main; audited sdk#184 round 2, 2026-09-25; fixed 2026-09-28 — both now throw, and a dispatcher assertion reddens on the shape):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reported that to the app as a successful open, until R3-778 closed it. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That was a live defect in site-main's handlers until R3-778 closed it (2026-09-28), not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n /** A provider rate-limit's wait in seconds, when the refusal carried one (R3-954). */\n retryAfter?: number;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. Twenty-three sites call this;\n * **eighteen** had an inline copy it replaced (`spacesMode.ts` was written against the\n * helper in R3-708, `openBundle.ts` against it in R3-808, and `catalog.ts` folded in\n * R3-1089 once the helper learned `retryAfter` — the one site R3-954's copy had kept\n * out). They tested for PRESENCE, in **three** shapes:\n *\n * - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —\n * `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;\n * - **seven** used the `in` operator: `((res && 'code' in res ? res.code : undefined) as\n * Code) ?? 'unknown'` — `openExternal` and `openRepository` (folded in R3-708) and\n * `feed`, `netFetch` and `theme` (×3) (folded in R3-817, #192);\n * - **four** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —\n * `ipc` (×2), `recents`, `tasks` (folded in R3-816).\n *\n * Every one of them let a host sending `code: 42` surface `err.code === 42` on a field\n * declared `string`, and turned `message: 42` into the string `\"42\"`. Both now fall back,\n * to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by\n * `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is\n * where a consumer learns of it.\n *\n * The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL\n * and `CodedRefusalError` requires it. No runtime difference for a missing code — the old\n * code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back\n * too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`\n * can stop.\n *\n * Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`\n * throws on a string reply.\n *\n * ONE revision of this paragraph got that backwards, and this is the fourth attempt to\n * describe it accurately. The original text was right FOR ITS REFERENT — it named\n * `'code' in res` as a shape replaced, without saying which sites, and at the time the\n * sites it referred to were R3-708's four, two of which used that form. R3-780 then folded\n * five DIFFERENT files and inherited the sentence unchanged, so it became false in place\n * without anyone editing it. That silent shift is the likeliest reason the next revision\n * \"corrected\" it to say NO replaced site used it — which is false the other way:\n * `openExternal` and `openRepository` did.\n *\n * The mechanism is worth more than the correction, because it is repeatable. `'code' in\n * res` is GONE from `main` — R3-817 (merged as #192, 0.74.3) folded the five sites that\n * carried it (`feed`, `netFetch`, `theme` ×3), beside R3-708's two (`openExternal`,\n * `openRepository`). A grep of `main` today finds the form only in this file's comments\n * and in test files. The tree that shows the form at the sites is the one before the\n * folds, `d4b07cc1^`. Read that before rewriting this paragraph again.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown; retryAfter?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n // R3-1089: R3-954's retryAfter (a provider rate-limit's wait in seconds) rides\n // the refusal here too, so catalog.ts's invoke() folds like every other site.\n // Number.isFinite, not typeof: NaN and Infinity are numbers the\n // structured-clone transport carries intact.\n if (Number.isFinite(r?.retryAfter)) err.retryAfter = (r as { retryAfter: number }).retryAfter;\n throw err;\n}\n"],"mappings":";AAmLO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAKlD,MAAI,OAAO,SAAS,GAAG,UAAU,EAAG,KAAI,aAAc,EAA6B;AACnF,QAAM;AACR;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Provider icons provenance
|
|
2
|
+
|
|
3
|
+
`sprite.generated.ts` vendors the monochrome provider icon set from
|
|
4
|
+
[sst/opencode](https://github.com/sst/opencode) —
|
|
5
|
+
`packages/ui/src/assets/icons/provider/*.svg` at commit
|
|
6
|
+
`0dcedc199c83c88ef206b4d89351f4a0e4a9a61d` (2026-08-10), MIT-licensed
|
|
7
|
+
(opencode's repo-root LICENSE; the set carries no per-directory notice).
|
|
8
|
+
|
|
9
|
+
Regenerate with `node scripts/sync-provider-icons.mjs` (fetches at the pinned commit,
|
|
10
|
+
optimizes with svgo, enforces monochrome). Bump the pin deliberately; the diff is the
|
|
11
|
+
review.
|
|
12
|
+
|
|
13
|
+
Provider marks are trademarks of their owners and identify the provider.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
MIT License
|
|
18
|
+
|
|
19
|
+
Copyright (c) 2025 opencode
|
|
20
|
+
|
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
in the Software without restriction, including without limitation the rights
|
|
24
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
furnished to do so, subject to the following conditions:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
SOFTWARE.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var ProviderIcon_exports = {};
|
|
20
|
+
__export(ProviderIcon_exports, {
|
|
21
|
+
ProviderIcon: () => ProviderIcon
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ProviderIcon_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_sprite = require("./sprite.generated");
|
|
27
|
+
const SPRITE_NODE_ID = "ir-provider-icon-sprite";
|
|
28
|
+
const ensureSprite = (doc) => {
|
|
29
|
+
if (doc.getElementById(SPRITE_NODE_ID)) return;
|
|
30
|
+
const host = doc.createElement("div");
|
|
31
|
+
host.id = SPRITE_NODE_ID;
|
|
32
|
+
host.setAttribute("aria-hidden", "true");
|
|
33
|
+
host.style.display = "none";
|
|
34
|
+
host.innerHTML = import_sprite.PROVIDER_ICON_SPRITE;
|
|
35
|
+
doc.body.appendChild(host);
|
|
36
|
+
};
|
|
37
|
+
function ProviderIcon({ id, label, size = 16 }) {
|
|
38
|
+
const known = import_sprite.PROVIDER_ICON_IDS.includes(id);
|
|
39
|
+
const docRef = (0, import_react.useRef)(null);
|
|
40
|
+
if (typeof document !== "undefined") docRef.current = document;
|
|
41
|
+
(0, import_react.useEffect)(() => {
|
|
42
|
+
if (known && docRef.current) ensureSprite(docRef.current);
|
|
43
|
+
}, [known]);
|
|
44
|
+
if (!known) {
|
|
45
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
46
|
+
"span",
|
|
47
|
+
{
|
|
48
|
+
role: "img",
|
|
49
|
+
"aria-label": label,
|
|
50
|
+
style: { display: "inline-block", width: size, height: size, textAlign: "center" },
|
|
51
|
+
children: label.charAt(0).toUpperCase()
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { role: "img", "aria-label": label, width: size, height: size, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("use", { href: `#pi-${id}` }) });
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
ProviderIcon
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=ProviderIcon.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/providerIcons/ProviderIcon.tsx"],"sourcesContent":["// ProviderIcon — the monochrome provider mark, keyed by models.dev provider id\n// (R3-1141; the same key as the catalogue's `modelsDevId`).\n//\n// The sprite is vendored (scripts/sync-provider-icons.mjs → sprite.generated.ts):\n// no runtime fetch — the CSP allows no external image host, and a refresh's diff is\n// reviewable. Monochrome is enforced by the generator (every paint is currentColor or\n// none), so the mark inherits the surrounding text color and no brand recoloring is\n// possible. A provider with no icon keeps its lettermark — a guessed logo misrepresents\n// the provider, which is worse than no logo.\n\nimport type { ReactNode } from 'react';\nimport { useEffect, useRef } from 'react';\nimport { PROVIDER_ICON_IDS, PROVIDER_ICON_SPRITE } from './sprite.generated';\n\nconst SPRITE_NODE_ID = 'ir-provider-icon-sprite';\n\n/** Inject the sprite once per document; a second renderer (or a remount) finds the\n * existing node and adds nothing. */\nconst ensureSprite = (doc: Document): void => {\n if (doc.getElementById(SPRITE_NODE_ID)) return;\n const host = doc.createElement('div');\n host.id = SPRITE_NODE_ID;\n host.setAttribute('aria-hidden', 'true');\n host.style.display = 'none';\n host.innerHTML = PROVIDER_ICON_SPRITE;\n doc.body.appendChild(host);\n};\n\nexport interface ProviderIconProps {\n /** The models.dev provider id (the sprite's symbol key). */\n id: string;\n /** The accessible name — and the lettermark's source when no icon exists. */\n label: string;\n /** Square edge in px. */\n size?: number;\n}\n\nexport function ProviderIcon({ id, label, size = 16 }: ProviderIconProps): ReactNode {\n const known = (PROVIDER_ICON_IDS as readonly string[]).includes(id);\n // useEffect, not render: the injection is a side effect, and a second render must not\n // double-inject (the getElementById check is the idempotence, the effect is the rule).\n const docRef = useRef<Document | null>(null);\n if (typeof document !== 'undefined') docRef.current = document;\n useEffect(() => {\n if (known && docRef.current) ensureSprite(docRef.current);\n }, [known]);\n\n if (!known) {\n // The lettermark: the label's first letter, no invented mark.\n return (\n <span\n role=\"img\"\n aria-label={label}\n style={{ display: 'inline-block', width: size, height: size, textAlign: 'center' }}\n >\n {label.charAt(0).toUpperCase()}\n </span>\n );\n }\n return (\n <svg role=\"img\" aria-label={label} width={size} height={size}>\n <use href={`#pi-${id}`} />\n </svg>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkDM;AAvCN,mBAAkC;AAClC,oBAAwD;AAExD,MAAM,iBAAiB;AAIvB,MAAM,eAAe,CAAC,QAAwB;AAC5C,MAAI,IAAI,eAAe,cAAc,EAAG;AACxC,QAAM,OAAO,IAAI,cAAc,KAAK;AACpC,OAAK,KAAK;AACV,OAAK,aAAa,eAAe,MAAM;AACvC,OAAK,MAAM,UAAU;AACrB,OAAK,YAAY;AACjB,MAAI,KAAK,YAAY,IAAI;AAC3B;AAWO,SAAS,aAAa,EAAE,IAAI,OAAO,OAAO,GAAG,GAAiC;AACnF,QAAM,QAAS,gCAAwC,SAAS,EAAE;AAGlE,QAAM,aAAS,qBAAwB,IAAI;AAC3C,MAAI,OAAO,aAAa,YAAa,QAAO,UAAU;AACtD,8BAAU,MAAM;AACd,QAAI,SAAS,OAAO,QAAS,cAAa,OAAO,OAAO;AAAA,EAC1D,GAAG,CAAC,KAAK,CAAC;AAEV,MAAI,CAAC,OAAO;AAEV,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,cAAY;AAAA,QACZ,OAAO,EAAE,SAAS,gBAAgB,OAAO,MAAM,QAAQ,MAAM,WAAW,SAAS;AAAA,QAEhF,gBAAM,OAAO,CAAC,EAAE,YAAY;AAAA;AAAA,IAC/B;AAAA,EAEJ;AACA,SACE,4CAAC,SAAI,MAAK,OAAM,cAAY,OAAO,OAAO,MAAM,QAAQ,MACtD,sDAAC,SAAI,MAAM,OAAO,EAAE,IAAI,GAC1B;AAEJ;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface ProviderIconProps {
|
|
4
|
+
/** The models.dev provider id (the sprite's symbol key). */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The accessible name — and the lettermark's source when no icon exists. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Square edge in px. */
|
|
9
|
+
size?: number;
|
|
10
|
+
}
|
|
11
|
+
declare function ProviderIcon({ id, label, size }: ProviderIconProps): ReactNode;
|
|
12
|
+
|
|
13
|
+
export { ProviderIcon, type ProviderIconProps };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface ProviderIconProps {
|
|
4
|
+
/** The models.dev provider id (the sprite's symbol key). */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The accessible name — and the lettermark's source when no icon exists. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Square edge in px. */
|
|
9
|
+
size?: number;
|
|
10
|
+
}
|
|
11
|
+
declare function ProviderIcon({ id, label, size }: ProviderIconProps): ReactNode;
|
|
12
|
+
|
|
13
|
+
export { ProviderIcon, type ProviderIconProps };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import "../chunk-VHAA22YE.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { PROVIDER_ICON_IDS, PROVIDER_ICON_SPRITE } from "./sprite.generated.js";
|
|
5
|
+
const SPRITE_NODE_ID = "ir-provider-icon-sprite";
|
|
6
|
+
const ensureSprite = (doc) => {
|
|
7
|
+
if (doc.getElementById(SPRITE_NODE_ID)) return;
|
|
8
|
+
const host = doc.createElement("div");
|
|
9
|
+
host.id = SPRITE_NODE_ID;
|
|
10
|
+
host.setAttribute("aria-hidden", "true");
|
|
11
|
+
host.style.display = "none";
|
|
12
|
+
host.innerHTML = PROVIDER_ICON_SPRITE;
|
|
13
|
+
doc.body.appendChild(host);
|
|
14
|
+
};
|
|
15
|
+
function ProviderIcon({ id, label, size = 16 }) {
|
|
16
|
+
const known = PROVIDER_ICON_IDS.includes(id);
|
|
17
|
+
const docRef = useRef(null);
|
|
18
|
+
if (typeof document !== "undefined") docRef.current = document;
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (known && docRef.current) ensureSprite(docRef.current);
|
|
21
|
+
}, [known]);
|
|
22
|
+
if (!known) {
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
"span",
|
|
25
|
+
{
|
|
26
|
+
role: "img",
|
|
27
|
+
"aria-label": label,
|
|
28
|
+
style: { display: "inline-block", width: size, height: size, textAlign: "center" },
|
|
29
|
+
children: label.charAt(0).toUpperCase()
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return /* @__PURE__ */ jsx("svg", { role: "img", "aria-label": label, width: size, height: size, children: /* @__PURE__ */ jsx("use", { href: `#pi-${id}` }) });
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
ProviderIcon
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=ProviderIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/providerIcons/ProviderIcon.tsx"],"sourcesContent":["// ProviderIcon — the monochrome provider mark, keyed by models.dev provider id\n// (R3-1141; the same key as the catalogue's `modelsDevId`).\n//\n// The sprite is vendored (scripts/sync-provider-icons.mjs → sprite.generated.ts):\n// no runtime fetch — the CSP allows no external image host, and a refresh's diff is\n// reviewable. Monochrome is enforced by the generator (every paint is currentColor or\n// none), so the mark inherits the surrounding text color and no brand recoloring is\n// possible. A provider with no icon keeps its lettermark — a guessed logo misrepresents\n// the provider, which is worse than no logo.\n\nimport type { ReactNode } from 'react';\nimport { useEffect, useRef } from 'react';\nimport { PROVIDER_ICON_IDS, PROVIDER_ICON_SPRITE } from './sprite.generated';\n\nconst SPRITE_NODE_ID = 'ir-provider-icon-sprite';\n\n/** Inject the sprite once per document; a second renderer (or a remount) finds the\n * existing node and adds nothing. */\nconst ensureSprite = (doc: Document): void => {\n if (doc.getElementById(SPRITE_NODE_ID)) return;\n const host = doc.createElement('div');\n host.id = SPRITE_NODE_ID;\n host.setAttribute('aria-hidden', 'true');\n host.style.display = 'none';\n host.innerHTML = PROVIDER_ICON_SPRITE;\n doc.body.appendChild(host);\n};\n\nexport interface ProviderIconProps {\n /** The models.dev provider id (the sprite's symbol key). */\n id: string;\n /** The accessible name — and the lettermark's source when no icon exists. */\n label: string;\n /** Square edge in px. */\n size?: number;\n}\n\nexport function ProviderIcon({ id, label, size = 16 }: ProviderIconProps): ReactNode {\n const known = (PROVIDER_ICON_IDS as readonly string[]).includes(id);\n // useEffect, not render: the injection is a side effect, and a second render must not\n // double-inject (the getElementById check is the idempotence, the effect is the rule).\n const docRef = useRef<Document | null>(null);\n if (typeof document !== 'undefined') docRef.current = document;\n useEffect(() => {\n if (known && docRef.current) ensureSprite(docRef.current);\n }, [known]);\n\n if (!known) {\n // The lettermark: the label's first letter, no invented mark.\n return (\n <span\n role=\"img\"\n aria-label={label}\n style={{ display: 'inline-block', width: size, height: size, textAlign: 'center' }}\n >\n {label.charAt(0).toUpperCase()}\n </span>\n );\n }\n return (\n <svg role=\"img\" aria-label={label} width={size} height={size}>\n <use href={`#pi-${id}`} />\n </svg>\n );\n}\n"],"mappings":";AAkDM;AAvCN,SAAS,WAAW,cAAc;AAClC,SAAS,mBAAmB,4BAA4B;AAExD,MAAM,iBAAiB;AAIvB,MAAM,eAAe,CAAC,QAAwB;AAC5C,MAAI,IAAI,eAAe,cAAc,EAAG;AACxC,QAAM,OAAO,IAAI,cAAc,KAAK;AACpC,OAAK,KAAK;AACV,OAAK,aAAa,eAAe,MAAM;AACvC,OAAK,MAAM,UAAU;AACrB,OAAK,YAAY;AACjB,MAAI,KAAK,YAAY,IAAI;AAC3B;AAWO,SAAS,aAAa,EAAE,IAAI,OAAO,OAAO,GAAG,GAAiC;AACnF,QAAM,QAAS,kBAAwC,SAAS,EAAE;AAGlE,QAAM,SAAS,OAAwB,IAAI;AAC3C,MAAI,OAAO,aAAa,YAAa,QAAO,UAAU;AACtD,YAAU,MAAM;AACd,QAAI,SAAS,OAAO,QAAS,cAAa,OAAO,OAAO;AAAA,EAC1D,GAAG,CAAC,KAAK,CAAC;AAEV,MAAI,CAAC,OAAO;AAEV,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,cAAY;AAAA,QACZ,OAAO,EAAE,SAAS,gBAAgB,OAAO,MAAM,QAAQ,MAAM,WAAW,SAAS;AAAA,QAEhF,gBAAM,OAAO,CAAC,EAAE,YAAY;AAAA;AAAA,IAC/B;AAAA,EAEJ;AACA,SACE,oBAAC,SAAI,MAAK,OAAM,cAAY,OAAO,OAAO,MAAM,QAAQ,MACtD,8BAAC,SAAI,MAAM,OAAO,EAAE,IAAI,GAC1B;AAEJ;","names":[]}
|