README

morning-start/prism/sdk does not have a README file

#
Context

pub struct Context {
system_prompt : String?
messages : Array[SdkMessage]
tools : Array[SdkTool]?
}

Context — 对话上下文

#
Context::add_assistant

fn Context::add_assistant(self : Context, text : String) -> Context

添加助手消息

#
Context::add_system

fn Context::add_system(self : Context, prompt : String) -> Context

设置系统指令

#
Context::add_tool_result

fn Context::add_tool_result(self : Context, tool_use_id : String, content : String, is_error : Bool) -> Context

注入工具执行结果(Agent 循环:执行工具后继续对话)

#
Context::add_tools

fn Context::add_tools(self : Context, tools : Array[SdkTool]) -> Context

添加工具

#
Context::add_user

fn Context::add_user(self : Context, text : String) -> Context

添加用户消息

#
Context::new

fn Context::new() -> Context

#
ConversionMeta

pub struct ConversionMeta {
source_provider : String
diagnostics : Array[
ConversionDiagnostic
]
provider_payload : Json?
extra_fields : Map[String, Json]?
}

ConversionMeta — 转换来源元信息(D8)

回答"这个 LUX 值是从哪个协议解码来的",并附带转换损失诊断 与厂商特有字段(provider_payload / extra_fields)。 开发者可用 source_provider 做按需特判(if 分支),主路径代码仍只写一次。

#
ConversionMeta::new

fn ConversionMeta::new(source_provider : String, diagnostics : Array[
ConversionDiagnostic
], provider_payload : Json?, extra_fields : Map[String, Json]?) -> ConversionMeta

#
ConvertMetaResult

pub struct ConvertMetaResult {
value : String
meta : ConversionMeta
}

ConvertMetaResult — convert 结果:目标协议 JSON + 来源元信息(D8)

#
ConvertMetaResult::meta

#
ConvertMetaResult::new

fn ConvertMetaResult::new(value : String, meta : ConversionMeta) -> ConvertMetaResult

#
ConvertMetaResult::value

fn ConvertMetaResult::value(self : ConvertMetaResult) -> String

#
DecodedResponse

pub struct DecodedResponse {
text : String
meta : ConversionMeta
}

DecodedResponse — 解码结果:主路径文本 + 溯源元信息

#
DecodedResponse::new

fn DecodedResponse::new(text : String, meta : ConversionMeta) -> DecodedResponse

#
FieldConstraint

pub struct FieldConstraint {
min_val : Double?
max_val : Double?
required : Bool
allowed_values : Array[String]?
}

FieldConstraint — 单字段约束

#
FieldConstraint::new

fn FieldConstraint::new(min_val : Double?, max_val : Double?, required : Bool, allowed_values : Array[String]?) -> FieldConstraint

#
Prism

pub struct Prism {
provider : String
}

Prism — 主实例

#
Prism::capability

fn Prism::capability(_self : Prism, provider_name : String) ->
ProviderCapability
?

查询指定 provider 的能力声明(基于注册表)

#
Prism::complete

fn Prism::complete(self : Prism, text : String, opts : PrismOptions, send : (String) -> Result[String, String]) -> Result[String, String]

L1 零配置:文本进、文本出(HTTP 由 Host 注入 send)

#
Prism::decode_response

fn Prism::decode_response(self : Prism, json_str : String) -> Result[String, String]

将提供商 JSON 响应解码为纯文本(L1:JSON 进,文本出)

#
Prism::decode_response_with_diagnostics

fn Prism::decode_response_with_diagnostics(self : Prism, json_str : String) -> Result[
ConversionResult
[
LucentResponse
], String]

将提供商响应解码为完整 LucentResponse,并返回结构化校验诊断。

#
Prism::decode_response_with_meta

fn Prism::decode_response_with_meta(self : Prism, json_str : String) -> Result[DecodedResponse, String]

将提供商 JSON 响应解码为 DecodedResponse(文本 + 来源元信息)。

meta.source_provider 为运行时从注册表解析的规范 provider 名 (精确匹配/别名/模型正则),开发者可据此做按需特判。

#
Prism::decode_sse

fn Prism::decode_sse(self : Prism, sse_str : String) -> Result[Array[PrismEvent], String]

将提供商 SSE 事件解码为 PrismEvent 数组

#
Prism::encode_request

fn Prism::encode_request(self : Prism, text : String, opts : PrismOptions) -> Result[String, String]

将文本请求编码为提供商 JSON(L1:文本进,JSON 出)

#
Prism::encode_request_with_diagnostics

fn Prism::encode_request_with_diagnostics(self : Prism, text : String, opts : PrismOptions) -> Result[
ConversionResult
[String], String]

将文本请求编码为提供商 JSON,并返回结构化校验诊断。

#
Prism::encode_stream_request

fn Prism::encode_stream_request(self : Prism, text : String, opts : PrismOptions) -> Result[String, String]

将文本请求编码为流式提供商 JSON

#
Prism::new

fn Prism::new() -> Prism

#
Prism::stream

fn Prism::stream(self : Prism, ctx : Context, send : (String) -> Result[String, String]) -> Result[Array[PrismEvent], String]

L2 Agent 循环:流式请求 + 5 事件解码(HTTP 由 Host 注入 send)

#
Prism::with_provider

fn Prism::with_provider(_self : Prism, name : String) -> Prism

设置 provider 名称

#
PrismEvent

