@engini/sdk 0.35.0 → 0.36.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 CHANGED
@@ -31,6 +31,18 @@ JWT auth is the fallback: `new Engini({ token: "<jwt>", companyToken: "<id>" })`
31
31
  `ENGINI_API_TOKEN` / `ENGINI_COMPANY_TOKEN`. With an API key the company is bound to the key,
32
32
  so no company token is needed. Point at another host with `new Engini({ …, baseUrl })`.
33
33
 
34
+ A person token (not an API key) can reach several workspaces. Name the one to act in with
35
+ `workspaceId` and `environmentId` (GUIDs, always together):
36
+
37
+ ```ts
38
+ const client = new Engini({ token: "<token>", workspaceId: "<ws-guid>", environmentId: "<env-guid>" });
39
+ ```
40
+
41
+ With neither, lists cover every workspace/environment you can open and a create lands in the
42
+ account's default workspace. An API key is already pinned to one pair, so passing a pair with
43
+ `apiKey` throws. The pair travels as headers for now; a later release moves it into list filters
44
+ and create bodies without changing these options.
45
+
34
46
  Every request carries a `User-Agent` identifying this SDK and its runtime (e.g.
35
47
  `engini-sdk-ts/0.13.0 node/20.11.0 darwin-arm64`). If you're embedding the SDK inside your own
36
48
  product, prepend your own token with `userAgentPrefix`:
package/dist/client.d.ts CHANGED
@@ -48,7 +48,28 @@ export interface EnginiOptions {
48
48
  * control character or exceeds 128 characters.
49
49
  */
50
50
  userAgentPrefix?: string;
51
+ /**
52
+ * Workspace to act in (a GUID), for a person token (`token`/`auth`) that can
53
+ * reach several workspaces. Pass it together with `environmentId`, or neither:
54
+ * with neither, the server decides (lists cover every pair you can open; a
55
+ * create lands in the account's default workspace). Not allowed with api-key
56
+ * auth - a key is already pinned to one workspace and environment.
57
+ *
58
+ * Sent as the `workspaceId` header for now; a later release moves it to list
59
+ * filters and create bodies inside the SDK, without changing this option.
60
+ */
61
+ workspaceId?: string;
62
+ /** Environment to act in (a GUID); always together with `workspaceId`. */
63
+ environmentId?: string;
51
64
  }
65
+ /**
66
+ * Validate the client-level workspace/environment pair: both or neither,
67
+ * GUID-shaped. Returns the pair, or `undefined` when neither is given.
68
+ */
69
+ export declare function validateScopePair(workspaceId: string | undefined, environmentId: string | undefined): {
70
+ workspaceId: string;
71
+ environmentId: string;
72
+ } | undefined;
52
73
  /** Engini SDK client — the single public entry point. */
53
74
  export declare class Engini {
54
75
  readonly tools: ToolsResource;
package/dist/client.js CHANGED
@@ -16,6 +16,25 @@ import { ApplicationsResource } from "./resources/applications.js";
16
16
  import { AuthResource } from "./resources/auth.js";
17
17
  import { Toolset } from "./toolset.js";
18
18
  export const DEFAULT_BASE_URL = "https://api.engini.io";
19
+ const GUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
20
+ /**
21
+ * Validate the client-level workspace/environment pair: both or neither,
22
+ * GUID-shaped. Returns the pair, or `undefined` when neither is given.
23
+ */
24
+ export function validateScopePair(workspaceId, environmentId) {
25
+ if (workspaceId === undefined && environmentId === undefined)
26
+ return undefined;
27
+ if (workspaceId === undefined || environmentId === undefined) {
28
+ throw new EnginiClientError("Pass both `workspaceId` and `environmentId`, or neither.");
29
+ }
30
+ if (!GUID_RE.test(workspaceId)) {
31
+ throw new EnginiClientError("`workspaceId` must be a GUID.");
32
+ }
33
+ if (!GUID_RE.test(environmentId)) {
34
+ throw new EnginiClientError("`environmentId` must be a GUID.");
35
+ }
36
+ return { workspaceId, environmentId };
37
+ }
19
38
  /** Engini SDK client — the single public entry point. */
20
39
  export class Engini {
21
40
  tools;
@@ -71,10 +90,15 @@ export class Engini {
71
90
  const companyToken = isApiKey
72
91
  ? undefined
73
92
  : (options.companyToken ?? process.env[ENV_COMPANY_TOKEN_VAR]);
93
+ const scope = validateScopePair(options.workspaceId, options.environmentId);
94
+ if (isApiKey && scope !== undefined) {
95
+ throw new EnginiClientError("`workspaceId`/`environmentId` are not used with api-key auth; the key is pinned to one workspace and environment.");
96
+ }
74
97
  this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
75
98
  this._transport = buildClient(this.baseUrl, auth, companyToken, {
76
99
  verify: options.verify ?? true,
77
100
  userAgentPrefix: options.userAgentPrefix,
101
+ scope,
78
102
  });
79
103
  this.provider = options.provider ?? new OpenAIProvider();
80
104
  this.tools = new ToolsResource(this);
package/dist/http.d.ts CHANGED
@@ -47,6 +47,10 @@ export declare function composeUserAgent(prefix?: string): string;
47
47
  export declare function buildClient(baseUrl: string, auth: Auth, companyToken?: string, options?: {
48
48
  verify?: Verify;
49
49
  userAgentPrefix?: string;
50
+ scope?: {
51
+ workspaceId: string;
52
+ environmentId: string;
53
+ };
50
54
  }): Transport;
51
55
  /** A generated operation function (hey-api), invoked with `{ client, ... }`. */
52
56
  type Operation<O, R> = (options: O & {
package/dist/http.js CHANGED
@@ -82,6 +82,12 @@ export function buildClient(baseUrl, auth, companyToken, options = {}) {
82
82
  headers.set(key, value);
83
83
  if (companyToken !== undefined)
84
84
  headers.set("companytoken", companyToken);
85
+ // Stopgap transport for the client-level pair: the server reads these headers
86
+ // today; a later release moves the pair into list filters / create bodies.
87
+ if (options.scope !== undefined) {
88
+ headers.set("workspaceId", options.scope.workspaceId);
89
+ headers.set("environmentId", options.scope.environmentId);
90
+ }
85
91
  headers.set("user-agent", composeUserAgent(options.userAgentPrefix));
86
92
  const dispatcher = tlsDispatcher(options.verify ?? true);
87
93
  const fetchOverride = dispatcher === undefined
package/dist/version.d.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * Regenerated on every build/typecheck/test (see the "pre*" scripts in
4
4
  * package.json). Un-stamped local builds yield "0.0.0".
5
5
  */
6
- export declare const VERSION = "0.35.0";
6
+ export declare const VERSION = "0.36.0";
package/dist/version.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Regenerated on every build/typecheck/test (see the "pre*" scripts in
4
4
  * package.json). Un-stamped local builds yield "0.0.0".
5
5
  */
6
- export const VERSION = "0.35.0";
6
+ export const VERSION = "0.36.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/sdk",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "Engini SDK — agent-first ergonomic layer over the Engini Public API",
5
5
  "license": "MIT",
6
6
  "type": "module",