@noodleseed/one 0.127.2 → 0.128.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.
Files changed (86) hide show
  1. package/dist/commands/assistant-embed-ops.d.ts.map +1 -1
  2. package/dist/commands/assistant-embed-ops.js +82 -9
  3. package/dist/commands/assistant-embed-ops.js.map +1 -1
  4. package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.d.ts.map +1 -1
  5. package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.js +6 -4
  6. package/node_modules/@noodle-borg/agent-kit/dist/skill-embedded-assistant-ref.js.map +1 -1
  7. package/node_modules/@noodle-borg/assistant-gateway/dist/assistant-store.d.ts +9 -0
  8. package/node_modules/@noodle-borg/assistant-gateway/dist/assistant-store.d.ts.map +1 -1
  9. package/node_modules/@noodle-borg/assistant-gateway/dist/assistant-store.js +11 -0
  10. package/node_modules/@noodle-borg/assistant-gateway/dist/assistant-store.js.map +1 -1
  11. package/node_modules/@noodle-borg/assistant-gateway/dist/elevation.d.ts +13 -1
  12. package/node_modules/@noodle-borg/assistant-gateway/dist/elevation.d.ts.map +1 -1
  13. package/node_modules/@noodle-borg/assistant-gateway/dist/elevation.js +4 -3
  14. package/node_modules/@noodle-borg/assistant-gateway/dist/elevation.js.map +1 -1
  15. package/node_modules/@noodle-borg/assistant-gateway/dist/postgres-assistant.d.ts +3 -0
  16. package/node_modules/@noodle-borg/assistant-gateway/dist/postgres-assistant.d.ts.map +1 -1
  17. package/node_modules/@noodle-borg/assistant-gateway/dist/postgres-assistant.js +8 -1
  18. package/node_modules/@noodle-borg/assistant-gateway/dist/postgres-assistant.js.map +1 -1
  19. package/node_modules/@noodle-borg/cli-catalog/dist/catalog-data-assistant.d.ts.map +1 -1
  20. package/node_modules/@noodle-borg/cli-catalog/dist/catalog-data-assistant.js +16 -0
  21. package/node_modules/@noodle-borg/cli-catalog/dist/catalog-data-assistant.js.map +1 -1
  22. package/node_modules/@noodle-borg/connector-defs/dist/delegated-token-exchange-identity.js +16 -1
  23. package/node_modules/@noodle-borg/connector-defs/dist/delegated-token-exchange-identity.js.map +1 -1
  24. package/node_modules/@noodle-borg/service/dist/assistant-delegated-projection.d.ts +12 -0
  25. package/node_modules/@noodle-borg/service/dist/assistant-delegated-projection.d.ts.map +1 -0
  26. package/node_modules/@noodle-borg/service/dist/assistant-delegated-projection.js +68 -0
  27. package/node_modules/@noodle-borg/service/dist/assistant-delegated-projection.js.map +1 -0
  28. package/node_modules/@noodle-borg/service/dist/credential-broker.d.ts +6 -0
  29. package/node_modules/@noodle-borg/service/dist/credential-broker.d.ts.map +1 -1
  30. package/node_modules/@noodle-borg/service/dist/credential-broker.js +9 -0
  31. package/node_modules/@noodle-borg/service/dist/credential-broker.js.map +1 -1
  32. package/node_modules/@noodle-borg/service/dist/registry-compile.d.ts.map +1 -1
  33. package/node_modules/@noodle-borg/service/dist/registry-compile.js +8 -0
  34. package/node_modules/@noodle-borg/service/dist/registry-compile.js.map +1 -1
  35. package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.d.ts.map +1 -1
  36. package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.js +26 -7
  37. package/node_modules/@noodle-borg/service/dist/routes/assistant-agent.js.map +1 -1
  38. package/node_modules/@noodle-borg/service/dist/routes/assistant-dispatch.js +2 -1
  39. package/node_modules/@noodle-borg/service/dist/routes/assistant-dispatch.js.map +1 -1
  40. package/node_modules/@noodle-borg/service/dist/routes/assistant-doctor.d.ts +10 -0
  41. package/node_modules/@noodle-borg/service/dist/routes/assistant-doctor.d.ts.map +1 -0
  42. package/node_modules/@noodle-borg/service/dist/routes/assistant-doctor.js +164 -0
  43. package/node_modules/@noodle-borg/service/dist/routes/assistant-doctor.js.map +1 -0
  44. package/node_modules/@noodle-borg/service/dist/routes/assistant-elevation.d.ts +21 -3
  45. package/node_modules/@noodle-borg/service/dist/routes/assistant-elevation.d.ts.map +1 -1
  46. package/node_modules/@noodle-borg/service/dist/routes/assistant-elevation.js +45 -7
  47. package/node_modules/@noodle-borg/service/dist/routes/assistant-elevation.js.map +1 -1
  48. package/node_modules/@noodle-borg/service/dist/routes/assistant.d.ts +0 -2
  49. package/node_modules/@noodle-borg/service/dist/routes/assistant.d.ts.map +1 -1
  50. package/node_modules/@noodle-borg/service/dist/routes/assistant.js +7 -88
  51. package/node_modules/@noodle-borg/service/dist/routes/assistant.js.map +1 -1
  52. package/node_modules/@noodleseed/assistant/README.md +68 -0
  53. package/node_modules/@noodleseed/assistant/dist/{chunk-S373FCAI.js → chunk-52XT7BLR.js} +9 -4
  54. package/node_modules/@noodleseed/assistant/dist/{chunk-S373FCAI.js.map → chunk-52XT7BLR.js.map} +1 -1
  55. package/node_modules/@noodleseed/assistant/dist/{chunk-RFETV5KQ.js → chunk-DLUINP4W.js} +9 -9
  56. package/node_modules/@noodleseed/assistant/dist/{chunk-RFETV5KQ.js.map → chunk-DLUINP4W.js.map} +1 -1
  57. package/node_modules/@noodleseed/assistant/dist/{client-BQ30Fq-c.d.cts → client-7o7n2nqw.d.cts} +6 -4
  58. package/node_modules/@noodleseed/assistant/dist/{client-B6pnBmF8.d.ts → client-CysBQBdd.d.ts} +6 -4
  59. package/node_modules/@noodleseed/assistant/dist/client.cjs +8 -3
  60. package/node_modules/@noodleseed/assistant/dist/client.cjs.map +1 -1
  61. package/node_modules/@noodleseed/assistant/dist/client.d.cts +1 -1
  62. package/node_modules/@noodleseed/assistant/dist/client.d.ts +1 -1
  63. package/node_modules/@noodleseed/assistant/dist/client.js +1 -1
  64. package/node_modules/@noodleseed/assistant/dist/embed.global.js +4 -4
  65. package/node_modules/@noodleseed/assistant/dist/index.cjs +15 -10
  66. package/node_modules/@noodleseed/assistant/dist/index.cjs.map +1 -1
  67. package/node_modules/@noodleseed/assistant/dist/index.d.cts +2 -2
  68. package/node_modules/@noodleseed/assistant/dist/index.d.ts +2 -2
  69. package/node_modules/@noodleseed/assistant/dist/index.js +2 -2
  70. package/node_modules/@noodleseed/assistant/dist/react/client.cjs +8 -3
  71. package/node_modules/@noodleseed/assistant/dist/react/client.cjs.map +1 -1
  72. package/node_modules/@noodleseed/assistant/dist/react/client.d.cts +1 -1
  73. package/node_modules/@noodleseed/assistant/dist/react/client.d.ts +1 -1
  74. package/node_modules/@noodleseed/assistant/dist/react/client.js +1 -1
  75. package/node_modules/@noodleseed/assistant/dist/react.cjs +15 -10
  76. package/node_modules/@noodleseed/assistant/dist/react.cjs.map +1 -1
  77. package/node_modules/@noodleseed/assistant/dist/react.d.cts +1 -1
  78. package/node_modules/@noodleseed/assistant/dist/react.d.ts +1 -1
  79. package/node_modules/@noodleseed/assistant/dist/react.js +2 -2
  80. package/node_modules/@noodleseed/assistant/dist/server.cjs +47 -1
  81. package/node_modules/@noodleseed/assistant/dist/server.cjs.map +1 -1
  82. package/node_modules/@noodleseed/assistant/dist/server.d.cts +60 -7
  83. package/node_modules/@noodleseed/assistant/dist/server.d.ts +60 -7
  84. package/node_modules/@noodleseed/assistant/dist/server.js +45 -1
  85. package/node_modules/@noodleseed/assistant/dist/server.js.map +1 -1
  86. package/package.json +1 -1
@@ -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-BQ30Fq-c.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-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-B6pnBmF8.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-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-RFETV5KQ.js";
7
- import "./chunk-S373FCAI.js";
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 new Error(`Assistant session exchange failed (${response.status})`);
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\nexport interface CreateAssistantSessionInput {\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 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 readonly context?: Readonly<Record<string, string | number | boolean | null>>;\n /** Backend-verified user preferences; these outrank untrusted browser presentation hints. */\n readonly preferences?: {\n readonly locale?: string;\n readonly timeZone?: string;\n };\n /** Backend-verified connector routes keyed by authored `customerEndpoint` name. */\n readonly routing?: {\n readonly endpoints: Readonly<Record<string, 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\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\nexport async function createAssistantSession(\n input: CreateAssistantSessionInput,\n dependencies: { readonly fetch?: typeof fetch } = {},\n): Promise<AssistantSession> {\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.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 if (!response.ok) throw new Error(`Assistant session exchange failed (${response.status})`);\n return (await response.json()) as AssistantSession;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgDA,eAAsB,uBACpB,OACA,eAAkD,CAAC,GACxB;AAC3B,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,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;AACD,MAAI,CAAC,SAAS,GAAI,OAAM,IAAI,MAAM,sCAAsC,SAAS,MAAM,GAAG;AAC1F,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 })\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 CreateAssistantSessionInput {
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 CreateAssistantSessionInput {
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 new Error(`Assistant session exchange failed (${response.status})`);
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\nexport interface CreateAssistantSessionInput {\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 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 readonly context?: Readonly<Record<string, string | number | boolean | null>>;\n /** Backend-verified user preferences; these outrank untrusted browser presentation hints. */\n readonly preferences?: {\n readonly locale?: string;\n readonly timeZone?: string;\n };\n /** Backend-verified connector routes keyed by authored `customerEndpoint` name. */\n readonly routing?: {\n readonly endpoints: Readonly<Record<string, 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\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\nexport async function createAssistantSession(\n input: CreateAssistantSessionInput,\n dependencies: { readonly fetch?: typeof fetch } = {},\n): Promise<AssistantSession> {\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.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 if (!response.ok) throw new Error(`Assistant session exchange failed (${response.status})`);\n return (await response.json()) as AssistantSession;\n}\n"],"mappings":";;;AAgDA,eAAsB,uBACpB,OACA,eAAkD,CAAC,GACxB;AAC3B,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,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;AACD,MAAI,CAAC,SAAS,GAAI,OAAM,IAAI,MAAM,sCAAsC,SAAS,MAAM,GAAG;AAC1F,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 })\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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noodleseed/one",
3
- "version": "0.127.2",
3
+ "version": "0.128.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",