pub(all) enum PrismEvent {
TextDelta(String)
ToolCall(PrismToolCall)
ToolResult(PrismToolResult)
Thinking(PrismThinking)
Finish(PrismFinishReason)
}

PrismEvent — 流事件枚举

#
PrismFinishReason

pub(all) enum PrismFinishReason {
Stop
Length
ToolCalls
ContentFilter
Error
}

PrismFinishReason — 结束原因

#
PrismOptions

pub struct PrismOptions {
model : String?
temperature : Double?
max_tokens : Int?
store : Bool?
extras : Map[String, Json]?
}

PrismOptions — SDK 请求选项

#
PrismOptions::default

fn PrismOptions::default() -> PrismOptions

#
PrismOptions::new

fn PrismOptions::new(model : String?, temperature : Double?, max_tokens : Int?, store : Bool?, extras : Map[String, Json]?) -> PrismOptions

#
PrismThinking

pub struct PrismThinking {
text : String
signature : String?
redacted : Bool
}

PrismThinking — 推理内容

#
PrismToolCall

pub struct PrismToolCall {
id : String
name : String
arguments_json : String
}

PrismToolCall — 工具调用

#
PrismToolResult

pub struct PrismToolResult {
tool_use_id : String
content : String
is_error : Bool
}

PrismToolResult — 工具结果

#
ProviderRegistration

#
ProviderSchema

pub struct ProviderSchema {
provider_name : String
temperature : FieldConstraint
top_p : FieldConstraint
top_k : FieldConstraint
max_output_tokens : FieldConstraint
resp_min_choices : Int
supports_tools : Bool
supports_system_instruction : Bool
supported_reasoning_efforts : Array[String]?
extra_checks : Array[() -> Array[String]]?
}

ProviderSchema — 单个 Provider 的请求/响应字段约束集合

#
ProviderSchema::anthropic

fn ProviderSchema::anthropic() -> ProviderSchema

Anthropic Messages

#
ProviderSchema::azure

Azure OpenAI

#
ProviderSchema::gemini

Google Gemini

#
ProviderSchema::openai

OpenAI Chat Completions / Responses

#
ProviderSchema::validate_request

校验请求是否符合 Provider 的字段约束 返回校验错误列表,空列表表示校验通过

#
ProviderSchema::validate_response

校验响应是否符合 Provider 的字段约束 返回校验错误列表,空列表表示校验通过

#
SdkMessage

pub struct SdkMessage {
role : String
content : String
tool_use_id : String?
is_error : Bool?
}

SdkMessage — SDK 层的消息表示

#
SdkMessage::new

fn SdkMessage::new(role : String, content : String) -> SdkMessage

#
SdkMessage::tool_result

fn SdkMessage::tool_result(tool_use_id : String, content : String, is_error : Bool) -> SdkMessage

构造工具结果消息(Agent 循环注入工具执行结果用)

#
SdkTool

pub struct SdkTool {
name : String
description : String
parameters_json : String
}

SdkTool — SDK 层的工具定义

#
SdkTool::new

fn SdkTool::new(name : String, description : String, parameters_json : String) -> SdkTool

#
all_providers

fn all_providers() -> Array[ProviderRegistration]

所有已注册的 Provider

新增 Provider 只需在 build_providers 中追加。 注意:条目顺序影响匹配优先级(精确匹配优先于正则匹配)。

每次调用返回独立数组,调用方可安全修改;内部匹配路径改用 providers_cache 避免重复构造。

#
context_to_lux_request

fn context_to_lux_request(ctx : Context, model : String, opts : PrismOptions) ->
LucentRequest

将 Context 转为 LucentRequest(SDK 内部使用)

#
convert_request

fn convert_request(source : String, json_str : String, target : String) -> Result[
ConversionResult
[String], String]

请求:source 协议 JSON → target 协议 JSON(带诊断)

#
convert_response

fn convert_response(source : String, json_str : String, target : String) -> Result[
ConversionResult
[String], String]

响应:source 协议 JSON → target 协议 JSON(带诊断)

#
convert_response_with_meta

fn convert_response_with_meta(source : String, json_str : String, target : String) -> Result[ConvertMetaResult, String]

响应转换(带来源元信息):source 协议 JSON → target 协议 JSON。 meta.source_provider 为注册表解析的规范 source 名(别名/模型正则归一)。

#
convert_stream

fn convert_stream(source : String, sse_str : String, target : String) -> Result[
ConversionResult
[String], String]

流式:source 协议 SSE → target 协议 SSE(事件级转换,带诊断)

#
get_schema

fn get_schema(provider : String) -> ProviderSchema?

根据 provider 名获取对应 schema(自动匹配主名、别名与模型名)

#
list_provider_names

fn list_provider_names() -> Array[String]

获取所有 Provider 的主名称列表

#
match_by_model

fn match_by_model(model_name : String) -> ProviderRegistration?

根据 model_name 匹配 Provider(通过 model_pattern 子串匹配)

返回最具体的匹配(pattern 中 * 越多越优先),或 None。

#
match_provider_name

fn match_provider_name(provider_name : String) -> ProviderRegistration?

根据名称匹配 Provider

匹配策略:
  1. 精确匹配 name
  2. 匹配 aliases 中的别名
  3. 均未命中时,把输入当作模型名走 match_by_model 回退

若只想按模型名匹配(不做名称/别名命中),直接调用 match_by_model