@hosty-sdk/app 0.8.0 → 0.9.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/embedder.d.ts +12 -0
- package/dist/embedder.js +26 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/package.json +1 -1
package/dist/embedder.d.ts
CHANGED
|
@@ -51,6 +51,18 @@ export interface AskAssistantIntent {
|
|
|
51
51
|
* embedder must still decide is *where* the text goes — this function says an app asked, never that
|
|
52
52
|
* the assistant should send anything. Nothing here may be auto-sent.
|
|
53
53
|
*/
|
|
54
|
+
/**
|
|
55
|
+
* Verifies an attention count posted by a frame the embedder deliberately embeds.
|
|
56
|
+
*
|
|
57
|
+
* Read from the frame rather than polled by the embedder: the page that holds the session list and
|
|
58
|
+
* its event stream is the one source, and a shell asking the same question on a timer would be a
|
|
59
|
+
* second source that disagrees with the first for the length of its interval.
|
|
60
|
+
*
|
|
61
|
+
* Sender-verified like every other message here, though the payload is only a count: a wrong badge is
|
|
62
|
+
* a small harm, and a wrong badge that any page could set is a way to make an operator stop trusting
|
|
63
|
+
* the badge that matters.
|
|
64
|
+
*/
|
|
65
|
+
export declare function parseActiveFrameAttention(event: EmbedderMessage, activeFrameWindow: unknown, activeFrameUrl: string): number | null;
|
|
54
66
|
export declare function parseActiveFrameAskAssistant(event: EmbedderMessage, activeFrameWindow: unknown, activeFrameUrl: string): AskAssistantIntent | null;
|
|
55
67
|
/**
|
|
56
68
|
* Per-app reissue throttle: a frame that keeps re-posting (e.g. it never accepts the new
|
package/dist/embedder.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// you have decided to grant one, mint a token from Core with your own session and post it back
|
|
13
13
|
// to that frame's origin. Both requests are unauthenticated by design; what makes them safe is
|
|
14
14
|
// that the embedder answers from facts about its own DOM rather than from what the frame claims.
|
|
15
|
-
import { ASK_ASSISTANT_MAX_CHARS, ASK_ASSISTANT_TYPE, AUTH_REQUIRED_INTENT_TYPE, DELEGATED_TOKEN_REQUEST_TYPE, } from "./index.js";
|
|
15
|
+
import { ASK_ASSISTANT_MAX_CHARS, ASK_ASSISTANT_TYPE, ATTENTION_TYPE, AUTH_REQUIRED_INTENT_TYPE, DELEGATED_TOKEN_REQUEST_TYPE, } from "./index.js";
|
|
16
16
|
/**
|
|
17
17
|
* Verifies that a `message` event is a genuine auth-required intent from the active app
|
|
18
18
|
* frame. Every check is about facts only the embedder can know:
|
|
@@ -66,6 +66,31 @@ export function parseActiveFrameDelegatedTokenRequest(event, activeFrameWindow,
|
|
|
66
66
|
* embedder must still decide is *where* the text goes — this function says an app asked, never that
|
|
67
67
|
* the assistant should send anything. Nothing here may be auto-sent.
|
|
68
68
|
*/
|
|
69
|
+
/**
|
|
70
|
+
* Verifies an attention count posted by a frame the embedder deliberately embeds.
|
|
71
|
+
*
|
|
72
|
+
* Read from the frame rather than polled by the embedder: the page that holds the session list and
|
|
73
|
+
* its event stream is the one source, and a shell asking the same question on a timer would be a
|
|
74
|
+
* second source that disagrees with the first for the length of its interval.
|
|
75
|
+
*
|
|
76
|
+
* Sender-verified like every other message here, though the payload is only a count: a wrong badge is
|
|
77
|
+
* a small harm, and a wrong badge that any page could set is a way to make an operator stop trusting
|
|
78
|
+
* the badge that matters.
|
|
79
|
+
*/
|
|
80
|
+
export function parseActiveFrameAttention(event, activeFrameWindow, activeFrameUrl) {
|
|
81
|
+
if (!isActiveFrameMessage(event, activeFrameWindow, activeFrameUrl)) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const candidate = event.data;
|
|
85
|
+
// `typeof NaN === "number"`, and NaN survives every clamp below to arrive as a badge count no
|
|
86
|
+
// renderer can do anything with. Finiteness is the check that was actually meant.
|
|
87
|
+
if (candidate.type !== ATTENTION_TYPE || !Number.isFinite(candidate.count)) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// Clamped rather than trusted: a negative or absurd count would render as a badge nobody can
|
|
91
|
+
// explain, and the frame has no business deciding how large a number the shell displays.
|
|
92
|
+
return Math.max(0, Math.min(99, Math.floor(candidate.count)));
|
|
93
|
+
}
|
|
69
94
|
export function parseActiveFrameAskAssistant(event, activeFrameWindow, activeFrameUrl) {
|
|
70
95
|
if (!isActiveFrameMessage(event, activeFrameWindow, activeFrameUrl)) {
|
|
71
96
|
return null;
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,13 @@ export declare function createAuthRequiredIntent(appId: string): AuthRequiredInt
|
|
|
34
34
|
* operator cannot read at a glance, and an answer would turn a hand-off into a channel.
|
|
35
35
|
*/
|
|
36
36
|
export declare const ASK_ASSISTANT_TYPE = "hosty:ask-assistant";
|
|
37
|
+
/**
|
|
38
|
+
* How many of an embedded assistant's sessions are waiting for the operator.
|
|
39
|
+
*
|
|
40
|
+
* Published by the page that holds them, not asked for on a timer: one source, so a shell's badge and
|
|
41
|
+
* the list behind it can never disagree.
|
|
42
|
+
*/
|
|
43
|
+
export declare const ATTENTION_TYPE = "hosty:assistant-attention";
|
|
37
44
|
/** Longer than a prompt fragment is a page dumping itself into someone's draft. */
|
|
38
45
|
export declare const ASK_ASSISTANT_MAX_CHARS = 4000;
|
|
39
46
|
export interface AskAssistantMessage {
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,13 @@ export function createAuthRequiredIntent(appId) {
|
|
|
37
37
|
* operator cannot read at a glance, and an answer would turn a hand-off into a channel.
|
|
38
38
|
*/
|
|
39
39
|
export const ASK_ASSISTANT_TYPE = "hosty:ask-assistant";
|
|
40
|
+
/**
|
|
41
|
+
* How many of an embedded assistant's sessions are waiting for the operator.
|
|
42
|
+
*
|
|
43
|
+
* Published by the page that holds them, not asked for on a timer: one source, so a shell's badge and
|
|
44
|
+
* the list behind it can never disagree.
|
|
45
|
+
*/
|
|
46
|
+
export const ATTENTION_TYPE = "hosty:assistant-attention";
|
|
40
47
|
/** Longer than a prompt fragment is a page dumping itself into someone's draft. */
|
|
41
48
|
export const ASK_ASSISTANT_MAX_CHARS = 4000;
|
|
42
49
|
/**
|
package/package.json
CHANGED