Skip to main content

licos-platform-sdk

LICOS 项目服务端 SDK,提供项目数据库、对象存储、企业知识库、本体和 OAuth 等平台能力。

项目登录身份

有内置登录用项目当前会话,没有内置登录用 LICOS 网页登录。显式配置模式,不按凭证是否存在切换身份:

from licos_platform_sdk import ProjectAuth, get_current_user

project_auth = ProjectAuth("platform")
token = project_auth.user_token(request)
user = get_current_user(user_token=token)

platform 模式接受调用方明确提供的 Bearer Token,或浏览器登录桥签发的 X-Licos-User-Ticket;两者同时出现会报错。票据只兑换一次,绑定 LICOS_PROJECT_ID,服务端使用 LICOS_AI_AGENT_TOKEN 兑换;不会根据初始化用户换 Token。

内置登录使用 ProjectAuth("builtin", resolve_builtin_token=已有会话取值函数),取值函数只返回该登录用户已授权的 LICOS Token。它缺失或失效时返回内置登录错误,不读取平台票据或容器用户。业务自签 JWT 不能直接传给平台 SDK。

Agent/Workflow 的请求节点使用 ctx.identity.user_token。异步 HTTP 处理器用 await asyncio.to_thread(project_auth.user_token, request) 完成票据兑换,避免阻塞事件循环。

沿用现有 OAuth 授权范围与接口权限。凭证无权访问目标接口时返回现有鉴权错误,不扩大权限或换用其他身份。

当前使用者信息(0.6.1 起)

from licos_platform_sdk import get_current_user

# token 是当前请求的用户 Bearer Token,不包含 "Bearer " 前缀。
sys_user = get_current_user(user_token=token)
print(sys_user["displayName"])
print(sys_user["departments"])
print(sys_user["primaryPosition"])

返回对象与低代码系统变量 sys_user 相同,保留平台的 camelCase 字段名: id、username、displayName、avatarUrl、tenantId、tenantName、 primaryDepartment、departments、organizationAssignments、primaryPosition、primaryJobTitle。 部门包含 ID、名称、组织路径、ID 路径及主部门标志;组织任职包含岗位、职务和部门负责人标志。

SDK 自动读取 LICOS_PLATFORM_API_BASE_URL、LICOS_AI_AGENT_TOKEN 和项目工作空间。 workspace_id 可由服务端指定执行工作空间;默认依次读取 LICOS_WORKSPACE_ID、 LICOS_OWNER_WORKSPACE_ID、AGENT_WORKSPACE_ID。企业按执行工作空间确定,与低代码一致。 无企业时企业字段为 None;未加入执行企业的使用者,部门和任职为空,不能返回项目所有者的信息。

多用户服务每次传入当前请求的 Token。智能体/工作流可传 ctx.identity.user_token; 在异步节点中使用 await asyncio.to_thread(get_current_user, user_token=token)。 结果不做全局缓存。Token 无效时直接报错,由调用方处理登录失效。

从 0.7.0 起必须显式传入 user_token。LICOS_CURRENT_USER_ID 只是容器初始化用户,不能代表网页登录者。 本接口仅供服务端使用;LICOS_AI_AGENT_TOKEN 不得发送到浏览器。

企业本体

本体接口仅供项目服务端使用,通过平台网关 /ontology-api 调用。先搜索当前用户的授权目录,再按返回的参数 Schema 和模式调用:

from licos_platform_sdk import ontology

# token 来自本次请求的认证会话,不含 Bearer 前缀。
catalog = ontology.search_tools("查询设备状态", user_token=token)
selected = next(
    item for item in catalog["items"]
    if item["selection"] == "MATCH" and item["mode"] == "READ"
    and item["definition"]["function"]["name"] == requested_tool_name
)
result = ontology.invoke_tool(
    selected["definition"]["function"]["name"],
    arguments_from_validated_request,
    user_token=token,
    catalog_version=catalog["catalogVersion"],
    required_mode="READ",
)
  • elementId 是已解析的部署实例 ID,用于上下文、属性、关系和数据查询。objectTypeId 从实例上下文读取,是对象模板 ID,与 template.templateId 一致;不能混用。
  • 函数与动作列表使用条目的 id,分别作为调用参数 functionId / actionTypeId。返回不再提供 actionTypeId、functionKind 或 implementationRef,新增的业务 definition 保持原始 JSON。
  • 动作预览携带选定部署实例的 objectElementId、真实实例键 objectKey 和参数。用户确认后使用同一预览的 confirmationId 执行,目标或参数变化时重新预览。
  • SDK 严格按动态目录校验。动作列表 AI 接口目前只接受 objectTypeId,列表按模板查询,预览指定 objectElementId;列表按实例过滤需要上游补齐接口契约。
  • 实时订阅使用 ontology.subscribe_realtime(element_ids, user_token=token);HTTP 401/403 终止订阅,由调用方更新 Token。异步服务通过工作线程调用同步 SDK。

