@noodleseed/one 0.127.2 → 0.129.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/commands/assistant-embed-ops.d.ts.map +1 -1
- package/dist/commands/assistant-embed-ops.js +82 -9
- package/dist/commands/assistant-embed-ops.js.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.d.ts.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.js +6 -4
- package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.js.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/package.json +1 -1
- package/node_modules/@noodle-borg/assistant-gateway/dist/assistant-store.d.ts +9 -0
- package/node_modules/@noodle-borg/assistant-gateway/dist/assistant-store.d.ts.map +1 -1
- package/node_modules/@noodle-borg/assistant-gateway/dist/assistant-store.js +11 -0
- package/node_modules/@noodle-borg/assistant-gateway/dist/assistant-store.js.map +1 -1
- package/node_modules/@noodle-borg/assistant-gateway/dist/elevation.d.ts +13 -1
- package/node_modules/@noodle-borg/assistant-gateway/dist/elevation.d.ts.map +1 -1
- package/node_modules/@noodle-borg/assistant-gateway/dist/elevation.js +4 -3
- package/node_modules/@noodle-borg/assistant-gateway/dist/elevation.js.map +1 -1
- package/node_modules/@noodle-borg/assistant-gateway/dist/postgres-assistant.d.ts +3 -0
- package/node_modules/@noodle-borg/assistant-gateway/dist/postgres-assistant.d.ts.map +1 -1
- package/node_modules/@noodle-borg/assistant-gateway/dist/postgres-assistant.js +8 -1
- package/node_modules/@noodle-borg/assistant-gateway/dist/postgres-assistant.js.map +1 -1
- package/node_modules/@noodle-borg/assistant-gateway/package.json +1 -1
- package/node_modules/@noodle-borg/auth/dist/index.d.ts +1 -0
- package/node_modules/@noodle-borg/auth/dist/index.d.ts.map +1 -1
- package/node_modules/@noodle-borg/auth/dist/index.js +1 -0
- package/node_modules/@noodle-borg/auth/dist/index.js.map +1 -1
- package/node_modules/@noodle-borg/auth/dist/oauth-client-redirect-policy.d.ts +34 -0
- package/node_modules/@noodle-borg/auth/dist/oauth-client-redirect-policy.d.ts.map +1 -0
- package/node_modules/@noodle-borg/auth/dist/oauth-client-redirect-policy.js +230 -0
- package/node_modules/@noodle-borg/auth/dist/oauth-client-redirect-policy.js.map +1 -0
- package/node_modules/@noodle-borg/cli-catalog/dist/catalog-data-assistant.d.ts.map +1 -1
- package/node_modules/@noodle-borg/cli-catalog/dist/catalog-data-assistant.js +16 -0
- package/node_modules/@noodle-borg/cli-catalog/dist/catalog-data-assistant.js.map +1 -1
- package/node_modules/@noodle-borg/connector-defs/dist/delegated-token-exchange-identity.js +16 -1
- package/node_modules/@noodle-borg/connector-defs/dist/delegated-token-exchange-identity.js.map +1 -1
- package/node_modules/@noodle-borg/oauth-client-registry/dist/authorization-handler.d.ts +17 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/authorization-handler.d.ts.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/authorization-handler.js +118 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/authorization-handler.js.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/client-registration-handler.d.ts +18 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/client-registration-handler.d.ts.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/client-registration-handler.js +130 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/client-registration-handler.js.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/index.d.ts +5 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/index.d.ts.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/index.js +5 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/index.js.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/legacy-inventory.d.ts +54 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/legacy-inventory.d.ts.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/legacy-inventory.js +256 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/legacy-inventory.js.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/legacy-redirect-rollout.d.ts +7 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/legacy-redirect-rollout.d.ts.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/legacy-redirect-rollout.js +6 -0
- package/node_modules/@noodle-borg/oauth-client-registry/dist/legacy-redirect-rollout.js.map +1 -0
- package/node_modules/@noodle-borg/oauth-client-registry/package.json +36 -0
- package/node_modules/@noodle-borg/service/dist/assistant-delegated-projection.d.ts +12 -0
- package/node_modules/@noodle-borg/service/dist/assistant-delegated-projection.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/assistant-delegated-projection.js +68 -0
- package/node_modules/@noodle-borg/service/dist/assistant-delegated-projection.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/credential-broker.d.ts +6 -0
- package/node_modules/@noodle-borg/service/dist/credential-broker.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/credential-broker.js +9 -0
- package/node_modules/@noodle-borg/service/dist/credential-broker.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/app.d.ts +2 -1
- package/node_modules/@noodle-borg/service/dist/oauth/app.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/app.js +3 -21
- package/node_modules/@noodle-borg/service/dist/oauth/app.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/service-bootstrap.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/oauth/service-bootstrap.js +1 -0
- package/node_modules/@noodle-borg/service/dist/oauth/service-bootstrap.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/registry-compile.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/registry-compile.js +8 -0
- package/node_modules/@noodle-borg/service/dist/registry-compile.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.js +26 -7
- package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/assistant-dispatch.js +2 -1
- package/node_modules/@noodle-borg/service/dist/routes/assistant-dispatch.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/assistant-doctor.d.ts +10 -0
- package/node_modules/@noodle-borg/service/dist/routes/assistant-doctor.d.ts.map +1 -0
- package/node_modules/@noodle-borg/service/dist/routes/assistant-doctor.js +164 -0
- package/node_modules/@noodle-borg/service/dist/routes/assistant-doctor.js.map +1 -0
- package/node_modules/@noodle-borg/service/dist/routes/assistant-elevation.d.ts +21 -3
- package/node_modules/@noodle-borg/service/dist/routes/assistant-elevation.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/assistant-elevation.js +45 -7
- package/node_modules/@noodle-borg/service/dist/routes/assistant-elevation.js.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/assistant.d.ts +0 -2
- package/node_modules/@noodle-borg/service/dist/routes/assistant.d.ts.map +1 -1
- package/node_modules/@noodle-borg/service/dist/routes/assistant.js +7 -88
- package/node_modules/@noodle-borg/service/dist/routes/assistant.js.map +1 -1
- package/node_modules/@noodle-borg/service/package.json +2 -1
- package/node_modules/@noodleseed/assistant/README.md +68 -0
- package/node_modules/@noodleseed/assistant/dist/{chunk-S373FCAI.js → chunk-52XT7BLR.js} +9 -4
- package/node_modules/@noodleseed/assistant/dist/{chunk-S373FCAI.js.map → chunk-52XT7BLR.js.map} +1 -1
- package/node_modules/@noodleseed/assistant/dist/{chunk-RFETV5KQ.js → chunk-DLUINP4W.js} +9 -9
- package/node_modules/@noodleseed/assistant/dist/{chunk-RFETV5KQ.js.map → chunk-DLUINP4W.js.map} +1 -1
- package/node_modules/@noodleseed/assistant/dist/{client-BQ30Fq-c.d.cts → client-7o7n2nqw.d.cts} +6 -4
- package/node_modules/@noodleseed/assistant/dist/{client-B6pnBmF8.d.ts → client-CysBQBdd.d.ts} +6 -4
- package/node_modules/@noodleseed/assistant/dist/client.cjs +8 -3
- package/node_modules/@noodleseed/assistant/dist/client.cjs.map +1 -1
- package/node_modules/@noodleseed/assistant/dist/client.d.cts +1 -1
- package/node_modules/@noodleseed/assistant/dist/client.d.ts +1 -1
- package/node_modules/@noodleseed/assistant/dist/client.js +1 -1
- package/node_modules/@noodleseed/assistant/dist/embed.global.js +4 -4
- package/node_modules/@noodleseed/assistant/dist/index.cjs +15 -10
- package/node_modules/@noodleseed/assistant/dist/index.cjs.map +1 -1
- package/node_modules/@noodleseed/assistant/dist/index.d.cts +2 -2
- package/node_modules/@noodleseed/assistant/dist/index.d.ts +2 -2
- package/node_modules/@noodleseed/assistant/dist/index.js +2 -2
- package/node_modules/@noodleseed/assistant/dist/react/client.cjs +8 -3
- package/node_modules/@noodleseed/assistant/dist/react/client.cjs.map +1 -1
- package/node_modules/@noodleseed/assistant/dist/react/client.d.cts +1 -1
- package/node_modules/@noodleseed/assistant/dist/react/client.d.ts +1 -1
- package/node_modules/@noodleseed/assistant/dist/react/client.js +1 -1
- package/node_modules/@noodleseed/assistant/dist/react.cjs +15 -10
- package/node_modules/@noodleseed/assistant/dist/react.cjs.map +1 -1
- package/node_modules/@noodleseed/assistant/dist/react.d.cts +1 -1
- package/node_modules/@noodleseed/assistant/dist/react.d.ts +1 -1
- package/node_modules/@noodleseed/assistant/dist/react.js +2 -2
- package/node_modules/@noodleseed/assistant/dist/server.cjs +47 -1
- package/node_modules/@noodleseed/assistant/dist/server.cjs.map +1 -1
- package/node_modules/@noodleseed/assistant/dist/server.d.cts +60 -7
- package/node_modules/@noodleseed/assistant/dist/server.d.ts +60 -7
- package/node_modules/@noodleseed/assistant/dist/server.js +45 -1
- package/node_modules/@noodleseed/assistant/dist/server.js.map +1 -1
- package/node_modules/@noodleseed/assistant/package.json +1 -1
- package/package.json +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactElement, RefAttributes } from 'react';
|
|
2
2
|
import { a as AssistantThemeMode } from './appearance-Cc-eqSbp.cjs';
|
|
3
3
|
import { AssistantAppearance, AssistantAppearanceWarning, NoodleAssistantElement } from './index.cjs';
|
|
4
|
-
import { c as AssistantClient, d as AssistantViewAvailableDetail, A as AssistantPageContext, a as AssistantContext, e as AssistantModelContextUpdate, f as AssistantClientEvent, g as AssistantErrorDetail } from './client-
|
|
4
|
+
import { c as AssistantClient, d as AssistantViewAvailableDetail, A as AssistantPageContext, a as AssistantContext, e as AssistantModelContextUpdate, f as AssistantClientEvent, g as AssistantErrorDetail } from './client-7o7n2nqw.cjs';
|
|
5
5
|
import 'ai';
|
|
6
6
|
|
|
7
7
|
interface NoodleAppViewProps {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactElement, RefAttributes } from 'react';
|
|
2
2
|
import { a as AssistantThemeMode } from './appearance-Cc-eqSbp.js';
|
|
3
3
|
import { AssistantAppearance, AssistantAppearanceWarning, NoodleAssistantElement } from './index.js';
|
|
4
|
-
import { c as AssistantClient, d as AssistantViewAvailableDetail, A as AssistantPageContext, a as AssistantContext, e as AssistantModelContextUpdate, f as AssistantClientEvent, g as AssistantErrorDetail } from './client-
|
|
4
|
+
import { c as AssistantClient, d as AssistantViewAvailableDetail, A as AssistantPageContext, a as AssistantContext, e as AssistantModelContextUpdate, f as AssistantClientEvent, g as AssistantErrorDetail } from './client-CysBQBdd.js';
|
|
5
5
|
import 'ai';
|
|
6
6
|
|
|
7
7
|
interface NoodleAppViewProps {
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
registerNoodleAssistant,
|
|
4
4
|
unmountAssistantApp,
|
|
5
5
|
updateAssistantAppTheme
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-DLUINP4W.js";
|
|
7
|
+
import "./chunk-52XT7BLR.js";
|
|
8
8
|
import "./chunk-3YYTUJPJ.js";
|
|
9
9
|
import "./chunk-5FUTL2UF.js";
|
|
10
10
|
|
|
@@ -20,10 +20,53 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/server.ts
|
|
21
21
|
var server_exports = {};
|
|
22
22
|
__export(server_exports, {
|
|
23
|
+
ASSISTANT_ELEVATION_REFUSAL_CODES: () => ASSISTANT_ELEVATION_REFUSAL_CODES,
|
|
24
|
+
AssistantSessionExchangeError: () => AssistantSessionExchangeError,
|
|
23
25
|
createAssistantSession: () => createAssistantSession
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(server_exports);
|
|
28
|
+
var ASSISTANT_ELEVATION_REFUSAL_CODES = [
|
|
29
|
+
"elevation_ticket_invalid",
|
|
30
|
+
"elevation_ticket_expired",
|
|
31
|
+
"elevation_tenant_mismatch",
|
|
32
|
+
"elevation_session_unavailable",
|
|
33
|
+
"elevation_already_signed_in"
|
|
34
|
+
];
|
|
35
|
+
var AssistantSessionExchangeError = class extends Error {
|
|
36
|
+
detail;
|
|
37
|
+
constructor(detail, message) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = "AssistantSessionExchangeError";
|
|
40
|
+
this.detail = detail;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The narrowed sign-in refusal, when this failure is one. `elevation_ticket_expired` means the
|
|
44
|
+
* visitor took too long — re-prompt; `elevation_tenant_mismatch` means a client reached for a
|
|
45
|
+
* conversation it does not own — alert someone, never retry.
|
|
46
|
+
*/
|
|
47
|
+
get elevationRefusal() {
|
|
48
|
+
const code = this.detail.serviceCode;
|
|
49
|
+
return code !== void 0 && ASSISTANT_ELEVATION_REFUSAL_CODES.includes(code) ? code : void 0;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
async function exchangeError(response) {
|
|
53
|
+
const body = await response.json().catch(() => void 0);
|
|
54
|
+
const serviceCode = typeof body?.code === "string" ? body.code : void 0;
|
|
55
|
+
return new AssistantSessionExchangeError(
|
|
56
|
+
{
|
|
57
|
+
code: "session_exchange_failed",
|
|
58
|
+
status: response.status,
|
|
59
|
+
// `elevation_unavailable` is a 503 an operator has to fix; retrying cannot help.
|
|
60
|
+
retryable: response.status >= 500 && serviceCode !== "elevation_unavailable",
|
|
61
|
+
...serviceCode === void 0 ? {} : { serviceCode }
|
|
62
|
+
},
|
|
63
|
+
`Assistant session exchange failed (${response.status})`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
26
66
|
async function createAssistantSession(input, dependencies = {}) {
|
|
67
|
+
if (input.signInTicket !== void 0 && input.context !== void 0) {
|
|
68
|
+
throw new Error("context does not apply when spending a sign-in ticket");
|
|
69
|
+
}
|
|
27
70
|
const request = dependencies.fetch ?? fetch;
|
|
28
71
|
const serviceUrl = input.serviceUrl.replace(/\/$/, "");
|
|
29
72
|
const credentials = Buffer.from(`${input.clientId}:${input.clientSecret}`, "utf8").toString(
|
|
@@ -39,17 +82,20 @@ async function createAssistantSession(input, dependencies = {}) {
|
|
|
39
82
|
body: JSON.stringify({
|
|
40
83
|
origin: input.origin,
|
|
41
84
|
user: input.user,
|
|
85
|
+
...input.signInTicket === void 0 ? {} : { signInTicket: input.signInTicket },
|
|
42
86
|
...input.claims ? { claims: input.claims } : {},
|
|
43
87
|
...input.context ? { context: input.context } : {},
|
|
44
88
|
...input.preferences ? { preferences: input.preferences } : {},
|
|
45
89
|
...input.routing ? { routing: input.routing } : {}
|
|
46
90
|
})
|
|
47
91
|
});
|
|
48
|
-
if (!response.ok) throw
|
|
92
|
+
if (!response.ok) throw await exchangeError(response);
|
|
49
93
|
return await response.json();
|
|
50
94
|
}
|
|
51
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
96
|
0 && (module.exports = {
|
|
97
|
+
ASSISTANT_ELEVATION_REFUSAL_CODES,
|
|
98
|
+
AssistantSessionExchangeError,
|
|
53
99
|
createAssistantSession
|
|
54
100
|
});
|
|
55
101
|
//# sourceMappingURL=server.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import type { AssistantConfiguration } from './appearance.js';\n\
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import type { AssistantConfiguration } from './appearance.js';\n\ninterface AssistantSessionExchangeBase {\n readonly serviceUrl: string;\n readonly clientId: string;\n readonly clientSecret: string;\n /** Browser origin to bind into the short-lived assistant session. */\n readonly origin: string;\n /** The signed-in person your backend vouches for — on both arms: an elevation IS this vouching. */\n readonly user: {\n readonly id: string;\n readonly email?: string;\n readonly name?: string;\n readonly tenant?: string;\n readonly roles?: readonly string[];\n readonly scopes?: readonly string[];\n };\n /** Backend-verified user preferences; these outrank untrusted browser presentation hints. */\n readonly preferences?: {\n readonly locale?: string;\n readonly timeZone?: string;\n };\n /**\n * Verified session claims from your authenticated backend. Only claims the server declares in\n * `embeddedAssistant({ sessionClaims })` reach tools (`\\${user.claims.<key>}`) and, when marked\n * `exposeToModel`, the assistant's identity context. Flat scalars only.\n */\n readonly claims?: Readonly<Record<string, string | number | boolean | null>>;\n}\n\n/**\n * Fresh mint XOR mid-conversation sign-in, exclusive rather than merged for the same reason the\n * client's `sessionEndpoint`/`embedId` pair is: the two are different operations, and the wrong\n * combination should fail to typecheck instead of silently picking a meaning.\n *\n * `context` applies only when a session is being created; an elevation keeps the existing\n * conversation, so it is excluded rather than silently ignored. `routing` is allowed on both arms —\n * elevation is the first authenticated moment, so it is the only chance a routed connector's\n * session ever gets its backend-verified customer routes.\n */\nexport type CreateAssistantSessionInput =\n | (AssistantSessionExchangeBase & {\n readonly signInTicket?: undefined;\n readonly context?: Readonly<Record<string, string | number | boolean | null>>;\n /** Backend-verified connector routes keyed by authored `customerEndpoint` name. */\n readonly routing?: {\n readonly endpoints: Readonly<Record<string, string>>;\n };\n })\n | (AssistantSessionExchangeBase & {\n /**\n * Single-use sign-in ticket from the widget's `assistant-sign-in-requested` event\n * (ADR 0201, 5.6b). Spending it binds this signed-in user to the visitor's existing\n * anonymous conversation instead of minting a new one. Unrelated to the server-held\n * interaction continuation, which never reaches browser code.\n */\n readonly signInTicket: string;\n readonly context?: undefined;\n /** Backend-verified connector routes keyed by authored `customerEndpoint` name. */\n readonly routing?: {\n readonly endpoints: Readonly<Record<string, string>>;\n };\n });\n\nexport interface AssistantSession {\n readonly token: string;\n readonly expiresAt: string;\n readonly endpoints: {\n readonly turns: string;\n readonly toolConfirmations: string;\n readonly interactions?: string;\n readonly apps?: string;\n /** Additive hosted sandbox document for widget frames; absent on older services. */\n readonly sandbox?: string;\n };\n readonly configuration?: AssistantConfiguration;\n}\n\n/** The service's refusal codes for a sign-in ticket the exchange would not honour. */\nexport const ASSISTANT_ELEVATION_REFUSAL_CODES = [\n 'elevation_ticket_invalid',\n 'elevation_ticket_expired',\n 'elevation_tenant_mismatch',\n 'elevation_session_unavailable',\n 'elevation_already_signed_in',\n] as const;\nexport type AssistantElevationRefusalCode = (typeof ASSISTANT_ELEVATION_REFUSAL_CODES)[number];\n\n/**\n * Structurally mirrors the browser client's `AssistantErrorDetail` (declared locally: the backend\n * entry must not pull the browser transport module into its graph). `code` is a closed union owned\n * by this package; `serviceCode` passes the service's machine code through additively.\n */\nexport interface AssistantSessionExchangeErrorDetail {\n readonly code: 'session_exchange_failed';\n readonly status: number;\n /** 5xx infrastructure failures may be retried; a refused exchange must not be — tickets are single-use. */\n readonly retryable: boolean;\n /** The service's machine code when the body carried one, e.g. `elevation_ticket_expired`. */\n readonly serviceCode?: string;\n}\n\nexport class AssistantSessionExchangeError extends Error {\n readonly detail: AssistantSessionExchangeErrorDetail;\n\n constructor(detail: AssistantSessionExchangeErrorDetail, message: string) {\n super(message);\n this.name = 'AssistantSessionExchangeError';\n this.detail = detail;\n }\n\n /**\n * The narrowed sign-in refusal, when this failure is one. `elevation_ticket_expired` means the\n * visitor took too long — re-prompt; `elevation_tenant_mismatch` means a client reached for a\n * conversation it does not own — alert someone, never retry.\n */\n get elevationRefusal(): AssistantElevationRefusalCode | undefined {\n const code = this.detail.serviceCode;\n return code !== undefined &&\n (ASSISTANT_ELEVATION_REFUSAL_CODES as readonly string[]).includes(code)\n ? (code as AssistantElevationRefusalCode)\n : undefined;\n }\n}\n\n/** Never throws while reading the body — a proxy can answer with HTML instead of JSON. */\nasync function exchangeError(response: Response): Promise<AssistantSessionExchangeError> {\n const body = (await response.json().catch(() => undefined)) as\n | { readonly error?: unknown; readonly code?: unknown }\n | undefined;\n const serviceCode = typeof body?.code === 'string' ? body.code : undefined;\n return new AssistantSessionExchangeError(\n {\n code: 'session_exchange_failed',\n status: response.status,\n // `elevation_unavailable` is a 503 an operator has to fix; retrying cannot help.\n retryable: response.status >= 500 && serviceCode !== 'elevation_unavailable',\n ...(serviceCode === undefined ? {} : { serviceCode }),\n },\n `Assistant session exchange failed (${response.status})`,\n );\n}\n\nexport async function createAssistantSession(\n input: CreateAssistantSessionInput,\n dependencies: { readonly fetch?: typeof fetch } = {},\n): Promise<AssistantSession> {\n if (input.signInTicket !== undefined && (input as { context?: unknown }).context !== undefined) {\n // Mirrors resolveSessionSource: silently dropping what the service ignores would pick a\n // meaning the developer did not intend.\n throw new Error('context does not apply when spending a sign-in ticket');\n }\n const request = dependencies.fetch ?? fetch;\n const serviceUrl = input.serviceUrl.replace(/\\/$/, '');\n const credentials = Buffer.from(`${input.clientId}:${input.clientSecret}`, 'utf8').toString(\n 'base64',\n );\n const response = await request(`${serviceUrl}/v1/assistant/sessions`, {\n method: 'POST',\n headers: {\n Authorization: `Basic ${credentials}`,\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n origin: input.origin,\n user: input.user,\n ...(input.signInTicket === undefined ? {} : { signInTicket: input.signInTicket }),\n ...(input.claims ? { claims: input.claims } : {}),\n ...(input.context ? { context: input.context } : {}),\n ...(input.preferences ? { preferences: input.preferences } : {}),\n ...(input.routing ? { routing: input.routing } : {}),\n }),\n });\n // A fresh mint answers 201, an elevation 200; both are the same wire shape (ADR 0151).\n if (!response.ok) throw await exchangeError(response);\n return (await response.json()) as AssistantSession;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+EO,IAAM,oCAAoC;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAiBO,IAAM,gCAAN,cAA4C,MAAM;AAAA,EAC9C;AAAA,EAET,YAAY,QAA6C,SAAiB;AACxE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,mBAA8D;AAChE,UAAM,OAAO,KAAK,OAAO;AACzB,WAAO,SAAS,UACb,kCAAwD,SAAS,IAAI,IACnE,OACD;AAAA,EACN;AACF;AAGA,eAAe,cAAc,UAA4D;AACvF,QAAM,OAAQ,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,MAAS;AAGzD,QAAM,cAAc,OAAO,MAAM,SAAS,WAAW,KAAK,OAAO;AACjE,SAAO,IAAI;AAAA,IACT;AAAA,MACE,MAAM;AAAA,MACN,QAAQ,SAAS;AAAA;AAAA,MAEjB,WAAW,SAAS,UAAU,OAAO,gBAAgB;AAAA,MACrD,GAAI,gBAAgB,SAAY,CAAC,IAAI,EAAE,YAAY;AAAA,IACrD;AAAA,IACA,sCAAsC,SAAS,MAAM;AAAA,EACvD;AACF;AAEA,eAAsB,uBACpB,OACA,eAAkD,CAAC,GACxB;AAC3B,MAAI,MAAM,iBAAiB,UAAc,MAAgC,YAAY,QAAW;AAG9F,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,QAAM,UAAU,aAAa,SAAS;AACtC,QAAM,aAAa,MAAM,WAAW,QAAQ,OAAO,EAAE;AACrD,QAAM,cAAc,OAAO,KAAK,GAAG,MAAM,QAAQ,IAAI,MAAM,YAAY,IAAI,MAAM,EAAE;AAAA,IACjF;AAAA,EACF;AACA,QAAM,WAAW,MAAM,QAAQ,GAAG,UAAU,0BAA0B;AAAA,IACpE,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,eAAe,SAAS,WAAW;AAAA,MACnC,QAAQ;AAAA,MACR,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAU;AAAA,MACnB,QAAQ,MAAM;AAAA,MACd,MAAM,MAAM;AAAA,MACZ,GAAI,MAAM,iBAAiB,SAAY,CAAC,IAAI,EAAE,cAAc,MAAM,aAAa;AAAA,MAC/E,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;AAAA,MAC/C,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,MAClD,GAAI,MAAM,cAAc,EAAE,aAAa,MAAM,YAAY,IAAI,CAAC;AAAA,MAC9D,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,IACpD,CAAC;AAAA,EACH,CAAC;AAED,MAAI,CAAC,SAAS,GAAI,OAAM,MAAM,cAAc,QAAQ;AACpD,SAAQ,MAAM,SAAS,KAAK;AAC9B;","names":[]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { A as AssistantConfiguration } from './appearance-Cc-eqSbp.cjs';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface AssistantSessionExchangeBase {
|
|
4
4
|
readonly serviceUrl: string;
|
|
5
5
|
readonly clientId: string;
|
|
6
6
|
readonly clientSecret: string;
|
|
7
7
|
/** Browser origin to bind into the short-lived assistant session. */
|
|
8
8
|
readonly origin: string;
|
|
9
|
+
/** The signed-in person your backend vouches for — on both arms: an elevation IS this vouching. */
|
|
9
10
|
readonly user: {
|
|
10
11
|
readonly id: string;
|
|
11
12
|
readonly email?: string;
|
|
@@ -14,16 +15,11 @@ interface CreateAssistantSessionInput {
|
|
|
14
15
|
readonly roles?: readonly string[];
|
|
15
16
|
readonly scopes?: readonly string[];
|
|
16
17
|
};
|
|
17
|
-
readonly context?: Readonly<Record<string, string | number | boolean | null>>;
|
|
18
18
|
/** Backend-verified user preferences; these outrank untrusted browser presentation hints. */
|
|
19
19
|
readonly preferences?: {
|
|
20
20
|
readonly locale?: string;
|
|
21
21
|
readonly timeZone?: string;
|
|
22
22
|
};
|
|
23
|
-
/** Backend-verified connector routes keyed by authored `customerEndpoint` name. */
|
|
24
|
-
readonly routing?: {
|
|
25
|
-
readonly endpoints: Readonly<Record<string, string>>;
|
|
26
|
-
};
|
|
27
23
|
/**
|
|
28
24
|
* Verified session claims from your authenticated backend. Only claims the server declares in
|
|
29
25
|
* `embeddedAssistant({ sessionClaims })` reach tools (`\${user.claims.<key>}`) and, when marked
|
|
@@ -31,6 +27,37 @@ interface CreateAssistantSessionInput {
|
|
|
31
27
|
*/
|
|
32
28
|
readonly claims?: Readonly<Record<string, string | number | boolean | null>>;
|
|
33
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Fresh mint XOR mid-conversation sign-in, exclusive rather than merged for the same reason the
|
|
32
|
+
* client's `sessionEndpoint`/`embedId` pair is: the two are different operations, and the wrong
|
|
33
|
+
* combination should fail to typecheck instead of silently picking a meaning.
|
|
34
|
+
*
|
|
35
|
+
* `context` applies only when a session is being created; an elevation keeps the existing
|
|
36
|
+
* conversation, so it is excluded rather than silently ignored. `routing` is allowed on both arms —
|
|
37
|
+
* elevation is the first authenticated moment, so it is the only chance a routed connector's
|
|
38
|
+
* session ever gets its backend-verified customer routes.
|
|
39
|
+
*/
|
|
40
|
+
type CreateAssistantSessionInput = (AssistantSessionExchangeBase & {
|
|
41
|
+
readonly signInTicket?: undefined;
|
|
42
|
+
readonly context?: Readonly<Record<string, string | number | boolean | null>>;
|
|
43
|
+
/** Backend-verified connector routes keyed by authored `customerEndpoint` name. */
|
|
44
|
+
readonly routing?: {
|
|
45
|
+
readonly endpoints: Readonly<Record<string, string>>;
|
|
46
|
+
};
|
|
47
|
+
}) | (AssistantSessionExchangeBase & {
|
|
48
|
+
/**
|
|
49
|
+
* Single-use sign-in ticket from the widget's `assistant-sign-in-requested` event
|
|
50
|
+
* (ADR 0201, 5.6b). Spending it binds this signed-in user to the visitor's existing
|
|
51
|
+
* anonymous conversation instead of minting a new one. Unrelated to the server-held
|
|
52
|
+
* interaction continuation, which never reaches browser code.
|
|
53
|
+
*/
|
|
54
|
+
readonly signInTicket: string;
|
|
55
|
+
readonly context?: undefined;
|
|
56
|
+
/** Backend-verified connector routes keyed by authored `customerEndpoint` name. */
|
|
57
|
+
readonly routing?: {
|
|
58
|
+
readonly endpoints: Readonly<Record<string, string>>;
|
|
59
|
+
};
|
|
60
|
+
});
|
|
34
61
|
interface AssistantSession {
|
|
35
62
|
readonly token: string;
|
|
36
63
|
readonly expiresAt: string;
|
|
@@ -44,8 +71,34 @@ interface AssistantSession {
|
|
|
44
71
|
};
|
|
45
72
|
readonly configuration?: AssistantConfiguration;
|
|
46
73
|
}
|
|
74
|
+
/** The service's refusal codes for a sign-in ticket the exchange would not honour. */
|
|
75
|
+
declare const ASSISTANT_ELEVATION_REFUSAL_CODES: readonly ["elevation_ticket_invalid", "elevation_ticket_expired", "elevation_tenant_mismatch", "elevation_session_unavailable", "elevation_already_signed_in"];
|
|
76
|
+
type AssistantElevationRefusalCode = (typeof ASSISTANT_ELEVATION_REFUSAL_CODES)[number];
|
|
77
|
+
/**
|
|
78
|
+
* Structurally mirrors the browser client's `AssistantErrorDetail` (declared locally: the backend
|
|
79
|
+
* entry must not pull the browser transport module into its graph). `code` is a closed union owned
|
|
80
|
+
* by this package; `serviceCode` passes the service's machine code through additively.
|
|
81
|
+
*/
|
|
82
|
+
interface AssistantSessionExchangeErrorDetail {
|
|
83
|
+
readonly code: 'session_exchange_failed';
|
|
84
|
+
readonly status: number;
|
|
85
|
+
/** 5xx infrastructure failures may be retried; a refused exchange must not be — tickets are single-use. */
|
|
86
|
+
readonly retryable: boolean;
|
|
87
|
+
/** The service's machine code when the body carried one, e.g. `elevation_ticket_expired`. */
|
|
88
|
+
readonly serviceCode?: string;
|
|
89
|
+
}
|
|
90
|
+
declare class AssistantSessionExchangeError extends Error {
|
|
91
|
+
readonly detail: AssistantSessionExchangeErrorDetail;
|
|
92
|
+
constructor(detail: AssistantSessionExchangeErrorDetail, message: string);
|
|
93
|
+
/**
|
|
94
|
+
* The narrowed sign-in refusal, when this failure is one. `elevation_ticket_expired` means the
|
|
95
|
+
* visitor took too long — re-prompt; `elevation_tenant_mismatch` means a client reached for a
|
|
96
|
+
* conversation it does not own — alert someone, never retry.
|
|
97
|
+
*/
|
|
98
|
+
get elevationRefusal(): AssistantElevationRefusalCode | undefined;
|
|
99
|
+
}
|
|
47
100
|
declare function createAssistantSession(input: CreateAssistantSessionInput, dependencies?: {
|
|
48
101
|
readonly fetch?: typeof fetch;
|
|
49
102
|
}): Promise<AssistantSession>;
|
|
50
103
|
|
|
51
|
-
export { type AssistantSession, type CreateAssistantSessionInput, createAssistantSession };
|
|
104
|
+
export { ASSISTANT_ELEVATION_REFUSAL_CODES, type AssistantElevationRefusalCode, type AssistantSession, AssistantSessionExchangeError, type AssistantSessionExchangeErrorDetail, type CreateAssistantSessionInput, createAssistantSession };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { A as AssistantConfiguration } from './appearance-Cc-eqSbp.js';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface AssistantSessionExchangeBase {
|
|
4
4
|
readonly serviceUrl: string;
|
|
5
5
|
readonly clientId: string;
|
|
6
6
|
readonly clientSecret: string;
|
|
7
7
|
/** Browser origin to bind into the short-lived assistant session. */
|
|
8
8
|
readonly origin: string;
|
|
9
|
+
/** The signed-in person your backend vouches for — on both arms: an elevation IS this vouching. */
|
|
9
10
|
readonly user: {
|
|
10
11
|
readonly id: string;
|
|
11
12
|
readonly email?: string;
|
|
@@ -14,16 +15,11 @@ interface CreateAssistantSessionInput {
|
|
|
14
15
|
readonly roles?: readonly string[];
|
|
15
16
|
readonly scopes?: readonly string[];
|
|
16
17
|
};
|
|
17
|
-
readonly context?: Readonly<Record<string, string | number | boolean | null>>;
|
|
18
18
|
/** Backend-verified user preferences; these outrank untrusted browser presentation hints. */
|
|
19
19
|
readonly preferences?: {
|
|
20
20
|
readonly locale?: string;
|
|
21
21
|
readonly timeZone?: string;
|
|
22
22
|
};
|
|
23
|
-
/** Backend-verified connector routes keyed by authored `customerEndpoint` name. */
|
|
24
|
-
readonly routing?: {
|
|
25
|
-
readonly endpoints: Readonly<Record<string, string>>;
|
|
26
|
-
};
|
|
27
23
|
/**
|
|
28
24
|
* Verified session claims from your authenticated backend. Only claims the server declares in
|
|
29
25
|
* `embeddedAssistant({ sessionClaims })` reach tools (`\${user.claims.<key>}`) and, when marked
|
|
@@ -31,6 +27,37 @@ interface CreateAssistantSessionInput {
|
|
|
31
27
|
*/
|
|
32
28
|
readonly claims?: Readonly<Record<string, string | number | boolean | null>>;
|
|
33
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Fresh mint XOR mid-conversation sign-in, exclusive rather than merged for the same reason the
|
|
32
|
+
* client's `sessionEndpoint`/`embedId` pair is: the two are different operations, and the wrong
|
|
33
|
+
* combination should fail to typecheck instead of silently picking a meaning.
|
|
34
|
+
*
|
|
35
|
+
* `context` applies only when a session is being created; an elevation keeps the existing
|
|
36
|
+
* conversation, so it is excluded rather than silently ignored. `routing` is allowed on both arms —
|
|
37
|
+
* elevation is the first authenticated moment, so it is the only chance a routed connector's
|
|
38
|
+
* session ever gets its backend-verified customer routes.
|
|
39
|
+
*/
|
|
40
|
+
type CreateAssistantSessionInput = (AssistantSessionExchangeBase & {
|
|
41
|
+
readonly signInTicket?: undefined;
|
|
42
|
+
readonly context?: Readonly<Record<string, string | number | boolean | null>>;
|
|
43
|
+
/** Backend-verified connector routes keyed by authored `customerEndpoint` name. */
|
|
44
|
+
readonly routing?: {
|
|
45
|
+
readonly endpoints: Readonly<Record<string, string>>;
|
|
46
|
+
};
|
|
47
|
+
}) | (AssistantSessionExchangeBase & {
|
|
48
|
+
/**
|
|
49
|
+
* Single-use sign-in ticket from the widget's `assistant-sign-in-requested` event
|
|
50
|
+
* (ADR 0201, 5.6b). Spending it binds this signed-in user to the visitor's existing
|
|
51
|
+
* anonymous conversation instead of minting a new one. Unrelated to the server-held
|
|
52
|
+
* interaction continuation, which never reaches browser code.
|
|
53
|
+
*/
|
|
54
|
+
readonly signInTicket: string;
|
|
55
|
+
readonly context?: undefined;
|
|
56
|
+
/** Backend-verified connector routes keyed by authored `customerEndpoint` name. */
|
|
57
|
+
readonly routing?: {
|
|
58
|
+
readonly endpoints: Readonly<Record<string, string>>;
|
|
59
|
+
};
|
|
60
|
+
});
|
|
34
61
|
interface AssistantSession {
|
|
35
62
|
readonly token: string;
|
|
36
63
|
readonly expiresAt: string;
|
|
@@ -44,8 +71,34 @@ interface AssistantSession {
|
|
|
44
71
|
};
|
|
45
72
|
readonly configuration?: AssistantConfiguration;
|
|
46
73
|
}
|
|
74
|
+
/** The service's refusal codes for a sign-in ticket the exchange would not honour. */
|
|
75
|
+
declare const ASSISTANT_ELEVATION_REFUSAL_CODES: readonly ["elevation_ticket_invalid", "elevation_ticket_expired", "elevation_tenant_mismatch", "elevation_session_unavailable", "elevation_already_signed_in"];
|
|
76
|
+
type AssistantElevationRefusalCode = (typeof ASSISTANT_ELEVATION_REFUSAL_CODES)[number];
|
|
77
|
+
/**
|
|
78
|
+
* Structurally mirrors the browser client's `AssistantErrorDetail` (declared locally: the backend
|
|
79
|
+
* entry must not pull the browser transport module into its graph). `code` is a closed union owned
|
|
80
|
+
* by this package; `serviceCode` passes the service's machine code through additively.
|
|
81
|
+
*/
|
|
82
|
+
interface AssistantSessionExchangeErrorDetail {
|
|
83
|
+
readonly code: 'session_exchange_failed';
|
|
84
|
+
readonly status: number;
|
|
85
|
+
/** 5xx infrastructure failures may be retried; a refused exchange must not be — tickets are single-use. */
|
|
86
|
+
readonly retryable: boolean;
|
|
87
|
+
/** The service's machine code when the body carried one, e.g. `elevation_ticket_expired`. */
|
|
88
|
+
readonly serviceCode?: string;
|
|
89
|
+
}
|
|
90
|
+
declare class AssistantSessionExchangeError extends Error {
|
|
91
|
+
readonly detail: AssistantSessionExchangeErrorDetail;
|
|
92
|
+
constructor(detail: AssistantSessionExchangeErrorDetail, message: string);
|
|
93
|
+
/**
|
|
94
|
+
* The narrowed sign-in refusal, when this failure is one. `elevation_ticket_expired` means the
|
|
95
|
+
* visitor took too long — re-prompt; `elevation_tenant_mismatch` means a client reached for a
|
|
96
|
+
* conversation it does not own — alert someone, never retry.
|
|
97
|
+
*/
|
|
98
|
+
get elevationRefusal(): AssistantElevationRefusalCode | undefined;
|
|
99
|
+
}
|
|
47
100
|
declare function createAssistantSession(input: CreateAssistantSessionInput, dependencies?: {
|
|
48
101
|
readonly fetch?: typeof fetch;
|
|
49
102
|
}): Promise<AssistantSession>;
|
|
50
103
|
|
|
51
|
-
export { type AssistantSession, type CreateAssistantSessionInput, createAssistantSession };
|
|
104
|
+
export { ASSISTANT_ELEVATION_REFUSAL_CODES, type AssistantElevationRefusalCode, type AssistantSession, AssistantSessionExchangeError, type AssistantSessionExchangeErrorDetail, type CreateAssistantSessionInput, createAssistantSession };
|
|
@@ -1,7 +1,48 @@
|
|
|
1
1
|
import "./chunk-5FUTL2UF.js";
|
|
2
2
|
|
|
3
3
|
// src/server.ts
|
|
4
|
+
var ASSISTANT_ELEVATION_REFUSAL_CODES = [
|
|
5
|
+
"elevation_ticket_invalid",
|
|
6
|
+
"elevation_ticket_expired",
|
|
7
|
+
"elevation_tenant_mismatch",
|
|
8
|
+
"elevation_session_unavailable",
|
|
9
|
+
"elevation_already_signed_in"
|
|
10
|
+
];
|
|
11
|
+
var AssistantSessionExchangeError = class extends Error {
|
|
12
|
+
detail;
|
|
13
|
+
constructor(detail, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "AssistantSessionExchangeError";
|
|
16
|
+
this.detail = detail;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The narrowed sign-in refusal, when this failure is one. `elevation_ticket_expired` means the
|
|
20
|
+
* visitor took too long — re-prompt; `elevation_tenant_mismatch` means a client reached for a
|
|
21
|
+
* conversation it does not own — alert someone, never retry.
|
|
22
|
+
*/
|
|
23
|
+
get elevationRefusal() {
|
|
24
|
+
const code = this.detail.serviceCode;
|
|
25
|
+
return code !== void 0 && ASSISTANT_ELEVATION_REFUSAL_CODES.includes(code) ? code : void 0;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
async function exchangeError(response) {
|
|
29
|
+
const body = await response.json().catch(() => void 0);
|
|
30
|
+
const serviceCode = typeof body?.code === "string" ? body.code : void 0;
|
|
31
|
+
return new AssistantSessionExchangeError(
|
|
32
|
+
{
|
|
33
|
+
code: "session_exchange_failed",
|
|
34
|
+
status: response.status,
|
|
35
|
+
// `elevation_unavailable` is a 503 an operator has to fix; retrying cannot help.
|
|
36
|
+
retryable: response.status >= 500 && serviceCode !== "elevation_unavailable",
|
|
37
|
+
...serviceCode === void 0 ? {} : { serviceCode }
|
|
38
|
+
},
|
|
39
|
+
`Assistant session exchange failed (${response.status})`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
4
42
|
async function createAssistantSession(input, dependencies = {}) {
|
|
43
|
+
if (input.signInTicket !== void 0 && input.context !== void 0) {
|
|
44
|
+
throw new Error("context does not apply when spending a sign-in ticket");
|
|
45
|
+
}
|
|
5
46
|
const request = dependencies.fetch ?? fetch;
|
|
6
47
|
const serviceUrl = input.serviceUrl.replace(/\/$/, "");
|
|
7
48
|
const credentials = Buffer.from(`${input.clientId}:${input.clientSecret}`, "utf8").toString(
|
|
@@ -17,16 +58,19 @@ async function createAssistantSession(input, dependencies = {}) {
|
|
|
17
58
|
body: JSON.stringify({
|
|
18
59
|
origin: input.origin,
|
|
19
60
|
user: input.user,
|
|
61
|
+
...input.signInTicket === void 0 ? {} : { signInTicket: input.signInTicket },
|
|
20
62
|
...input.claims ? { claims: input.claims } : {},
|
|
21
63
|
...input.context ? { context: input.context } : {},
|
|
22
64
|
...input.preferences ? { preferences: input.preferences } : {},
|
|
23
65
|
...input.routing ? { routing: input.routing } : {}
|
|
24
66
|
})
|
|
25
67
|
});
|
|
26
|
-
if (!response.ok) throw
|
|
68
|
+
if (!response.ok) throw await exchangeError(response);
|
|
27
69
|
return await response.json();
|
|
28
70
|
}
|
|
29
71
|
export {
|
|
72
|
+
ASSISTANT_ELEVATION_REFUSAL_CODES,
|
|
73
|
+
AssistantSessionExchangeError,
|
|
30
74
|
createAssistantSession
|
|
31
75
|
};
|
|
32
76
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import type { AssistantConfiguration } from './appearance.js';\n\
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import type { AssistantConfiguration } from './appearance.js';\n\ninterface AssistantSessionExchangeBase {\n readonly serviceUrl: string;\n readonly clientId: string;\n readonly clientSecret: string;\n /** Browser origin to bind into the short-lived assistant session. */\n readonly origin: string;\n /** The signed-in person your backend vouches for — on both arms: an elevation IS this vouching. */\n readonly user: {\n readonly id: string;\n readonly email?: string;\n readonly name?: string;\n readonly tenant?: string;\n readonly roles?: readonly string[];\n readonly scopes?: readonly string[];\n };\n /** Backend-verified user preferences; these outrank untrusted browser presentation hints. */\n readonly preferences?: {\n readonly locale?: string;\n readonly timeZone?: string;\n };\n /**\n * Verified session claims from your authenticated backend. Only claims the server declares in\n * `embeddedAssistant({ sessionClaims })` reach tools (`\\${user.claims.<key>}`) and, when marked\n * `exposeToModel`, the assistant's identity context. Flat scalars only.\n */\n readonly claims?: Readonly<Record<string, string | number | boolean | null>>;\n}\n\n/**\n * Fresh mint XOR mid-conversation sign-in, exclusive rather than merged for the same reason the\n * client's `sessionEndpoint`/`embedId` pair is: the two are different operations, and the wrong\n * combination should fail to typecheck instead of silently picking a meaning.\n *\n * `context` applies only when a session is being created; an elevation keeps the existing\n * conversation, so it is excluded rather than silently ignored. `routing` is allowed on both arms —\n * elevation is the first authenticated moment, so it is the only chance a routed connector's\n * session ever gets its backend-verified customer routes.\n */\nexport type CreateAssistantSessionInput =\n | (AssistantSessionExchangeBase & {\n readonly signInTicket?: undefined;\n readonly context?: Readonly<Record<string, string | number | boolean | null>>;\n /** Backend-verified connector routes keyed by authored `customerEndpoint` name. */\n readonly routing?: {\n readonly endpoints: Readonly<Record<string, string>>;\n };\n })\n | (AssistantSessionExchangeBase & {\n /**\n * Single-use sign-in ticket from the widget's `assistant-sign-in-requested` event\n * (ADR 0201, 5.6b). Spending it binds this signed-in user to the visitor's existing\n * anonymous conversation instead of minting a new one. Unrelated to the server-held\n * interaction continuation, which never reaches browser code.\n */\n readonly signInTicket: string;\n readonly context?: undefined;\n /** Backend-verified connector routes keyed by authored `customerEndpoint` name. */\n readonly routing?: {\n readonly endpoints: Readonly<Record<string, string>>;\n };\n });\n\nexport interface AssistantSession {\n readonly token: string;\n readonly expiresAt: string;\n readonly endpoints: {\n readonly turns: string;\n readonly toolConfirmations: string;\n readonly interactions?: string;\n readonly apps?: string;\n /** Additive hosted sandbox document for widget frames; absent on older services. */\n readonly sandbox?: string;\n };\n readonly configuration?: AssistantConfiguration;\n}\n\n/** The service's refusal codes for a sign-in ticket the exchange would not honour. */\nexport const ASSISTANT_ELEVATION_REFUSAL_CODES = [\n 'elevation_ticket_invalid',\n 'elevation_ticket_expired',\n 'elevation_tenant_mismatch',\n 'elevation_session_unavailable',\n 'elevation_already_signed_in',\n] as const;\nexport type AssistantElevationRefusalCode = (typeof ASSISTANT_ELEVATION_REFUSAL_CODES)[number];\n\n/**\n * Structurally mirrors the browser client's `AssistantErrorDetail` (declared locally: the backend\n * entry must not pull the browser transport module into its graph). `code` is a closed union owned\n * by this package; `serviceCode` passes the service's machine code through additively.\n */\nexport interface AssistantSessionExchangeErrorDetail {\n readonly code: 'session_exchange_failed';\n readonly status: number;\n /** 5xx infrastructure failures may be retried; a refused exchange must not be — tickets are single-use. */\n readonly retryable: boolean;\n /** The service's machine code when the body carried one, e.g. `elevation_ticket_expired`. */\n readonly serviceCode?: string;\n}\n\nexport class AssistantSessionExchangeError extends Error {\n readonly detail: AssistantSessionExchangeErrorDetail;\n\n constructor(detail: AssistantSessionExchangeErrorDetail, message: string) {\n super(message);\n this.name = 'AssistantSessionExchangeError';\n this.detail = detail;\n }\n\n /**\n * The narrowed sign-in refusal, when this failure is one. `elevation_ticket_expired` means the\n * visitor took too long — re-prompt; `elevation_tenant_mismatch` means a client reached for a\n * conversation it does not own — alert someone, never retry.\n */\n get elevationRefusal(): AssistantElevationRefusalCode | undefined {\n const code = this.detail.serviceCode;\n return code !== undefined &&\n (ASSISTANT_ELEVATION_REFUSAL_CODES as readonly string[]).includes(code)\n ? (code as AssistantElevationRefusalCode)\n : undefined;\n }\n}\n\n/** Never throws while reading the body — a proxy can answer with HTML instead of JSON. */\nasync function exchangeError(response: Response): Promise<AssistantSessionExchangeError> {\n const body = (await response.json().catch(() => undefined)) as\n | { readonly error?: unknown; readonly code?: unknown }\n | undefined;\n const serviceCode = typeof body?.code === 'string' ? body.code : undefined;\n return new AssistantSessionExchangeError(\n {\n code: 'session_exchange_failed',\n status: response.status,\n // `elevation_unavailable` is a 503 an operator has to fix; retrying cannot help.\n retryable: response.status >= 500 && serviceCode !== 'elevation_unavailable',\n ...(serviceCode === undefined ? {} : { serviceCode }),\n },\n `Assistant session exchange failed (${response.status})`,\n );\n}\n\nexport async function createAssistantSession(\n input: CreateAssistantSessionInput,\n dependencies: { readonly fetch?: typeof fetch } = {},\n): Promise<AssistantSession> {\n if (input.signInTicket !== undefined && (input as { context?: unknown }).context !== undefined) {\n // Mirrors resolveSessionSource: silently dropping what the service ignores would pick a\n // meaning the developer did not intend.\n throw new Error('context does not apply when spending a sign-in ticket');\n }\n const request = dependencies.fetch ?? fetch;\n const serviceUrl = input.serviceUrl.replace(/\\/$/, '');\n const credentials = Buffer.from(`${input.clientId}:${input.clientSecret}`, 'utf8').toString(\n 'base64',\n );\n const response = await request(`${serviceUrl}/v1/assistant/sessions`, {\n method: 'POST',\n headers: {\n Authorization: `Basic ${credentials}`,\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n origin: input.origin,\n user: input.user,\n ...(input.signInTicket === undefined ? {} : { signInTicket: input.signInTicket }),\n ...(input.claims ? { claims: input.claims } : {}),\n ...(input.context ? { context: input.context } : {}),\n ...(input.preferences ? { preferences: input.preferences } : {}),\n ...(input.routing ? { routing: input.routing } : {}),\n }),\n });\n // A fresh mint answers 201, an elevation 200; both are the same wire shape (ADR 0151).\n if (!response.ok) throw await exchangeError(response);\n return (await response.json()) as AssistantSession;\n}\n"],"mappings":";;;AA+EO,IAAM,oCAAoC;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAiBO,IAAM,gCAAN,cAA4C,MAAM;AAAA,EAC9C;AAAA,EAET,YAAY,QAA6C,SAAiB;AACxE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,mBAA8D;AAChE,UAAM,OAAO,KAAK,OAAO;AACzB,WAAO,SAAS,UACb,kCAAwD,SAAS,IAAI,IACnE,OACD;AAAA,EACN;AACF;AAGA,eAAe,cAAc,UAA4D;AACvF,QAAM,OAAQ,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,MAAS;AAGzD,QAAM,cAAc,OAAO,MAAM,SAAS,WAAW,KAAK,OAAO;AACjE,SAAO,IAAI;AAAA,IACT;AAAA,MACE,MAAM;AAAA,MACN,QAAQ,SAAS;AAAA;AAAA,MAEjB,WAAW,SAAS,UAAU,OAAO,gBAAgB;AAAA,MACrD,GAAI,gBAAgB,SAAY,CAAC,IAAI,EAAE,YAAY;AAAA,IACrD;AAAA,IACA,sCAAsC,SAAS,MAAM;AAAA,EACvD;AACF;AAEA,eAAsB,uBACpB,OACA,eAAkD,CAAC,GACxB;AAC3B,MAAI,MAAM,iBAAiB,UAAc,MAAgC,YAAY,QAAW;AAG9F,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,QAAM,UAAU,aAAa,SAAS;AACtC,QAAM,aAAa,MAAM,WAAW,QAAQ,OAAO,EAAE;AACrD,QAAM,cAAc,OAAO,KAAK,GAAG,MAAM,QAAQ,IAAI,MAAM,YAAY,IAAI,MAAM,EAAE;AAAA,IACjF;AAAA,EACF;AACA,QAAM,WAAW,MAAM,QAAQ,GAAG,UAAU,0BAA0B;AAAA,IACpE,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,eAAe,SAAS,WAAW;AAAA,MACnC,QAAQ;AAAA,MACR,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAU;AAAA,MACnB,QAAQ,MAAM;AAAA,MACd,MAAM,MAAM;AAAA,MACZ,GAAI,MAAM,iBAAiB,SAAY,CAAC,IAAI,EAAE,cAAc,MAAM,aAAa;AAAA,MAC/E,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;AAAA,MAC/C,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,MAClD,GAAI,MAAM,cAAc,EAAE,aAAa,MAAM,YAAY,IAAI,CAAC;AAAA,MAC9D,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,IACpD,CAAC;AAAA,EACH,CAAC;AAED,MAAI,CAAC,SAAS,GAAI,OAAM,MAAM,cAAc,QAAQ;AACpD,SAAQ,MAAM,SAAS,KAAK;AAC9B;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noodleseed/assistant",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Embed the Noodle Seed customer-branded assistant in your web app with a Web Component, managed or custom React UI, DOM-free client, and backend session helper. Authoring and deploying the server is @noodleseed/one.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noodleseed/one",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.129.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Noodle CLI by Noodle Seed — author, run, and deploy declarative MCP servers. Embedding the assistant in your own web app is @noodleseed/assistant.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"@noodle-borg/knowledge-operations",
|
|
104
104
|
"@noodle-borg/module",
|
|
105
105
|
"@noodle-borg/module-audit",
|
|
106
|
+
"@noodle-borg/oauth-client-registry",
|
|
106
107
|
"@noodle-borg/openapi-import",
|
|
107
108
|
"@noodle-borg/plugin-distribution",
|
|
108
109
|
"@noodle-borg/protocol",
|
|
@@ -235,7 +236,7 @@
|
|
|
235
236
|
"@jitl/quickjs-wasmfile-release-sync": "0.32.0",
|
|
236
237
|
"@modelcontextprotocol/client": "2.0.0",
|
|
237
238
|
"@modelcontextprotocol/server": "2.0.0",
|
|
238
|
-
"@noodle-borg/agent-kit": "0.
|
|
239
|
+
"@noodle-borg/agent-kit": "0.76.0",
|
|
239
240
|
"@noodle-borg/app-audit": "0.0.0",
|
|
240
241
|
"@noodle-borg/app-package": "0.0.0",
|
|
241
242
|
"@noodle-borg/auth": "0.0.0",
|