@axiom-lattice/client-sdk 4.3.2 → 4.3.4

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.
@@ -0,0 +1,67 @@
1
+ import { Client } from "./client";
2
+ import type { MessageChunk } from "@axiom-lattice/protocols";
3
+ import type { AgentState, ClientConfig, RunOptions } from "./types";
4
+ /**
5
+ * Identity presented to an Agent Web App runtime by {@link RuntimeAxiomClient}.
6
+ *
7
+ * Mirrors the web-app SDK identity union: `verified` sessions authenticate
8
+ * with a short-lived `Authorization: Bearer` token resolved (and refreshed)
9
+ * per transport use, while `unverified` sessions identify through the stable
10
+ * `X-Axiom-External-User-Id` header the gateway accepts without a token.
11
+ */
12
+ export type RuntimeAxiomIdentity = {
13
+ mode: "verified";
14
+ tokenProvider: () => Promise<string>;
15
+ } | {
16
+ mode: "unverified";
17
+ userId: string;
18
+ };
19
+ /**
20
+ * AxiomClient transport wired to an Agent Web App runtime instead of the
21
+ * Console. Reuse-first: only the transport differs. `baseURL` points at
22
+ * `<gateway>/api/web-apps/:webAppId/runtime`, every Console `/api/...` path
23
+ * the chat stack produces lands on the gateway's `/runtime/api` console
24
+ * mirror, and the web-app identity (bearer or external-user header) is
25
+ * injected fresh per request.
26
+ *
27
+ * The chat stack (AgentThreadContext + Chating) therefore runs unmodified.
28
+ */
29
+ export declare class RuntimeAxiomClient extends Client {
30
+ private readonly gatewayUrl;
31
+ private readonly webAppId;
32
+ private readonly identity;
33
+ private token;
34
+ private tokenPromise;
35
+ constructor(config: Omit<ClientConfig, "apiKey" | "baseURL"> & {
36
+ gatewayUrl: string;
37
+ webAppId: string;
38
+ identity: RuntimeAxiomIdentity;
39
+ });
40
+ /**
41
+ * Resolve (and cache) the current identity credential.
42
+ *
43
+ * - `verified`: resolves the bearer token from the provider (single-flight;
44
+ * call again later to force a refresh, or pass through a fresh provider).
45
+ * - `unverified`: no credential is needed; returns `""`.
46
+ *
47
+ * Transport methods resolve this lazily, so the chat stack needs no explicit
48
+ * priming — the first request triggers the token provider.
49
+ */
50
+ primeToken(): Promise<string>;
51
+ private identityHeaders;
52
+ protected getAllHeaders(): Record<string, string>;
53
+ protected makeRequest<T>(url: string, options?: {
54
+ method?: string;
55
+ body?: unknown;
56
+ headers?: Record<string, string>;
57
+ }): Promise<T>;
58
+ private getBaseUrl;
59
+ /**
60
+ * Clone into a real sibling instance sharing the runtime identity so the
61
+ * `AxiomLatticeProvider` per-assistant `clone({ assistantId })` cache keeps
62
+ * working (each clone carries its own resolved credential cache).
63
+ */
64
+ protected createInstance(config: ClientConfig): Client;
65
+ protected streamRequest(_options: RunOptions, _onEvent: (event: MessageChunk) => void, _onComplete?: (state?: AgentState) => void, _onError?: (error: Error) => void): () => void;
66
+ }
67
+ //# sourceMappingURL=runtime-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-client.d.ts","sourceRoot":"","sources":["../src/runtime-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,aAAa,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3C;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,SAAQ,MAAM;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAChD,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,YAAY,CAAgC;gBAExC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,SAAS,CAAC,GAAG;QAC7D,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,oBAAoB,CAAC;KAChC;IAcD;;;;;;;;;OASG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAWnC,OAAO,CAAC,eAAe;IAOvB,SAAS,CAAC,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;cAQjC,WAAW,CAAC,CAAC,EAC3B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAC9E,OAAO,CAAC,CAAC,CAAC;IAkCb,OAAO,CAAC,UAAU;IAIlB;;;;OAIG;IACH,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM;IAatD,SAAS,CAAC,aAAa,CACrB,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,EACvC,WAAW,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,UAAU,KAAK,IAAI,EAC1C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAChC,MAAM,IAAI;CAGd"}
@@ -0,0 +1,122 @@
1
+ import { Client } from "./client";
2
+ /**
3
+ * AxiomClient transport wired to an Agent Web App runtime instead of the
4
+ * Console. Reuse-first: only the transport differs. `baseURL` points at
5
+ * `<gateway>/api/web-apps/:webAppId/runtime`, every Console `/api/...` path
6
+ * the chat stack produces lands on the gateway's `/runtime/api` console
7
+ * mirror, and the web-app identity (bearer or external-user header) is
8
+ * injected fresh per request.
9
+ *
10
+ * The chat stack (AgentThreadContext + Chating) therefore runs unmodified.
11
+ */
12
+ export class RuntimeAxiomClient extends Client {
13
+ constructor(config) {
14
+ super({
15
+ ...config,
16
+ baseURL: `${config.gatewayUrl.replace(/\/$/, "")}/api/web-apps/${config.webAppId}/runtime`,
17
+ apiKey: "runtime-bearer",
18
+ });
19
+ this.token = null;
20
+ this.tokenPromise = null;
21
+ this.gatewayUrl = config.gatewayUrl.replace(/\/$/, "");
22
+ this.webAppId = config.webAppId;
23
+ this.identity = config.identity;
24
+ if (config.identity.mode === "unverified" && config.identity.userId.length === 0) {
25
+ throw new Error("RuntimeAxiomClient requires a non-empty userId in unverified mode");
26
+ }
27
+ }
28
+ /**
29
+ * Resolve (and cache) the current identity credential.
30
+ *
31
+ * - `verified`: resolves the bearer token from the provider (single-flight;
32
+ * call again later to force a refresh, or pass through a fresh provider).
33
+ * - `unverified`: no credential is needed; returns `""`.
34
+ *
35
+ * Transport methods resolve this lazily, so the chat stack needs no explicit
36
+ * priming — the first request triggers the token provider.
37
+ */
38
+ async primeToken() {
39
+ if (this.identity.mode !== "verified")
40
+ return "";
41
+ if (!this.tokenPromise) {
42
+ this.tokenPromise = this.identity.tokenProvider().then((token) => {
43
+ this.token = token;
44
+ return token;
45
+ });
46
+ }
47
+ return this.tokenPromise;
48
+ }
49
+ identityHeaders() {
50
+ if (this.identity.mode === "verified") {
51
+ return { Authorization: `Bearer ${this.token ?? ""}` };
52
+ }
53
+ return { "X-Axiom-External-User-Id": this.identity.userId };
54
+ }
55
+ getAllHeaders() {
56
+ const workspace = this.getWorkspaceHeaders();
57
+ return {
58
+ ...this.identityHeaders(),
59
+ ...workspace,
60
+ };
61
+ }
62
+ async makeRequest(url, options) {
63
+ await this.primeToken();
64
+ const method = options?.method ?? "GET";
65
+ const headers = {
66
+ "Content-Type": "application/json",
67
+ ...this.identityHeaders(),
68
+ ...(options?.headers ?? {}),
69
+ };
70
+ const requestOptions = { method, headers };
71
+ if (options?.body !== undefined) {
72
+ if (options.body instanceof FormData) {
73
+ requestOptions.body = options.body;
74
+ delete headers["Content-Type"];
75
+ }
76
+ else {
77
+ requestOptions.body = JSON.stringify(options.body);
78
+ }
79
+ }
80
+ const response = await fetch(`${this.getBaseUrl()}${url}`, requestOptions);
81
+ if (!response.ok) {
82
+ let message = `HTTP ${response.status}`;
83
+ try {
84
+ const body = (await response.json());
85
+ message = body.error ?? body.message ?? message;
86
+ }
87
+ catch {
88
+ /* keep the status message */
89
+ }
90
+ const error = new Error(message);
91
+ error.status = response.status;
92
+ throw error;
93
+ }
94
+ if (response.status === 204)
95
+ return undefined;
96
+ return (await response.json());
97
+ }
98
+ getBaseUrl() {
99
+ return this.config.baseURL;
100
+ }
101
+ /**
102
+ * Clone into a real sibling instance sharing the runtime identity so the
103
+ * `AxiomLatticeProvider` per-assistant `clone({ assistantId })` cache keeps
104
+ * working (each clone carries its own resolved credential cache).
105
+ */
106
+ createInstance(config) {
107
+ return new RuntimeAxiomClient({
108
+ gatewayUrl: this.gatewayUrl,
109
+ webAppId: this.webAppId,
110
+ identity: this.identity,
111
+ assistantId: config.assistantId,
112
+ transport: config.transport,
113
+ ...(config.timeout !== undefined ? { timeout: config.timeout } : {}),
114
+ ...(config.headers !== undefined ? { headers: config.headers } : {}),
115
+ ...(config.retry !== undefined ? { retry: config.retry } : {}),
116
+ });
117
+ }
118
+ streamRequest(_options, _onEvent, _onComplete, _onError) {
119
+ throw new Error("RuntimeAxiomClient uses resumeStream; chat.stream is unsupported");
120
+ }
121
+ }
122
+ //# sourceMappingURL=runtime-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-client.js","sourceRoot":"","sources":["../src/runtime-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAgBlC;;;;;;;;;GASG;AACH,MAAM,OAAO,kBAAmB,SAAQ,MAAM;IAO5C,YAAY,MAIX;QACC,KAAK,CAAC;YACJ,GAAG,MAAM;YACT,OAAO,EAA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CAAC;IACL,CAAC;IAES,aAAa,CACrB,QAAoB,EACpB,QAAuC,EACvC,WAA0C,EAC1C,QAAiC;QAEjC,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiom-lattice/client-sdk",
3
- "version": "4.3.2",
3
+ "version": "4.3.4",
4
4
  "description": "TypeScript client SDK for interacting with the Agent Service API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "best-effort-json-parser": "^1.2.1",
34
- "@axiom-lattice/protocols": "4.1.3"
34
+ "@axiom-lattice/protocols": "4.1.4"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsc &&tsup src/index.ts --format cjs,esm --dts --sourcemap",