@noodleseed/assistant 1.23.0 → 1.25.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/README.md +4 -9
- package/dist/{app-view-element-7ZQZLYbL.d.ts → app-view-element-9ojWWYov.d.cts} +3 -2
- package/dist/{app-view-element-1i_w6FDf.d.cts → app-view-element-BM4lral-.d.ts} +3 -2
- package/dist/app-view.cjs +213 -41
- package/dist/app-view.cjs.map +1 -1
- package/dist/app-view.d.cts +3 -3
- package/dist/app-view.d.ts +3 -3
- package/dist/app-view.js +2 -2
- package/dist/{appearance-Cc-eqSbp.d.cts → appearance-B6vSg8Ub.d.cts} +5 -0
- package/dist/{appearance-Cc-eqSbp.d.ts → appearance-B6vSg8Ub.d.ts} +5 -0
- package/dist/{chunk-IBDP6PXQ.js → chunk-7BQHW37I.js} +71 -3
- package/dist/chunk-7BQHW37I.js.map +1 -0
- package/dist/{chunk-5NBHHNI3.js → chunk-LNBUYHL7.js} +2 -2
- package/dist/chunk-LNBUYHL7.js.map +1 -0
- package/dist/{chunk-XKTUXFGX.js → chunk-P32MAR4K.js} +214 -42
- package/dist/chunk-P32MAR4K.js.map +1 -0
- package/dist/{chunk-X7UQDIGS.js → chunk-SGMECNNU.js} +94 -43
- package/dist/chunk-SGMECNNU.js.map +1 -0
- package/dist/{client-Bp_VKpMg.d.ts → client-BkogON2A.d.ts} +11 -1
- package/dist/{client-uo57Swlm.d.cts → client-C07ppTU_.d.cts} +11 -1
- package/dist/client.cjs +70 -2
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/embed.global.js +149 -114
- package/dist/index.cjs +396 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/react/client.cjs +70 -2
- package/dist/react/client.cjs.map +1 -1
- package/dist/react/client.d.cts +2 -2
- package/dist/react/client.d.ts +2 -2
- package/dist/react/client.js +1 -1
- package/dist/react.cjs +396 -105
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +4 -4
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +3 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5NBHHNI3.js.map +0 -1
- package/dist/chunk-IBDP6PXQ.js.map +0 -1
- package/dist/chunk-X7UQDIGS.js.map +0 -1
- package/dist/chunk-XKTUXFGX.js.map +0 -1
package/dist/react.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactElement, RefAttributes } from 'react';
|
|
2
|
-
import { a as AssistantThemeMode } from './appearance-
|
|
2
|
+
import { a as AssistantThemeMode } from './appearance-B6vSg8Ub.cjs';
|
|
3
3
|
import { AssistantAppearance, AssistantAppearanceWarning, NoodleAssistantElement } from './index.cjs';
|
|
4
|
-
import { A as AssistantClient, a as AssistantViewAvailableDetail, b as AssistantPageContext, c as AssistantContext, f as AssistantModelContextUpdate, g as AssistantClientEvent, e as AssistantErrorDetail } from './client-
|
|
5
|
-
import { a as AssistantAppViewErrorDetail } from './app-view-element-
|
|
4
|
+
import { A as AssistantClient, a as AssistantViewAvailableDetail, b as AssistantPageContext, c as AssistantContext, f as AssistantModelContextUpdate, g as AssistantClientEvent, e as AssistantErrorDetail } from './client-C07ppTU_.cjs';
|
|
5
|
+
import { a as AssistantAppViewErrorDetail } from './app-view-element-9ojWWYov.cjs';
|
|
6
6
|
import 'ai';
|
|
7
7
|
|
|
8
8
|
interface NoodleAppViewProps {
|
package/dist/react.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactElement, RefAttributes } from 'react';
|
|
2
|
-
import { a as AssistantThemeMode } from './appearance-
|
|
2
|
+
import { a as AssistantThemeMode } from './appearance-B6vSg8Ub.js';
|
|
3
3
|
import { AssistantAppearance, AssistantAppearanceWarning, NoodleAssistantElement } from './index.js';
|
|
4
|
-
import { A as AssistantClient, a as AssistantViewAvailableDetail, b as AssistantPageContext, c as AssistantContext, f as AssistantModelContextUpdate, g as AssistantClientEvent, e as AssistantErrorDetail } from './client-
|
|
5
|
-
import { a as AssistantAppViewErrorDetail } from './app-view-element-
|
|
4
|
+
import { A as AssistantClient, a as AssistantViewAvailableDetail, b as AssistantPageContext, c as AssistantContext, f as AssistantModelContextUpdate, g as AssistantClientEvent, e as AssistantErrorDetail } from './client-BkogON2A.js';
|
|
5
|
+
import { a as AssistantAppViewErrorDetail } from './app-view-element-BM4lral-.js';
|
|
6
6
|
import 'ai';
|
|
7
7
|
|
|
8
8
|
interface NoodleAppViewProps {
|
package/dist/react.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
registerNoodleAssistant
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SGMECNNU.js";
|
|
4
4
|
import {
|
|
5
5
|
APP_VIEW_TAG_NAME,
|
|
6
6
|
registerNoodleAppView
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-LNBUYHL7.js";
|
|
8
|
+
import "./chunk-P32MAR4K.js";
|
|
9
|
+
import "./chunk-7BQHW37I.js";
|
|
10
10
|
import "./chunk-P223CYPO.js";
|
|
11
11
|
import "./chunk-3YYTUJPJ.js";
|
|
12
12
|
import "./chunk-5FUTL2UF.js";
|
package/dist/server.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 /** Resume applies only when spending a sign-in ticket; a fresh mint has nothing pending. */\n readonly resume?: undefined;\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 * Whether the service resumes the intercepted tool call as the elevated session's first\n * turn (issue #1177). ON by default — omit it and the visitor's pending question answers\n * itself after sign-in; pass `false` if your application provides its own affordance.\n */\n readonly resume?: boolean;\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 /**\n * Present only on an elevation that armed the one-shot resume of the intercepted tool. Forward\n * the response body unchanged and the widget answers with one automatic turn.\n */\n readonly resume?: { readonly tool: string };\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.signInTicket !== undefined && input.resume !== undefined\n ? { resume: input.resume }\n : {}),\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;AA4FO,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,iBAAiB,UAAa,MAAM,WAAW,SACrD,EAAE,QAAQ,MAAM,OAAO,IACvB,CAAC;AAAA,MACL,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
|
+
{"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 /** Resume applies only when spending a sign-in ticket; a fresh mint has nothing pending. */\n readonly resume?: undefined;\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 * Whether the service resumes the intercepted tool call as the elevated session's first\n * turn (issue #1177). ON by default — omit it and the visitor's pending question answers\n * itself after sign-in; pass `false` if your application provides its own affordance.\n */\n readonly resume?: boolean;\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 /** Additive bounded visible-transcript endpoint; absent on older services. */\n readonly transcript?: string;\n };\n /**\n * Present only on an elevation that armed the one-shot resume of the intercepted tool. Forward\n * the response body unchanged and the widget answers with one automatic turn.\n */\n readonly resume?: { readonly tool: string };\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.signInTicket !== undefined && input.resume !== undefined\n ? { resume: input.resume }\n : {}),\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;A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AAA,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,iBAAiB,UAAa,MAAM,WAAW,SACrD,EAAE,QAAQ,MAAM,OAAO,IACvB,CAAC;AAAA,MACL,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":[]}
|
package/dist/server.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AssistantConfiguration } from './appearance-
|
|
1
|
+
import { A as AssistantConfiguration } from './appearance-B6vSg8Ub.cjs';
|
|
2
2
|
|
|
3
3
|
interface AssistantSessionExchangeBase {
|
|
4
4
|
readonly serviceUrl: string;
|
|
@@ -76,6 +76,8 @@ interface AssistantSession {
|
|
|
76
76
|
readonly apps?: string;
|
|
77
77
|
/** Additive hosted sandbox document for widget frames; absent on older services. */
|
|
78
78
|
readonly sandbox?: string;
|
|
79
|
+
/** Additive bounded visible-transcript endpoint; absent on older services. */
|
|
80
|
+
readonly transcript?: string;
|
|
79
81
|
};
|
|
80
82
|
/**
|
|
81
83
|
* Present only on an elevation that armed the one-shot resume of the intercepted tool. Forward
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AssistantConfiguration } from './appearance-
|
|
1
|
+
import { A as AssistantConfiguration } from './appearance-B6vSg8Ub.js';
|
|
2
2
|
|
|
3
3
|
interface AssistantSessionExchangeBase {
|
|
4
4
|
readonly serviceUrl: string;
|
|
@@ -76,6 +76,8 @@ interface AssistantSession {
|
|
|
76
76
|
readonly apps?: string;
|
|
77
77
|
/** Additive hosted sandbox document for widget frames; absent on older services. */
|
|
78
78
|
readonly sandbox?: string;
|
|
79
|
+
/** Additive bounded visible-transcript endpoint; absent on older services. */
|
|
80
|
+
readonly transcript?: string;
|
|
79
81
|
};
|
|
80
82
|
/**
|
|
81
83
|
* Present only on an elevation that armed the one-shot resume of the intercepted tool. Forward
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 /** Resume applies only when spending a sign-in ticket; a fresh mint has nothing pending. */\n readonly resume?: undefined;\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 * Whether the service resumes the intercepted tool call as the elevated session's first\n * turn (issue #1177). ON by default — omit it and the visitor's pending question answers\n * itself after sign-in; pass `false` if your application provides its own affordance.\n */\n readonly resume?: boolean;\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 /**\n * Present only on an elevation that armed the one-shot resume of the intercepted tool. Forward\n * the response body unchanged and the widget answers with one automatic turn.\n */\n readonly resume?: { readonly tool: string };\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.signInTicket !== undefined && input.resume !== undefined\n ? { resume: input.resume }\n : {}),\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":";;;AA4FO,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,O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AAI,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
|
+
{"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 /** Resume applies only when spending a sign-in ticket; a fresh mint has nothing pending. */\n readonly resume?: undefined;\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 * Whether the service resumes the intercepted tool call as the elevated session's first\n * turn (issue #1177). ON by default — omit it and the visitor's pending question answers\n * itself after sign-in; pass `false` if your application provides its own affordance.\n */\n readonly resume?: boolean;\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 /** Additive bounded visible-transcript endpoint; absent on older services. */\n readonly transcript?: string;\n };\n /**\n * Present only on an elevation that armed the one-shot resume of the intercepted tool. Forward\n * the response body unchanged and the widget answers with one automatic turn.\n */\n readonly resume?: { readonly tool: string };\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.signInTicket !== undefined && input.resume !== undefined\n ? { resume: input.resume }\n : {}),\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":";;;AA8FO,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,WA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M,cAAc,QAAQ;AACpD,SAAQ,MAAM,SAAS,KAAK;AAC9B;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noodleseed/assistant",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.0",
|
|
4
4
|
"description": "Embed the Noodle Seed customer-branded assistant in your web app with managed or framework-owned UI, a framework-neutral MCP App host, a DOM-free client, and a backend session helper. Authoring and deploying the server is @noodleseed/one.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/app-view-element.ts","../src/app-view.ts"],"sourcesContent":["import { mountAssistantApp, unmountAssistantApp, updateAssistantAppTheme } from './app-host.js';\nimport { ASSISTANT_APP_VIEW_STYLES } from './app-view-styles.js';\nimport type { AssistantClient, AssistantViewAvailableDetail } from './client.js';\nimport type { AssistantErrorDetail } from './transport.js';\n\nexport const APP_VIEW_TAG_NAME = 'noodle-app-view';\n\nexport interface AssistantAppViewErrorDetail {\n readonly code: 'view_render_timeout';\n readonly retryable: false;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'noodle-app-view': NoodleAppViewElement;\n }\n\n interface HTMLElementEventMap {\n 'assistant-error': CustomEvent<AssistantErrorDetail>;\n }\n}\n\nconst HTMLElementBase: typeof HTMLElement =\n globalThis.HTMLElement ?? (class {} as unknown as typeof HTMLElement);\n\nfunction viewIdentity(view: AssistantViewAvailableDetail): string {\n return `${view.id}\\u0000${view.resourceUri}`;\n}\n\n/**\n * Framework-neutral host for one service-resolved MCP App view.\n *\n * `client` and `view` are object properties, not serialized attributes. Vue, Angular, and plain DOM\n * renderers can therefore pass the same `data-view` payload without taking a React dependency.\n */\nexport class NoodleAppViewElement extends HTMLElementBase {\n static readonly observedAttributes = ['allow-fullscreen', 'theme'];\n\n #allowFullscreen = false;\n #client: AssistantClient | undefined;\n #view: AssistantViewAvailableDetail | undefined;\n #theme: 'light' | 'dark' = 'light';\n #container: HTMLElement | undefined;\n #mounted: HTMLElement | undefined;\n #mountedClient: AssistantClient | undefined;\n #mountedAllowFullscreen = false;\n #mountedIdentity: string | undefined;\n #requestedTeardown: { readonly client: AssistantClient; readonly identity: string } | undefined;\n\n get client(): AssistantClient | undefined {\n return this.#client;\n }\n\n /** Allow the hosted App to request fullscreen. Disabled by default. */\n get allowFullscreen(): boolean {\n return this.#allowFullscreen;\n }\n\n set allowFullscreen(value: boolean) {\n const next = value === true;\n if (next === this.#allowFullscreen) return;\n this.#allowFullscreen = next;\n this.toggleAttribute('allow-fullscreen', next);\n this.#reconcile();\n }\n\n set client(value: AssistantClient | undefined) {\n if (value === this.#client) return;\n this.#client = value;\n this.#reconcile();\n }\n\n get view(): AssistantViewAvailableDetail | undefined {\n return this.#view;\n }\n\n set view(value: AssistantViewAvailableDetail | undefined) {\n this.#view = value;\n this.#reconcile();\n }\n\n get theme(): 'light' | 'dark' {\n return this.#theme;\n }\n\n set theme(value: 'light' | 'dark') {\n const next = value === 'dark' ? 'dark' : 'light';\n const changed = next !== this.#theme;\n this.#theme = next;\n if (this.getAttribute('data-theme') !== next) this.setAttribute('data-theme', next);\n if (changed && this.#mounted) updateAssistantAppTheme(this.#mounted, next);\n }\n\n connectedCallback(): void {\n this.#ensureContainer();\n this.#upgradeProperty('allowFullscreen');\n this.#upgradeProperty('client');\n this.#upgradeProperty('theme');\n this.#upgradeProperty('view');\n this.#reconcile();\n }\n\n disconnectedCallback(): void {\n this.#requestedTeardown = undefined;\n this.#releaseMount();\n }\n\n attributeChangedCallback(name: string, _previous: string | null, value: string | null): void {\n if (name === 'allow-fullscreen') this.allowFullscreen = value !== null;\n if (name === 'theme') this.theme = value === 'dark' ? 'dark' : 'light';\n }\n\n #ensureContainer(): HTMLElement {\n if (this.#container) return this.#container;\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' });\n root.innerHTML = ASSISTANT_APP_VIEW_STYLES;\n const container = document.createElement('div');\n container.className = 'noodle-app-mount';\n container.setAttribute('part', 'mount');\n root.append(container);\n this.#container = container;\n return container;\n }\n\n #upgradeProperty(name: 'allowFullscreen' | 'client' | 'theme' | 'view'): void {\n const property = Object.getOwnPropertyDescriptor(this, name);\n if (!property) return;\n Reflect.deleteProperty(this, name);\n Reflect.set(this, name, property.value);\n }\n\n #releaseMount(): void {\n const mounted = this.#mounted;\n this.#mounted = undefined;\n this.#mountedClient = undefined;\n this.#mountedAllowFullscreen = false;\n this.#mountedIdentity = undefined;\n this.#container?.replaceChildren();\n if (mounted) void unmountAssistantApp(mounted);\n }\n\n #reconcile(): void {\n if (!this.isConnected) return;\n const client = this.#client;\n const detail = this.#view;\n const identity = detail ? viewIdentity(detail) : undefined;\n\n if (this.#mounted) {\n if (\n client === this.#mountedClient &&\n identity === this.#mountedIdentity &&\n this.#allowFullscreen === this.#mountedAllowFullscreen\n ) {\n return;\n }\n this.#releaseMount();\n }\n\n if (\n this.#requestedTeardown &&\n (client !== this.#requestedTeardown.client || identity !== this.#requestedTeardown.identity)\n ) {\n this.#requestedTeardown = undefined;\n }\n if (!client || !detail?.html || !identity || this.#requestedTeardown) return;\n\n const initialHtml = detail.html;\n const sandboxUrl = client.appSandboxUrl?.();\n let card: HTMLElement | undefined;\n card = mountAssistantApp(\n detail,\n {\n client,\n sendMessage: (message) => client.sendMessage(message),\n updateModelContext: (update) => client.updateModelContext(update),\n theme: this.#theme,\n },\n {\n allowFullscreen: this.#allowFullscreen,\n ...(sandboxUrl ? { sandboxUrl } : {}),\n getDetail: () => {\n const latest = this.#view;\n if (this.#client !== client || !latest || viewIdentity(latest) !== identity)\n return detail;\n return latest.html ? latest : { ...latest, html: initialHtml };\n },\n onRenderFailure: (failure) => {\n this.dispatchEvent(\n new CustomEvent<AssistantAppViewErrorDetail>('assistant-error', {\n detail: failure,\n bubbles: true,\n composed: true,\n }),\n );\n },\n onTeardownRequest: () => {\n if (this.#mounted !== card) return;\n this.#mounted = undefined;\n this.#mountedClient = undefined;\n this.#mountedIdentity = undefined;\n this.#requestedTeardown = { client, identity };\n },\n },\n );\n if (!card) return;\n this.#mounted = card;\n this.#mountedClient = client;\n this.#mountedAllowFullscreen = this.#allowFullscreen;\n this.#mountedIdentity = identity;\n this.#ensureContainer().replaceChildren(card);\n }\n}\n","import { APP_VIEW_TAG_NAME, NoodleAppViewElement } from './app-view-element.js';\n\nexport {\n APP_VIEW_TAG_NAME,\n type AssistantAppViewErrorDetail,\n NoodleAppViewElement,\n} from './app-view-element.js';\nexport type { AssistantClient, AssistantViewAvailableDetail } from './client.js';\n\n/** Register the framework-neutral MCP App host. Safe to call more than once or during SSR. */\nexport function registerNoodleAppView(): void {\n if (!globalThis.customElements?.get(APP_VIEW_TAG_NAME)) {\n globalThis.customElements?.define(APP_VIEW_TAG_NAME, NoodleAppViewElement);\n }\n}\n\nregisterNoodleAppView();\n"],"mappings":";;;;;;;;AAKO,IAAM,oBAAoB;AAiBjC,IAAM,kBACJ,WAAW,eAAgB,MAAM;AAAC;AAEpC,SAAS,aAAa,MAA4C;AAChE,SAAO,GAAG,KAAK,EAAE,KAAS,KAAK,WAAW;AAC5C;AAQO,IAAM,uBAAN,cAAmC,gBAAgB;AAAA,EACxD,OAAgB,qBAAqB,CAAC,oBAAoB,OAAO;AAAA,EAEjE,mBAAmB;AAAA,EACnB;AAAA,EACA;AAAA,EACA,SAA2B;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA,0BAA0B;AAAA,EAC1B;AAAA,EACA;AAAA,EAEA,IAAI,SAAsC;AACxC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,kBAA2B;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,gBAAgB,OAAgB;AAClC,UAAM,OAAO,UAAU;AACvB,QAAI,SAAS,KAAK,iBAAkB;AACpC,SAAK,mBAAmB;AACxB,SAAK,gBAAgB,oBAAoB,IAAI;AAC7C,SAAK,WAAW;AA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