@stigmer/sdk 3.1.7 → 3.1.8
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/__tests__/errors.test.js +42 -0
- package/__tests__/errors.test.js.map +1 -1
- package/__tests__/guest-auth.test.d.ts +2 -0
- package/__tests__/guest-auth.test.d.ts.map +1 -0
- package/__tests__/guest-auth.test.js +223 -0
- package/__tests__/guest-auth.test.js.map +1 -0
- package/__tests__/sharing.test.d.ts +2 -0
- package/__tests__/sharing.test.d.ts.map +1 -0
- package/__tests__/sharing.test.js +106 -0
- package/__tests__/sharing.test.js.map +1 -0
- package/gen/agent.d.ts +20 -1
- package/gen/agent.d.ts.map +1 -1
- package/gen/agent.js +54 -1
- package/gen/agent.js.map +1 -1
- package/gen/client.d.ts +1 -1
- package/gen/client.d.ts.map +1 -1
- package/gen/environment.d.ts +2 -0
- package/gen/environment.d.ts.map +1 -1
- package/gen/environment.js +8 -0
- package/gen/environment.js.map +1 -1
- package/gen/platformclient.d.ts +2 -1
- package/gen/platformclient.d.ts.map +1 -1
- package/gen/platformclient.js +8 -0
- package/gen/platformclient.js.map +1 -1
- package/gen/session.d.ts +2 -2
- package/gen/session.d.ts.map +1 -1
- package/gen/session.js +2 -2
- package/gen/session.js.map +1 -1
- package/guest-auth.d.ts +172 -0
- package/guest-auth.d.ts.map +1 -0
- package/guest-auth.js +227 -0
- package/guest-auth.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +4 -0
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/sharing.d.ts +75 -0
- package/sharing.d.ts.map +1 -0
- package/sharing.js +116 -0
- package/sharing.js.map +1 -0
- package/src/__tests__/errors.test.ts +56 -0
- package/src/__tests__/guest-auth.test.ts +287 -0
- package/src/__tests__/sharing.test.ts +159 -0
- package/src/gen/agent.ts +61 -2
- package/src/gen/client.ts +1 -1
- package/src/gen/environment.ts +7 -1
- package/src/gen/platformclient.ts +7 -1
- package/src/gen/session.ts +3 -3
- package/src/guest-auth.ts +331 -0
- package/src/index.ts +20 -0
- package/src/sharing.ts +134 -0
package/guest-auth.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { createGrpcWebTransport } from "@connectrpc/connect-web";
|
|
2
|
+
import { createClient } from "@connectrpc/connect";
|
|
3
|
+
import { create } from "@bufbuild/protobuf";
|
|
4
|
+
import { PlatformClientTokenController } from "@stigmer/protos/ai/stigmer/iam/platformclient/v1/token_pb";
|
|
5
|
+
import { MintGuestTokenRequestSchema } from "@stigmer/protos/ai/stigmer/iam/platformclient/v1/token_pb";
|
|
6
|
+
import { wrapError } from "./gen/errors.js";
|
|
7
|
+
import { rpcMetadataInterceptor, errorStripInterceptor, } from "./internal/interceptors.js";
|
|
8
|
+
/**
|
|
9
|
+
* How long before expiry a cached guest token is considered stale.
|
|
10
|
+
* Re-minting inside this window keeps long-lived streams from starting
|
|
11
|
+
* with a token that expires moments later.
|
|
12
|
+
*/
|
|
13
|
+
const EXPIRY_SKEW_MS = 60_000;
|
|
14
|
+
/** Storage key prefix for the persisted guest id, namespaced per org. */
|
|
15
|
+
const GUEST_ID_STORAGE_PREFIX = "stigmer:guest-id:";
|
|
16
|
+
/**
|
|
17
|
+
* Guest token-minting helper for shared-agent pages.
|
|
18
|
+
*
|
|
19
|
+
* A minimal, purpose-built companion to the main Stigmer client: it
|
|
20
|
+
* lazily mints short-lived guest JWTs via the public `mintGuestToken`
|
|
21
|
+
* RPC, caches them in memory until just before expiry, and persists
|
|
22
|
+
* the server-issued guest id so the same browser resolves to the same
|
|
23
|
+
* guest across visits.
|
|
24
|
+
*
|
|
25
|
+
* Wire {@link getAccessToken} into a `Stigmer` client — the SDK calls
|
|
26
|
+
* it per request, so refresh is automatic and no token ever needs to
|
|
27
|
+
* be stored outside memory.
|
|
28
|
+
*
|
|
29
|
+
* Failure semantics: when minting fails (e.g. sharing was revoked —
|
|
30
|
+
* the server answers NOT_FOUND, indistinguishable from "no such
|
|
31
|
+
* agent"), {@link getAccessToken} rejects with a `StigmerError`, which
|
|
32
|
+
* fails the triggering request with the real cause instead of sending
|
|
33
|
+
* it unauthenticated.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const guestAuth = createGuestAuth({
|
|
38
|
+
* baseUrl: "https://api.stigmer.ai",
|
|
39
|
+
* org: "acme",
|
|
40
|
+
* slug: "support-agent",
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* const client = new Stigmer({
|
|
44
|
+
* baseUrl: "https://api.stigmer.ai",
|
|
45
|
+
* getAccessToken: guestAuth.getAccessToken,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export class GuestAuth {
|
|
50
|
+
tokenClient;
|
|
51
|
+
org;
|
|
52
|
+
slug;
|
|
53
|
+
storage;
|
|
54
|
+
storageKey;
|
|
55
|
+
embedOrigin;
|
|
56
|
+
linkToken;
|
|
57
|
+
cached = null;
|
|
58
|
+
pendingMint = null;
|
|
59
|
+
/** @internal Use {@link createGuestAuth} instead. */
|
|
60
|
+
constructor(config) {
|
|
61
|
+
this.org = config.org;
|
|
62
|
+
this.slug = config.slug;
|
|
63
|
+
this.storage = config.storage ?? resolveDefaultStorage();
|
|
64
|
+
this.storageKey = `${GUEST_ID_STORAGE_PREFIX}${config.org}`;
|
|
65
|
+
this.embedOrigin = config.embedOrigin ?? "";
|
|
66
|
+
this.linkToken = config.linkToken ?? "";
|
|
67
|
+
const transport = createGrpcWebTransport({
|
|
68
|
+
baseUrl: config.baseUrl,
|
|
69
|
+
interceptors: [rpcMetadataInterceptor, errorStripInterceptor],
|
|
70
|
+
});
|
|
71
|
+
this.tokenClient = createClient(PlatformClientTokenController, transport);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The visitor's persisted guest id, or `null` before the first
|
|
75
|
+
* successful mint in this browser.
|
|
76
|
+
*/
|
|
77
|
+
get guestCookieId() {
|
|
78
|
+
return safeGetItem(this.storage, this.storageKey);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Token provider for `StigmerConfig.getAccessToken`.
|
|
82
|
+
*
|
|
83
|
+
* Returns the cached guest JWT while it has more than a minute of
|
|
84
|
+
* life left; otherwise mints a fresh one. Concurrent callers during
|
|
85
|
+
* a mint share the same in-flight request (single-flight).
|
|
86
|
+
*
|
|
87
|
+
* Defined as an arrow property so it can be passed detached:
|
|
88
|
+
* `new Stigmer({ ..., getAccessToken: guestAuth.getAccessToken })`.
|
|
89
|
+
*
|
|
90
|
+
* @throws {StigmerError} with code `"not-found"` when the agent is
|
|
91
|
+
* not shared (or sharing was revoked — the server keeps the two
|
|
92
|
+
* indistinguishable by design)
|
|
93
|
+
* @throws {StigmerError} with code `"permission-denied"` when
|
|
94
|
+
* `embedOrigin` is not in the agent's `allowed_origins` — embeds
|
|
95
|
+
* should hide the widget on this code rather than surface an error
|
|
96
|
+
* @throws {StigmerError} with code `"invalid-argument"` when org or
|
|
97
|
+
* slug is malformed
|
|
98
|
+
*/
|
|
99
|
+
getAccessToken = async () => {
|
|
100
|
+
if (this.cached && this.cached.expiresAt - Date.now() > EXPIRY_SKEW_MS) {
|
|
101
|
+
return this.cached.accessToken;
|
|
102
|
+
}
|
|
103
|
+
// Single-flight: the provider is invoked once per request, so a
|
|
104
|
+
// burst at page load (registry fetches + profile resolution) must
|
|
105
|
+
// collapse into one mint — both for latency and because concurrent
|
|
106
|
+
// first mints would otherwise race to persist different guest ids.
|
|
107
|
+
this.pendingMint ??= this.mint().finally(() => {
|
|
108
|
+
this.pendingMint = null;
|
|
109
|
+
});
|
|
110
|
+
return this.pendingMint;
|
|
111
|
+
};
|
|
112
|
+
async mint() {
|
|
113
|
+
try {
|
|
114
|
+
const response = await this.tokenClient.mintGuestToken(create(MintGuestTokenRequestSchema, {
|
|
115
|
+
org: this.org,
|
|
116
|
+
slug: this.slug,
|
|
117
|
+
guestCookieId: safeGetItem(this.storage, this.storageKey) ?? "",
|
|
118
|
+
embedOrigin: this.embedOrigin,
|
|
119
|
+
linkToken: this.linkToken,
|
|
120
|
+
}));
|
|
121
|
+
safeSetItem(this.storage, this.storageKey, response.guestCookieId);
|
|
122
|
+
this.cached = {
|
|
123
|
+
accessToken: response.accessToken,
|
|
124
|
+
expiresAt: Date.now() + response.expiresIn * 1000,
|
|
125
|
+
};
|
|
126
|
+
return response.accessToken;
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
throw wrapError(e);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* `localStorage` when usable, otherwise an in-memory fallback.
|
|
135
|
+
*
|
|
136
|
+
* Access is probed inside try/catch because merely touching
|
|
137
|
+
* `localStorage` can throw (e.g. sandboxed iframes with storage
|
|
138
|
+
* blocked). With the fallback, the chat still works — the visitor
|
|
139
|
+
* just gets a fresh guest identity per page load.
|
|
140
|
+
*
|
|
141
|
+
* `globalThis` is typed structurally because this package compiles
|
|
142
|
+
* without DOM libs (it is also consumed from Node, where
|
|
143
|
+
* `localStorage` does not exist).
|
|
144
|
+
*/
|
|
145
|
+
function resolveDefaultStorage() {
|
|
146
|
+
try {
|
|
147
|
+
const { localStorage: storage } = globalThis;
|
|
148
|
+
if (storage) {
|
|
149
|
+
const probeKey = "stigmer:storage-probe";
|
|
150
|
+
storage.setItem(probeKey, "1");
|
|
151
|
+
storage.removeItem(probeKey);
|
|
152
|
+
return storage;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Fall through to the in-memory storage below.
|
|
157
|
+
}
|
|
158
|
+
const memory = new Map();
|
|
159
|
+
return {
|
|
160
|
+
getItem: (key) => memory.get(key) ?? null,
|
|
161
|
+
setItem: (key, value) => {
|
|
162
|
+
memory.set(key, value);
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Storage reads/writes never fail the mint: the guest id is a
|
|
168
|
+
* convenience (stable identity across visits), not a requirement —
|
|
169
|
+
* the server issues a fresh id when none is presented.
|
|
170
|
+
*/
|
|
171
|
+
function safeGetItem(storage, key) {
|
|
172
|
+
try {
|
|
173
|
+
return storage.getItem(key);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function safeSetItem(storage, key, value) {
|
|
180
|
+
try {
|
|
181
|
+
storage.setItem(key, value);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// Persisting the id is best-effort; see safeGetItem.
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Create a guest token-minting helper for a shared agent's hosted page
|
|
189
|
+
* or embed.
|
|
190
|
+
*
|
|
191
|
+
* This is the browser-side counterpart of `createPlatformClientAuth`:
|
|
192
|
+
* it involves **no credentials** — the server gates minting on the
|
|
193
|
+
* agent's `spec.sharing.enabled` and issues a short-lived guest JWT
|
|
194
|
+
* scoped to the sharing org. Pass {@link GuestAuth.getAccessToken} to
|
|
195
|
+
* a `Stigmer` client and every request authenticates as this visitor.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* import { Stigmer, createGuestAuth } from "@stigmer/sdk";
|
|
200
|
+
*
|
|
201
|
+
* const guestAuth = createGuestAuth({
|
|
202
|
+
* baseUrl: "https://api.stigmer.ai",
|
|
203
|
+
* org: "acme",
|
|
204
|
+
* slug: "support-agent",
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* const client = new Stigmer({
|
|
208
|
+
* baseUrl: "https://api.stigmer.ai",
|
|
209
|
+
* getAccessToken: guestAuth.getAccessToken,
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @throws {Error} if `baseUrl`, `org`, or `slug` is missing or empty
|
|
214
|
+
*/
|
|
215
|
+
export function createGuestAuth(config) {
|
|
216
|
+
if (!config.baseUrl) {
|
|
217
|
+
throw new Error("createGuestAuth: baseUrl is required (e.g., \"https://api.stigmer.ai\")");
|
|
218
|
+
}
|
|
219
|
+
if (!config.org) {
|
|
220
|
+
throw new Error("createGuestAuth: org is required — the organization slug from the share URL");
|
|
221
|
+
}
|
|
222
|
+
if (!config.slug) {
|
|
223
|
+
throw new Error("createGuestAuth: slug is required — the agent slug from the share URL");
|
|
224
|
+
}
|
|
225
|
+
return new GuestAuth(config);
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=guest-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guest-auth.js","sourceRoot":"","sources":["../src/guest-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAe,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,2DAA2D,CAAC;AAC1G,OAAO,EAAE,2BAA2B,EAAE,MAAM,2DAA2D,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AA+EpC;;;;GAIG;AACH,MAAM,cAAc,GAAG,MAAM,CAAC;AAE9B,yEAAyE;AACzE,MAAM,uBAAuB,GAAG,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,SAAS;IACH,WAAW,CAA+C;IAC1D,GAAG,CAAS;IACZ,IAAI,CAAS;IACb,OAAO,CAAiB;IACxB,UAAU,CAAS;IACnB,WAAW,CAAS;IACpB,SAAS,CAAS;IAE3B,MAAM,GAAsD,IAAI,CAAC;IACjE,WAAW,GAA2B,IAAI,CAAC;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ED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { Stigmer } from "./stigmer.js";
|
|
2
2
|
export { type RunnerAdapter, type RunnerWorkerHost, createRunnerAdapter, } from "./runner-adapter.js";
|
|
3
3
|
export { type StigmerConfig, type TokenProvider } from "./config.js";
|
|
4
|
+
export { createGuestAuth, GuestAuth, type GuestAuthConfig, type GuestIdStorage, } from "./guest-auth.js";
|
|
5
|
+
export { MAX_ALLOWED_ORIGINS, LINK_TOKEN_PARAM, validateOrigin, chatPath, buildChatUrl, appendLinkToken, buildEmbedLoaderUrl, buildEmbedSnippet, } from "./sharing.js";
|
|
4
6
|
export { StigmerError, type ErrorCode, isNotFound, isUnauthenticated, isPermissionDenied, isRetryable, type ErrorCategory, isConnectError, classifyError, isRetryableError, isTransientStreamError, getUserMessage, type RpcErrorMetadata, annotateRpcError, getRpcMetadata, } from "./errors.js";
|
|
5
7
|
export { type DeploymentMode, isResourceAvailable, } from "./resource-availability.js";
|
|
6
8
|
export { getGrantableRoles, hasGrantableRoles, isRoleGrantable, } from "./authorization-config.js";
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAGrE,OAAO,EACL,YAAY,EACZ,KAAK,SAAS,EACd,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,KAAK,aAAa,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,KAAK,gBAAgB,EACrB,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC;AA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O,EACL,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,2BAA2B,CAAC"}
|
package/index.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
export { Stigmer } from "./stigmer.js";
|
|
4
4
|
// Runner adapter
|
|
5
5
|
export { createRunnerAdapter, } from "./runner-adapter.js";
|
|
6
|
+
// Guest auth (shared-agent pages and embeds; browser-safe, credential-free)
|
|
7
|
+
export { createGuestAuth, GuestAuth, } from "./guest-auth.js";
|
|
8
|
+
// Agent sharing (hosted link + embed snippet; framework-free)
|
|
9
|
+
export { MAX_ALLOWED_ORIGINS, LINK_TOKEN_PARAM, validateOrigin, chatPath, buildChatUrl, appendLinkToken, buildEmbedLoaderUrl, buildEmbedSnippet, } from "./sharing.js";
|
|
6
10
|
// Error handling
|
|
7
11
|
export { StigmerError, isNotFound, isUnauthenticated, isPermissionDenied, isRetryable, isConnectError, classifyError, isRetryableError, isTransientStreamError, getUserMessage, annotateRpcError, getRpcMetadata, } from "./errors.js";
|
|
8
12
|
// Resource availability
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,iBAAiB;AACjB,OAAO,EAGL,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAK7B,iBAAiB;AACjB,OAAO,EACL,YAAY,EAEZ,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EAEX,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EAEd,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,wBAAwB;AACxB,OAAO,EAEL,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AAEpC,8CAA8C;AAC9C,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAC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8",
|
|
4
4
|
"description": "Stigmer TypeScript SDK — typed API client for all Stigmer platform resources",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@bufbuild/protobuf": "^2.0.0",
|
|
46
46
|
"@connectrpc/connect-node": "^2.0.0",
|
|
47
|
-
"@stigmer/protos": "3.1.
|
|
47
|
+
"@stigmer/protos": "3.1.8"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/sharing.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-sharing helpers — the single source of truth for the hosted chat
|
|
3
|
+
* URL shape, the embed snippet, and client-side `allowed_origins`
|
|
4
|
+
* validation. Framework-free by design: consumed by the web console and
|
|
5
|
+
* desktop app (via `@stigmer/react`), the `stigmer` CLI, and any platform
|
|
6
|
+
* builder that wants to construct share links or embed snippets itself.
|
|
7
|
+
*
|
|
8
|
+
* The canonical URL shape is `<app-origin>/chat/<org>/<slug>` (a T01
|
|
9
|
+
* design decision), and `embed.js` is served from the root of that same
|
|
10
|
+
* app origin (T04). Callers supply the origin — resolving it is a host
|
|
11
|
+
* concern (the console knows its `appUrl`, the CLI resolves it from the
|
|
12
|
+
* backend type) — while the path and snippet shapes live here so every
|
|
13
|
+
* surface emits byte-identical output.
|
|
14
|
+
*/
|
|
15
|
+
/** Maximum number of allowed origins (proto: `repeated.max_items = 32`). */
|
|
16
|
+
export declare const MAX_ALLOWED_ORIGINS = 32;
|
|
17
|
+
/**
|
|
18
|
+
* Validate a single `allowed_origins` entry.
|
|
19
|
+
*
|
|
20
|
+
* Returns `null` when valid, or a user-facing message explaining what
|
|
21
|
+
* to fix (DD-006: errors state what happened and what to do).
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateOrigin(value: string): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Query parameter carrying the share-link token on a locked link:
|
|
26
|
+
* `/chat/<org>/<slug>?k=<token>`. Short by design — the token rides every
|
|
27
|
+
* copied link, and `k` (for "key") is the platform's one-character
|
|
28
|
+
* convention, mirrored by the hosted page and the embed widget.
|
|
29
|
+
*/
|
|
30
|
+
export declare const LINK_TOKEN_PARAM = "k";
|
|
31
|
+
/**
|
|
32
|
+
* The hosted chat page path for a shared agent: `/chat/<org>/<slug>`,
|
|
33
|
+
* plus `?k=<token>` when the share link is locked with a rotatable token
|
|
34
|
+
* (`agent.status.shareLinkToken`).
|
|
35
|
+
*
|
|
36
|
+
* Useful on its own when the caller renders relative to the current
|
|
37
|
+
* origin (e.g. a host that never configured an absolute app URL).
|
|
38
|
+
*/
|
|
39
|
+
export declare function chatPath(org: string, slug: string, linkToken?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* The absolute hosted chat URL for a shared agent:
|
|
42
|
+
* `<appOrigin>/chat/<org>/<slug>[?k=<token>]`.
|
|
43
|
+
*
|
|
44
|
+
* A trailing slash on `appOrigin` is tolerated so callers can pass
|
|
45
|
+
* user-configured values verbatim. An empty `appOrigin` degrades to the
|
|
46
|
+
* relative {@link chatPath} — the same graceful fallback a host without a
|
|
47
|
+
* configured public origin gets in the share dialog.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildChatUrl(appOrigin: string, org: string, slug: string, linkToken?: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Append the share-link token to an already-built chat URL.
|
|
52
|
+
*
|
|
53
|
+
* For hosts that construct the base URL through their own callback (the
|
|
54
|
+
* share dialog's `buildShareUrl` prop) rather than {@link buildChatUrl}.
|
|
55
|
+
* A `null`/empty token returns the URL unchanged, so callers can pass
|
|
56
|
+
* `agent.status?.shareLinkToken` straight through. Emits the identical
|
|
57
|
+
* `?k=` shape as {@link chatPath} — one URL grammar across every surface.
|
|
58
|
+
*/
|
|
59
|
+
export declare function appendLinkToken(url: string, linkToken: string | null | undefined): string;
|
|
60
|
+
/**
|
|
61
|
+
* The embed loader URL: `embed.js` lives at the root of the app origin
|
|
62
|
+
* (the loader derives the chat-page origin from its own script URL, so
|
|
63
|
+
* the two must share an origin). An empty `appOrigin` degrades to the
|
|
64
|
+
* relative `/embed.js`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildEmbedLoaderUrl(appOrigin: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* The two-line embed snippet an owner pastes into any website: the
|
|
69
|
+
* loader script plus the `<stigmer-agent>` element where the widget
|
|
70
|
+
* renders. A locked share link adds the `token` attribute, which the
|
|
71
|
+
* widget forwards as `?k=` on its iframe URL. Every surface (share
|
|
72
|
+
* dialog, CLI, docs) emits exactly this.
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildEmbedSnippet(appOrigin: string, org: string, slug: string, linkToken?: string): string;
|
|
75
|
+
//# sourceMappingURL=sharing.d.ts.map
|
package/sharing.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharing.d.ts","sourceRoot":"","sources":["../src/sharing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,KAAK,CAAC;AActC;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO3D;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAK9E;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAER;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIzF;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAMR"}
|
package/sharing.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-sharing helpers — the single source of truth for the hosted chat
|
|
3
|
+
* URL shape, the embed snippet, and client-side `allowed_origins`
|
|
4
|
+
* validation. Framework-free by design: consumed by the web console and
|
|
5
|
+
* desktop app (via `@stigmer/react`), the `stigmer` CLI, and any platform
|
|
6
|
+
* builder that wants to construct share links or embed snippets itself.
|
|
7
|
+
*
|
|
8
|
+
* The canonical URL shape is `<app-origin>/chat/<org>/<slug>` (a T01
|
|
9
|
+
* design decision), and `embed.js` is served from the root of that same
|
|
10
|
+
* app origin (T04). Callers supply the origin — resolving it is a host
|
|
11
|
+
* concern (the console knows its `appUrl`, the CLI resolves it from the
|
|
12
|
+
* backend type) — while the path and snippet shapes live here so every
|
|
13
|
+
* surface emits byte-identical output.
|
|
14
|
+
*/
|
|
15
|
+
/** Maximum number of allowed origins (proto: `repeated.max_items = 32`). */
|
|
16
|
+
export const MAX_ALLOWED_ORIGINS = 32;
|
|
17
|
+
/**
|
|
18
|
+
* Exact web origin: scheme://host[:port] — no path, query, fragment, or
|
|
19
|
+
* trailing slash. Mirrors the CEL expression `allowed_origins.format` on
|
|
20
|
+
* `AgentSharing` (`apis/ai/stigmer/agentic/agent/v1/spec.proto`).
|
|
21
|
+
*
|
|
22
|
+
* The proto is the source of truth — if the CEL expression changes, this
|
|
23
|
+
* pattern must change with it. Mirroring it client-side gives immediate
|
|
24
|
+
* feedback instead of a round-trip rejection.
|
|
25
|
+
*/
|
|
26
|
+
const ORIGIN_PATTERN = /^https?:\/\/[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)*(:[0-9]{1,5})?$/;
|
|
27
|
+
/**
|
|
28
|
+
* Validate a single `allowed_origins` entry.
|
|
29
|
+
*
|
|
30
|
+
* Returns `null` when valid, or a user-facing message explaining what
|
|
31
|
+
* to fix (DD-006: errors state what happened and what to do).
|
|
32
|
+
*/
|
|
33
|
+
export function validateOrigin(value) {
|
|
34
|
+
const trimmed = value.trim();
|
|
35
|
+
if (!trimmed)
|
|
36
|
+
return "Enter an origin, like https://example.com";
|
|
37
|
+
if (!ORIGIN_PATTERN.test(trimmed)) {
|
|
38
|
+
return "Must be an exact web origin like https://example.com — no path, query, or trailing slash";
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Query parameter carrying the share-link token on a locked link:
|
|
44
|
+
* `/chat/<org>/<slug>?k=<token>`. Short by design — the token rides every
|
|
45
|
+
* copied link, and `k` (for "key") is the platform's one-character
|
|
46
|
+
* convention, mirrored by the hosted page and the embed widget.
|
|
47
|
+
*/
|
|
48
|
+
export const LINK_TOKEN_PARAM = "k";
|
|
49
|
+
/**
|
|
50
|
+
* The hosted chat page path for a shared agent: `/chat/<org>/<slug>`,
|
|
51
|
+
* plus `?k=<token>` when the share link is locked with a rotatable token
|
|
52
|
+
* (`agent.status.shareLinkToken`).
|
|
53
|
+
*
|
|
54
|
+
* Useful on its own when the caller renders relative to the current
|
|
55
|
+
* origin (e.g. a host that never configured an absolute app URL).
|
|
56
|
+
*/
|
|
57
|
+
export function chatPath(org, slug, linkToken) {
|
|
58
|
+
const path = `/chat/${org}/${slug}`;
|
|
59
|
+
return linkToken
|
|
60
|
+
? `${path}?${LINK_TOKEN_PARAM}=${encodeURIComponent(linkToken)}`
|
|
61
|
+
: path;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The absolute hosted chat URL for a shared agent:
|
|
65
|
+
* `<appOrigin>/chat/<org>/<slug>[?k=<token>]`.
|
|
66
|
+
*
|
|
67
|
+
* A trailing slash on `appOrigin` is tolerated so callers can pass
|
|
68
|
+
* user-configured values verbatim. An empty `appOrigin` degrades to the
|
|
69
|
+
* relative {@link chatPath} — the same graceful fallback a host without a
|
|
70
|
+
* configured public origin gets in the share dialog.
|
|
71
|
+
*/
|
|
72
|
+
export function buildChatUrl(appOrigin, org, slug, linkToken) {
|
|
73
|
+
return stripTrailingSlash(appOrigin) + chatPath(org, slug, linkToken);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Append the share-link token to an already-built chat URL.
|
|
77
|
+
*
|
|
78
|
+
* For hosts that construct the base URL through their own callback (the
|
|
79
|
+
* share dialog's `buildShareUrl` prop) rather than {@link buildChatUrl}.
|
|
80
|
+
* A `null`/empty token returns the URL unchanged, so callers can pass
|
|
81
|
+
* `agent.status?.shareLinkToken` straight through. Emits the identical
|
|
82
|
+
* `?k=` shape as {@link chatPath} — one URL grammar across every surface.
|
|
83
|
+
*/
|
|
84
|
+
export function appendLinkToken(url, linkToken) {
|
|
85
|
+
if (!linkToken)
|
|
86
|
+
return url;
|
|
87
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
88
|
+
return `${url}${separator}${LINK_TOKEN_PARAM}=${encodeURIComponent(linkToken)}`;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The embed loader URL: `embed.js` lives at the root of the app origin
|
|
92
|
+
* (the loader derives the chat-page origin from its own script URL, so
|
|
93
|
+
* the two must share an origin). An empty `appOrigin` degrades to the
|
|
94
|
+
* relative `/embed.js`.
|
|
95
|
+
*/
|
|
96
|
+
export function buildEmbedLoaderUrl(appOrigin) {
|
|
97
|
+
return `${stripTrailingSlash(appOrigin)}/embed.js`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The two-line embed snippet an owner pastes into any website: the
|
|
101
|
+
* loader script plus the `<stigmer-agent>` element where the widget
|
|
102
|
+
* renders. A locked share link adds the `token` attribute, which the
|
|
103
|
+
* widget forwards as `?k=` on its iframe URL. Every surface (share
|
|
104
|
+
* dialog, CLI, docs) emits exactly this.
|
|
105
|
+
*/
|
|
106
|
+
export function buildEmbedSnippet(appOrigin, org, slug, linkToken) {
|
|
107
|
+
const tokenAttribute = linkToken ? ` token="${linkToken}"` : "";
|
|
108
|
+
return [
|
|
109
|
+
`<script src="${buildEmbedLoaderUrl(appOrigin)}" async></script>`,
|
|
110
|
+
`<stigmer-agent org="${org}" agent="${slug}"${tokenAttribute}></stigmer-agent>`,
|
|
111
|
+
].join("\n");
|
|
112
|
+
}
|
|
113
|
+
function stripTrailingSlash(origin) {
|
|
114
|
+
return origin.endsWith("/") ? origin.slice(0, -1) : origin;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=sharing.js.map
|
package/sharing.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharing.js","sourceRoot":"","sources":["../src/sharing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,cAAc,GAClB,8GAA8G,CAAC;AAEjH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO;QAAE,OAAO,2CAA2C,CAAC;IACjE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,0FAA0F,CAAC;IACpG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAEpC;;;;;;;GAOG;AAC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ChF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAc;IACxC,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC7D,CAAC"}
|
|
@@ -11,6 +11,62 @@ import {
|
|
|
11
11
|
type ErrorCategory,
|
|
12
12
|
} from "../errors";
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Guest launch-gate refusal contract (shared-agent abuse controls).
|
|
16
|
+
*
|
|
17
|
+
* The cloud backend resolves owner-customizable refusal copy server-side and
|
|
18
|
+
* carries it in the gRPC status description; the SDK must surface that copy
|
|
19
|
+
* VERBATIM through getUserMessage — no client-side mapping exists by design.
|
|
20
|
+
* These tests pin the two halves of that contract:
|
|
21
|
+
*
|
|
22
|
+
* 1. RESOURCE_EXHAUSTED / FAILED_PRECONDITION descriptions pass through
|
|
23
|
+
* getUserMessage untouched.
|
|
24
|
+
* 2. The platform-default copy (mirrors GuestLimitReason in the cloud
|
|
25
|
+
* backend) never collides with the sanitizer's rewrite patterns.
|
|
26
|
+
*/
|
|
27
|
+
describe("guest launch-gate refusal copy passthrough", () => {
|
|
28
|
+
// Mirrors GuestLimitReason default copy in the cloud stigmer-service.
|
|
29
|
+
// If those strings change, update here — this guardrail exists to catch a
|
|
30
|
+
// default that a sanitizer pattern would silently rewrite.
|
|
31
|
+
const platformDefaultCopy = [
|
|
32
|
+
"You\u2019re sending messages too quickly. Please wait a moment before sending another.",
|
|
33
|
+
"This agent is currently unavailable. Please check back later.",
|
|
34
|
+
"This conversation has ended. Please start a new conversation to continue.",
|
|
35
|
+
"This agent can\u2019t be embedded on this site.",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const refusalCodes: Array<[string, Code]> = [
|
|
39
|
+
["ResourceExhausted (rate limit)", Code.ResourceExhausted],
|
|
40
|
+
["FailedPrecondition (fail-closed / bounds)", Code.FailedPrecondition],
|
|
41
|
+
["PermissionDenied (embed origin)", Code.PermissionDenied],
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
it.each(refusalCodes)(
|
|
45
|
+
"surfaces a %s status description verbatim",
|
|
46
|
+
(_label, code) => {
|
|
47
|
+
for (const copy of platformDefaultCopy) {
|
|
48
|
+
expect(getUserMessage(new ConnectError(copy, code))).toBe(copy);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
it("surfaces owner-customized copy verbatim", () => {
|
|
54
|
+
const ownerCopy = "Whoa, slow down! Try again in a minute or two.";
|
|
55
|
+
expect(
|
|
56
|
+
getUserMessage(new ConnectError(ownerCopy, Code.ResourceExhausted)),
|
|
57
|
+
).toBe(ownerCopy);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("classifies rate-limit refusals as retryable and bounds refusals as not", () => {
|
|
61
|
+
expect(
|
|
62
|
+
isRetryableError(new ConnectError("copy", Code.ResourceExhausted)),
|
|
63
|
+
).toBe(true);
|
|
64
|
+
expect(
|
|
65
|
+
isRetryableError(new ConnectError("copy", Code.FailedPrecondition)),
|
|
66
|
+
).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
14
70
|
describe("classifyError", () => {
|
|
15
71
|
const stigmerMappings: Array<[string, ErrorCategory]> = [
|
|
16
72
|
["unauthenticated", "auth"],
|