@ahmedramez-org/chat 0.7.0-beta.3 → 0.8.0-beta.1

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.
@@ -149,7 +149,7 @@ export declare function chatPageOf(url: string): string | null;
149
149
  export declare const NOT_INCORTA = "not_incorta";
150
150
  /** `fetchClientId`'s error code: no answer from the instance itself (down, offline, redirected away, too slow). */
151
151
  export declare const INCORTA_UNREACHABLE = "incorta_unreachable";
152
- /** `fetchClientId`'s error code: the instance's gateway answered 502, 503 or 504 (down or restarting). */
152
+ /** `fetchClientId`'s error code: the instance's gateway answered 502, 503 or 504 (down or restarting), not Incorta's `oauth_server_disabled` refusal. */
153
153
  export declare const INCORTA_UNAVAILABLE = "incorta_unavailable";
154
154
  /**
155
155
  * The apps' client Copilot names for a workspace now, or null when it cannot say within
@@ -174,12 +174,13 @@ export declare function signInFailure(error: unknown): SignInFailure | undefined
174
174
  /** Each app's words for a `signInFailure`, one copy so every app says the same. */
175
175
  export declare const SIGN_IN_FAILURE_TEXT: Record<SignInFailure, string>;
176
176
  /**
177
- * Asks Copilot for the apps' OAuth client on a tenant (it registers one per tenant, D-119): the
178
- * check that the address is an Incorta that signs the apps in, before any browser sign-in. It
179
- * sends nothing of the user's (no cookie, no token) and gives up after `timeoutMs`. Throws an error
180
- * coded `NOT_INCORTA` when the address is not such an Incorta (or the tenant is unknown: Copilot
181
- * cannot tell them apart), `INCORTA_UNREACHABLE` when the instance does not answer (or a redirect
182
- * leaves it), `INCORTA_UNAVAILABLE` when its gateway says it is down, and a plain one otherwise.
177
+ * Asks Incorta for the apps' OAuth client on a tenant (`GET /oauth/{tenant}/intelligence-chat-client`:
178
+ * Incorta creates one per tenant, D-244): the check that the address is an Incorta that signs the
179
+ * apps in, before any browser sign-in. It sends nothing of the user's (no cookie, no token) and gives
180
+ * up after `timeoutMs`. Throws an error coded `NOT_INCORTA` when the address is not such an Incorta
181
+ * (or the tenant is unknown, Copilot is off for it, or its OAuth server is off),
182
+ * `INCORTA_UNREACHABLE` when the instance does not answer (or a redirect leaves it),
183
+ * `INCORTA_UNAVAILABLE` when its gateway says it is down, and a plain one otherwise.
183
184
  */
