@kmlckj/licos-platform-sdk 0.6.8 → 0.6.9

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
@@ -17,50 +17,50 @@ is resolved automatically by the runtime:
17
17
 
18
18
  ## Database
19
19
 
20
- Database CRUD helpers call the runtime database data plane only. Tooling helpers
21
- can fetch platform schema metadata for ORM export. The SDK does not expose
22
- service deletion APIs.
23
-
24
- `database.table(name)` is a query builder. Use it for `select` queries only.
25
-
26
- ```js
27
- import { database } from '@kmlckj/licos-platform-sdk';
28
-
29
- const rows = await database
20
+ Database CRUD helpers call the runtime database data plane only. Tooling helpers
21
+ can fetch platform schema metadata for ORM export. The SDK does not expose
22
+ service deletion APIs.
23
+
24
+ `database.table(name)` is a query builder. Use it for `select` queries only.
25
+
26
+ ```js
27
+ import { database } from '@kmlckj/licos-platform-sdk';
28
+
29
+ const rows = await database
30
30
  .table('todos')
31
31
  .select('id', 'title')
32
32
  .eq('done', false)
33
33
  .order('created_at', { desc: true })
34
- .limit(10)
35
- .execute();
36
- ```
37
-
38
- Use top-level helpers for mutations:
39
-
40
- ```js
41
- import { database } from '@kmlckj/licos-platform-sdk';
42
-
43
- const inserted = await database.insert('todos', {
44
- row: { title: 'Call customer', done: false },
45
- returning: true,
46
- });
47
-
48
- await database.updateRows('todos', {
49
- filters: [{ field: 'id', op: 'eq', value: inserted.data?.[0]?.id }],
50
- values: { done: true },
51
- });
52
-
53
- await database.deleteRows('todos', {
54
- filters: [{ field: 'done', op: 'eq', value: true }],
55
- });
56
- ```
57
-
58
- Do not call `.table('todos').insert(...)`, `.table('todos').updateRows(...)`,
59
- or `.table('todos').deleteRows(...)`; those methods do not exist on the query
60
- builder.
61
-
62
- ORM export is a tooling helper. It fetches platform schema metadata and returns
63
- source text; it does not use direct database credentials.
34
+ .limit(10)
35
+ .execute();
36
+ ```
37
+
38
+ Use top-level helpers for mutations:
39
+
40
+ ```js
41
+ import { database } from '@kmlckj/licos-platform-sdk';
42
+
43
+ const inserted = await database.insert('todos', {
44
+ row: { title: 'Call customer', done: false },
45
+ returning: true,
46
+ });
47
+
48
+ await database.updateRows('todos', {
49
+ filters: [{ field: 'id', op: 'eq', value: inserted.data?.[0]?.id }],
50
+ values: { done: true },
51
+ });
52
+
53
+ await database.deleteRows('todos', {
54
+ filters: [{ field: 'done', op: 'eq', value: true }],
55
+ });
56
+ ```
57
+
58
+ Do not call `.table('todos').insert(...)`, `.table('todos').updateRows(...)`,
59
+ or `.table('todos').deleteRows(...)`; those methods do not exist on the query
60
+ builder.
61
+
62
+ ORM export is a tooling helper. It fetches platform schema metadata and returns
63
+ source text; it does not use direct database credentials.
64
64
 
65
65
  ```js
66
66
  import { database } from '@kmlckj/licos-platform-sdk';
@@ -68,11 +68,11 @@ import { database } from '@kmlckj/licos-platform-sdk';
68
68
  const source = await database.exportOrm({ language: 'typescript', orm: 'drizzle' });
69
69
  ```
70
70
 
71
- Studio project database management is exposed through `studioDatabase` for
72
- server-side tooling flows. Use it for tables, rows, controlled SQL, migrations,
73
- sync, and backup. Do not import it into browser/client bundles. Do not put
74
- schema creation or migration logic in normal project runtime request handlers;
75
- run those operations from LICOS agent/tooling flows before the app starts.
71
+ Studio project database management is exposed through `studioDatabase` for
72
+ server-side tooling flows. Use it for tables, rows, controlled SQL, migrations,
73
+ sync, and backup. Do not import it into browser/client bundles. Do not put
74
+ schema creation or migration logic in normal project runtime request handlers;
75
+ run those operations from LICOS agent/tooling flows before the app starts.
76
76
 
77
77
  ```js
78
78
  import { studioDatabase } from '@kmlckj/licos-platform-sdk';
package/dist/index.d.ts CHANGED
@@ -7,6 +7,27 @@ export class PlatformSdkError extends Error {
7
7
  export class ConfigurationError extends PlatformSdkError {}
8
8
  export class ApiError extends PlatformSdkError {}
9
9
 
10
+ export interface RuntimeConfig {
11
+ baseUrl: string;
12
+ projectId: string;
13
+ workspaceId?: string;
14
+ userId?: string;
15
+ token?: string;
16
+ environment: string;
17
+ ownerProjectId?: string;
18
+ ownerWorkspaceId?: string;
19
+ ownerOrgId?: string;
20
+ ownerUserId?: string;
21
+ ownerProjectType?: string;
22
+ ownerApplicationType?: string;
23
+ runtimeEnv?: string;
24
+ currentUserId?: string;
25
+ currentUserOrgId?: string;
26
+ }
27
+
28
+ export function runtimeConfig(options?: { environmentOverrideEnv?: string }): Promise<RuntimeConfig>;
29
+ export function authHeaders(config: RuntimeConfig, contentType?: string): Record<string, string>;
30
+
10
31
  export const DataSourceType: {
11
32
  TEXT: 0;
12
33
  URL: 1;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{PlatformSdkError,ConfigurationError,ApiError}from"./shared.js";export*from"./database.js";export*from"./knowledge.js";export*from"./storage.js";export{studioDatabase}from"./studio-database.js";
1
+ export{PlatformSdkError,ConfigurationError,ApiError}from"./shared.js";export{runtimeConfig,authHeaders}from"./runtime.js";export*from"./database.js";export*from"./knowledge.js";export*from"./storage.js";export{studioDatabase}from"./studio-database.js";
package/dist/runtime.js CHANGED
@@ -1 +1 @@
1
- import{ConfigurationError as e}from"./shared.js";const t=new Map;export function env(e){const t=process.env[e];if("string"!=typeof t)return;return t.trim()||void 0}function n(e,t,n){const r=env(e);if(r)return`http://${r}:${env(t)||n}`}export function platformBaseUrl(){const t=env("LICOS_PLATFORM_API_BASE_URL")||n("AIOS_PLATFORM_SERVICE_HOST","AIOS_PLATFORM_SERVICE_PORT","9100")||n("LICOS_PLATFORM_SERVICE_HOST","LICOS_PLATFORM_SERVICE_PORT","9100")||n("PLATFORM_SERVICE_HOST","PLATFORM_SERVICE_PORT","9100");if(!t)throw new e("LICOS_PLATFORM_API_BASE_URL is not configured");return function(e){let t=e.trim().replace(/\/+$/,"");return t.endsWith("/api/v1")&&(t=t.slice(0,-7)),t.replace(/\/+$/,"")}(t)}export function projectEnvironment(e){const t=((e?env(e):void 0)||"").toLowerCase();if("dev"===t||"prod"===t)return t;const n=(env("LICOS_PROJECT_ENV")||env("AGENT_ENV")||"").toLowerCase();return["prod","production","release"].includes(n)?"prod":"dev"}async function r(n,r,{forceRefresh:o=!1}={}){const s=String(r||"").trim();if(!s)throw new e("project owner user ID is not configured");const i=env("LICOS_AI_AGENT_TOKEN");if(!i)throw new e("platform runtime identity is unavailable");const c=`${n}\n${s}\n${i}`;if(t.has(c)){const e=t.get(c);if(!o)return e;if(e&&"function"==typeof e.then)return e}const a=fetch(`${n}/api/v1/internal/auth/ai-user-token`,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},body:JSON.stringify({userId:s})}).then(async n=>{const r=await n.text();let o=null;try{o=r?JSON.parse(r):null}catch(t){const o=new e("parse AI user token exchange response failed");throw o.status=n.status,o.details=r,o}if(!n.ok){const t=o?.message||r||`AI user token exchange returned ${n.status}`,s=new e(t);throw s.status=n.status,s.details=o,s}const s=function(t){if(!t||"object"!=typeof t)throw new e("AI user token exchange response is not an object");if(void 0!==t.code&&0!==t.code||!1===t.success){const n=new e(t.message||"AI user token exchange failed");throw n.code="number"==typeof t.code?t.code:void 0,n.details=t,n}const n=t.data,r="string"==typeof n?n.trim():String(n?.accessToken||n?.access_token||n?.token||"").trim();if(!r){const n=new e("AI user token exchange response missing accessToken");throw n.details=t,n}return r}(o);return t.set(c,s),s});t.set(c,a);try{return await a}catch(e){throw t.delete(c),e}}export function clearTokenCacheForTests(){t.clear()}export function shouldRefreshUserToken(e){return 401===e?.status||10002===e?.code}export async function refreshRuntimeConfig(e){return{...e,token:await r(e.baseUrl,e.userId,{forceRefresh:!0})}}export async function runtimeConfig({environmentOverrideEnv:t}={}){const n=env("LICOS_PROJECT_ID")||env("AGENT_PROJECT_ID");if(!n)throw new e("LICOS_PROJECT_ID or AGENT_PROJECT_ID is not configured");const o=platformBaseUrl(),s=env("LICOS_USER_ID")||env("AGENT_USER_ID"),i=await r(o,s);return{baseUrl:o,projectId:n,environment:projectEnvironment(t),token:i,workspaceId:env("LICOS_WORKSPACE_ID")||env("AGENT_WORKSPACE_ID"),userId:s}}export function authHeaders(e,t="application/json"){const n={Authorization:`Bearer ${e.token}`};return t&&(n["Content-Type"]=t),e.workspaceId&&(n["X-Workspace-Id"]=e.workspaceId),e.userId&&(n["X-User-Id"]=e.userId),n}
1
+ import{ConfigurationError as e}from"./shared.js";const r=new Map;export function env(e){const r=process.env[e];if("string"!=typeof r)return;return r.trim()||void 0}function n(e,r,n){const t=env(e);if(t)return`http://${t}:${env(r)||n}`}export function platformBaseUrl(){const r=env("LICOS_PLATFORM_API_BASE_URL")||n("AIOS_PLATFORM_SERVICE_HOST","AIOS_PLATFORM_SERVICE_PORT","9100")||n("LICOS_PLATFORM_SERVICE_HOST","LICOS_PLATFORM_SERVICE_PORT","9100")||n("PLATFORM_SERVICE_HOST","PLATFORM_SERVICE_PORT","9100");if(!r)throw new e("LICOS_PLATFORM_API_BASE_URL is not configured");return function(e){let r=e.trim().replace(/\/+$/,"");return r.endsWith("/api/v1")&&(r=r.slice(0,-7)),r.replace(/\/+$/,"")}(r)}export function projectEnvironment(e){const r=((e?env(e):void 0)||"").toLowerCase();if("dev"===r||"prod"===r)return r;const n=(env("LICOS_PROJECT_ENV")||env("AGENT_ENV")||"").toLowerCase();return["prod","production","release"].includes(n)?"prod":"dev"}async function t(n,t,{forceRefresh:o=!1}={}){const s=String(t||"").trim();if(!s)throw new e("project owner user ID is not configured");const c=env("LICOS_AI_AGENT_TOKEN");if(!c)throw new e("platform runtime identity is unavailable");const i=`${n}\n${s}\n${c}`;if(r.has(i)){const e=r.get(i);if(!o)return e;if(e&&"function"==typeof e.then)return e}const I=fetch(`${n}/api/v1/internal/auth/ai-user-token`,{method:"POST",headers:{Authorization:`Bearer ${c}`,"Content-Type":"application/json"},body:JSON.stringify({userId:s})}).then(async n=>{const t=await n.text();let o=null;try{o=t?JSON.parse(t):null}catch(r){const o=new e("parse AI user token exchange response failed");throw o.status=n.status,o.details=t,o}if(!n.ok){const r=o?.message||t||`AI user token exchange returned ${n.status}`,s=new e(r);throw s.status=n.status,s.details=o,s}const s=function(r){if(!r||"object"!=typeof r)throw new e("AI user token exchange response is not an object");if(void 0!==r.code&&0!==r.code||!1===r.success){const n=new e(r.message||"AI user token exchange failed");throw n.code="number"==typeof r.code?r.code:void 0,n.details=r,n}const n=r.data,t="string"==typeof n?n.trim():String(n?.accessToken||n?.access_token||n?.token||"").trim();if(!t){const n=new e("AI user token exchange response missing accessToken");throw n.details=r,n}return t}(o);return r.set(i,s),s});r.set(i,I);try{return await I}catch(e){throw r.delete(i),e}}export function clearTokenCacheForTests(){r.clear()}export function shouldRefreshUserToken(e){return 401===e?.status||10002===e?.code}export async function refreshRuntimeConfig(e){return{...e,token:await t(e.baseUrl,e.userId,{forceRefresh:!0})}}export async function runtimeConfig({environmentOverrideEnv:r}={}){const n=env("LICOS_OWNER_PROJECT_ID"),o=env("LICOS_OWNER_WORKSPACE_ID"),s=env("LICOS_OWNER_USER_ID"),c=env("LICOS_PROJECT_ID")||n||env("AGENT_PROJECT_ID");if(!c)throw new e("LICOS_PROJECT_ID or AGENT_PROJECT_ID is not configured");const i=platformBaseUrl(),I=env("LICOS_USER_ID")||s||env("AGENT_USER_ID"),a=await t(i,I);return{baseUrl:i,projectId:c,environment:projectEnvironment(r),token:a,workspaceId:env("LICOS_WORKSPACE_ID")||o||env("AGENT_WORKSPACE_ID"),userId:I,ownerProjectId:n||c,ownerWorkspaceId:o,ownerOrgId:env("LICOS_OWNER_ORG_ID"),ownerUserId:s||I,ownerProjectType:env("LICOS_OWNER_PROJECT_TYPE"),ownerApplicationType:env("LICOS_OWNER_APPLICATION_TYPE"),runtimeEnv:env("LICOS_RUNTIME_ENV"),currentUserId:env("LICOS_CURRENT_USER_ID"),currentUserOrgId:env("LICOS_CURRENT_USER_ORG_ID")}}export function authHeaders(e,r="application/json"){const n={Authorization:`Bearer ${e.token}`};return r&&(n["Content-Type"]=r),e.workspaceId&&(n["X-Workspace-Id"]=e.workspaceId),e.userId&&(n["X-User-Id"]=e.userId),o(n,"X-Licos-Current-User-Id",e.currentUserId),o(n,"X-Licos-Current-Org-Id",e.currentUserOrgId),o(n,"current_user_id",e.currentUserId),o(n,"current_user_org_id",e.currentUserOrgId),o(n,"X-Licos-Runtime-Env",e.runtimeEnv),o(n,"X-Runtime-Env",e.runtimeEnv),o(n,"runtime_env",e.runtimeEnv),o(n,"owner_project_type",e.ownerProjectType),o(n,"owner_application_type",e.ownerApplicationType),e.ownerProjectId&&(o(n,"X-Licos-Owner-Project-Id",e.ownerProjectId),o(n,"X-Licos-Owner-Workspace-Id",e.ownerWorkspaceId),o(n,"X-Licos-Owner-Org-Id",e.ownerOrgId),o(n,"X-Licos-Owner-User-Id",e.ownerUserId),o(n,"owner_project_id",e.ownerProjectId),o(n,"owner_workspace_id",e.ownerWorkspaceId),o(n,"owner_org_id",e.ownerOrgId),o(n,"owner_user_id",e.ownerUserId),o(n,"X-Project-Id",e.ownerProjectId),o(n,"X-Workspace-Id",e.ownerWorkspaceId),o(n,"X-Tenant-Id",e.ownerOrgId),o(n,"X-User-Id",e.ownerUserId)),n}function o(e,r,n){if("string"!=typeof n)return;const t=n.trim();t&&(e[r]=t)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-platform-sdk",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "LICOS platform SDK package shell for browser and Node runtimes",
5
5
  "author": "kmlckj",
6
6
  "type": "module",