身份选择(0.7.0 起)

LICOS_CURRENT_USER_ID 表示容器启动时配置的执行用户。SDK 不用它推断当前网页登录者,也不从进程级 LICOS_USER_TOKEN 取得本次请求凭证。项目身份指运行时配置的项目所有者身份,按接口选择:

接口 调用身份
get_current_user 必须显式传入本次用户的 user_token
enterprise_knowledge 全部接口 必须传 user_token,企业范围和权限由平台认证结果确定
本体 search_tools、resolve_tool、invoke_tool、subscribe_realtime 必须传执行用户的 user_token;网页登录请求使用本次登录会话的 Token
普通 knowledge 接口 默认项目身份;需要用户权限时显式传 user_token
数据库、对象存储、oauth 应用管理 项目身份
oauth_runtime 授权码交换、刷新、userinfo、撤销 按 OAuth 协议传对应凭证,不使用容器用户替代

user_token 不含 Bearer 前缀。用户标识、名称和企业信息以平台认证结果为准;项目所有者、工作空间等资源归属字段单独保留。

from licos_platform_sdk import enterprise_knowledge, get_current_user, knowledge, ontology

# token 来自本次请求的认证会话。
user = get_current_user(user_token=token)
resources = enterprise_knowledge.tree(user_token=token)
catalog = ontology.search_tools('设备状态', user_token=token)
result = knowledge.search('资料', user_token=token)

网页登录请求缺少 Token 时,业务入口应返回登录错误,不能改用容器用户或项目所有者。每次调用显式传入 Token,不把请求 Token 或用户 ID 写入 os.environ,也不跨用户共享请求身份。

显式传入的 Token 失效时直接返回鉴权错误,由调用方更新登录凭证。实时订阅遇到网络中断会携带原 Token 重新检查授权并订阅,401/403 终止;取得新 Token 后重新创建订阅。后台常驻的项目订阅由调用方显式传项目所有者 Token。

独立 licos-platform CLI 的用户操作才默认按 LICOS_CURRENT_USER_ID 和运行时服务凭证换 Token。HTTP 服务通过 CLI 调用用户接口时使用 --token-stdin,不依赖容器默认用户。升级到 0.7.0 时,已有企业知识库和本体调用必须补上 user_token 参数。

Metadata

Release files for licos-platform-sdk 0.7.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for licos-platform-sdk 0.7.5
File Size Uploaded
licos_platform_sdk-0.7.5.tar.gz 50.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for licos-platform-sdk 0.7.5
File Interpreter ABI Platform
licos_platform_sdk-0.7.5-py3-none-any.whl Python 3 none any Details

Total release size: 95.2 kB

Release files / licos_platform_sdk-0.7.5.tar.gz

Download URL licos_platform_sdk-0.7.5.tar.gz
Size 50.6 kB
Tags Source
SHA-256 checksum
How to use checksums
70229460dbf1ae426f6dc732f1180a577f530fe2d8539fb7b9113165d8a7e71e
BLAKE2b-256 checksum
How to use checksums
16e3bfdafcf27eaee96c206b26ffcf9a7a89c468149e370f4c56ba7a33921f18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.7

Release files / licos_platform_sdk-0.7.5-py3-none-any.whl

Download URL licos_platform_sdk-0.7.5-py3-none-any.whl
Size 44.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cb7dfba46f192fa80b7790f1d13a4dac47c707f27b7774cbc3f922e7c5c9b30
BLAKE2b-256 checksum
How to use checksums
8b1fb8a6800768a82f80f1e1859def9bc8ee83f80982c4f4aba95cb33939e5bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.7

Release history Release notifications | RSS feed

This release

0.7.5 This release

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.9

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page