184
185
  export declare function fetchClientId(incortaUrl: string, tenant: string, fetchImpl?: typeof fetch, { timeoutMs }?: {
185
186
  timeoutMs?: number;
package/contract/host.js CHANGED
@@ -235,7 +235,7 @@ export function chatPageOf(url) {
235
235
  export const NOT_INCORTA = 'not_incorta';
236
236
  /** `fetchClientId`'s error code: no answer from the instance itself (down, offline, redirected away, too slow). */
237
237
  export const INCORTA_UNREACHABLE = 'incorta_unreachable';
238
- /** `fetchClientId`'s error code: the instance's gateway answered 502, 503 or 504 (down or restarting). */
238
+ /** `fetchClientId`'s error code: the instance's gateway answered 502, 503 or 504 (down or restarting), not Incorta's `oauth_server_disabled` refusal. */
239
239
  export const INCORTA_UNAVAILABLE = 'incorta_unavailable';
240
240
  /**
241
241
  * The apps' client Copilot names for a workspace now, or null when it cannot say within
@@ -276,21 +276,25 @@ export const SIGN_IN_FAILURE_TEXT = {
276
276
  failed: 'Something went wrong. Try again.',
277
277
  };
278
278
  /**
279
- * Asks Copilot for the apps' OAuth client on a tenant (it registers one per tenant, D-119): the
280
- * check that the address is an Incorta that signs the apps in, before any browser sign-in. It
281
- * sends nothing of the user's (no cookie, no token) and gives up after `timeoutMs`. Throws an error
282
- * coded `NOT_INCORTA` when the address is not such an Incorta (or the tenant is unknown: Copilot
283
- * cannot tell them apart), `INCORTA_UNREACHABLE` when the instance does not answer (or a redirect
284
- * leaves it), `INCORTA_UNAVAILABLE` when its gateway says it is down, and a plain one otherwise.
279
+ * Asks Incorta for the apps' OAuth client on a tenant (`GET /oauth/{tenant}/intelligence-chat-client`:
280
+ * Incorta creates one per tenant, D-244): the check that the address is an Incorta that signs the
281
+ * apps in, before any browser sign-in. It sends nothing of the user's (no cookie, no token) and gives
282
+ * up after `timeoutMs`. Throws an error coded `NOT_INCORTA` when the address is not such an Incorta
283
+ * (or the tenant is unknown, Copilot is off for it, or its OAuth server is off),
284
+ * `INCORTA_UNREACHABLE` when the instance does not answer (or a redirect leaves it),
285
+ * `INCORTA_UNAVAILABLE` when its gateway says it is down, and a plain one otherwise.
285
286
  */
286
287
  export async function fetchClientId(incortaUrl, tenant, fetchImpl = globalThis.fetch, { timeoutMs = 10_000 } = {}) {
287
288
  const coded = (code, why, cause) => Object.assign(new Error(why, { cause }), { code });
289
+ // The tenant is a path segment: only a plain name, never `.` or `..`, which would leave it.
290
+ if (!/^[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}$/.test(tenant) || /^\.+$/.test(tenant))
291
+ throw coded(NOT_INCORTA, 'Not a tenant name');
288
292
  const deadline = new AbortController();
289
293
  const timer = setTimeout(() => deadline.abort(), timeoutMs);
290
294
  try {
291
295
  let answer;
292
296
  try {
293
- answer = await fetchImpl(`${incortaUrl}/copilot/native/oauth-client?tenant=${encodeURIComponent(tenant)}`, { credentials: 'omit', signal: deadline.signal });
297
+ answer = await fetchImpl(`${incortaUrl}/oauth/${encodeURIComponent(tenant)}/intelligence-chat-client`, { credentials: 'omit', signal: deadline.signal });
294
298
  }
295
299
  catch (error) {
296
300
  throw coded(INCORTA_UNREACHABLE, 'Incorta did not answer', error);
@@ -298,9 +302,15 @@ export async function fetchClientId(incortaUrl, tenant, fetchImpl = globalThis.f
298
302
  // A captive portal or a gateway's sign-in page answers in its place.
299
303
  if (answer.url && new URL(answer.url).origin !== new URL(incortaUrl).origin)
300
304
  throw coded(INCORTA_UNREACHABLE, 'Redirected off the instance');
301
- if (answer.status === 502 || answer.status === 503 || answer.status === 504)
305
+ if (answer.status === 502 || answer.status === 503 || answer.status === 504) {
306
+ // Incorta's `oauth_server_disabled` refusal is a setting, not an outage. Sent as 400
307
+ // today (NOT_INCORTA below), as 503 once Incorta sends the status it intends.
308
+ const why = (await answer.json().catch(() => null));
309
+ if (why?.error === 'oauth_server_disabled')
310
+ throw coded(NOT_INCORTA, 'Incorta signs no apps in');
302
311
  throw coded(INCORTA_UNAVAILABLE, `Incorta answered HTTP ${answer.status}.`);
303
- // 404: not an Incorta, the apps' sign-in is off, or the tenant is unknown; 400: not a tenant name.
312
+ }
313
+ // 404: not an Incorta, Copilot is off, or the tenant is unknown; 400: not a tenant name.
304
314
  if (answer.status === 404 || answer.status === 400)
305
315
  throw coded(NOT_INCORTA, `No app client (HTTP ${answer.status})`);
306
316
  if (!answer.ok)
@@ -683,16 +683,23 @@ export interface HostAction<T, R = void> {
683
683
  run(target: T): R | Promise<R>;
684
684
  }
685
685
  /**
686
- * What `actions.save` is handed: the artifact. A report (`html`, `report`)
687
- * also carries where Copilot stores it and Copilot's own task and artifact
688
- * ids: the chat asks about a report only once it can place it in the stored
689
- * conversation. Every other kind is saved from `data` and never carries them.
686
+ * What `actions.save`, `actions.shareAccess` and `actions.openSaved` are
687
+ * handed: the artifact. A report (`html`, `report`) also carries its id in
688
+ * Copilot's artifact repository and, for a save, Copilot's own task and
689
+ * artifact ids: Save asks about a report only once the chat can place it in the
690
+ * stored conversation. Every other kind is saved from `data` and never carries
691
+ * them.
690
692
  */
691
693
  export interface SaveTarget extends ChatArtifact {
692
694
  /**
693
- * The report's file in Copilot's artifact repository (`artifact://{tenant}/{id}`):
694
- * what a host saves the report by and later opens it by. Absent when Copilot
695
- * did not name one; a host that needs it declines the report then.
695
+ * The report's id in Copilot's artifact repository (`repo_artifact_id`): what a host saves
696
+ * the report by and later opens it by, in the caller's tenant. Absent when Copilot did not
697
+ * name one; a host that needs it declines the report then.
698
+ */
699
+ repoArtifactId?: string;
700
+ /**
701
+ * @deprecated The report's `artifact://{tenant}/{id}` URI: save by `repoArtifactId`. Still
702
+ * filled while hosts move off it.
696
703
  */
697
704
  artifactUri?: string;
698
705
  /** Copilot's task and artifact ids for the message part: email share and lineage. */
@@ -714,19 +721,32 @@ export interface ChatActions {
714
721
  open?: HostAction<OpenIntent>;
715
722
  /**
716
723
  * Save a generated draft or a report in the host's catalog. `run` resolves
717
- * to the fields the save changed; the chat records them on the stored part
718
- * so the conversation replays the artifact as saved: in `data` when the
719
- * payload is an object, in `metadata` when it is not (a report's HTML), which
720
- * is where `can` then reads them. In `metadata` a field is only ever added:
721
- * one the part already carries is kept. `{}` means nothing was saved (the
722
- * user dismissed the host's dialog): nothing is recorded and Save stays.
723
- * Absent: no Save.
724
+ * to the fields the save changed, which `can` then reads on the artifact.
725
+ * A draft's go into its `data` and are recorded on the stored part, so the
726
+ * conversation replays it as saved. A report's go into its `metadata` on the
727
+ * card only, never sent: the host's backend marks a saved report itself as it
728
+ * serves the history (Incorta's `saved_items`). A field the artifact already
729
+ * carries is replaced. `{}` means nothing was saved (the user dismissed the
730
+ * host's dialog): nothing is recorded and Save stays. Absent: no Save.
724
731
  */
725
732
  save?: HostAction<SaveTarget, Record<string, unknown>>;
726
733
  /**
727
- * Share an artifact through the host's own dialog; `run` resolves `true`
728
- * once shared. Shown in the canvas and the card menu wherever `can` accepts
729
- * the target. Absent: no Share.
734
+ * Who may see a report the host saved: its own access dialog, offered wherever
735
+ * `can` accepts the report (a host offers it once the report is saved, so Save
736
+ * and Share access take turns). `run` may resolve to fields to set on the
737
+ * report's card, as Save's are: a host that finds the saved item gone resolves
738
+ * `{ saved_items: null }`, and the card offers Save again. Absent: no Share access.
739
+ */
740
+ shareAccess?: HostAction<SaveTarget, Record<string, unknown> | void>;
741
+ /**
742
+ * Open the saved report where the host keeps it (Incorta's Content), offered
743
+ * as "Open in Content" wherever `can` accepts the report. Absent: none.
744
+ */
745
+ openSaved?: HostAction<SaveTarget>;
746
+ /**
747
+ * Email an artifact through the host's own dialog (Copilot sends it, hence its
748
+ * ids); `run` resolves `true` once sent. Shown in the canvas and the card menu,
749
+ * as "Email report", wherever `can` accepts the target. Absent: no Email.
730
750
  */
731
751
  share?: HostAction<ShareTarget, boolean>;
732
752
  /** Insert an answer's code block into the host (a notebook paragraph). Absent: no Insert button. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahmedramez-org/chat",
3
- "version": "0.7.0-beta.3",
3
+ "version": "0.8.0-beta.1",
4
4
  "description": "Incorta's chat for any app: a connector and React component that load the prebuilt chat from IncortaCopilot (or a pinned copy), and the host contract types and checks.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {