protocol

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package protocol 解析从 sctl 权威 schema 生成并嵌入的协议元数据。

Index

Constants

View Source
const BlockingNone = "none"

BlockingNone 是 blocking 的取值之一:方法收到即执行,不等待人工决定。

View Source
const ConfirmParam = "confirm"

ConfirmParam 是 L1 方法参数里承载显式确认的字段名,值必须恰好是 true。

Variables

View Source
var DefinitionJSON []byte

DefinitionJSON is the sole maintained protocol definition embedded directly from protocol.json.

Functions

This section is empty.

Types

type Action

type Action struct {
	Scope    string `json:"scope"`
	Write    bool   `json:"-"`
	Effect   string `json:"effect"`
	Blocking string `json:"blocking,omitempty"`
	Level    Level  `json:"level"`
	Params   string `json:"params"`
	Result   string `json:"result"`
	Peer     Peer   `json:"peer"`
	// MergeField 是结果中的数组字段名:多个浏览器同时在线时 daemon 按它合并各实例的列表;非列表方法为空。
	MergeField string `json:"mergeField,omitempty"`
	// Internal 标记只供 daemon 内部组件调用的方法(如原始 CDP 中转):它们能以用户登录态驱动任意页面,
	// 所以既不经 /control/call 对外开放,也不注册为 MCP 工具。
	Internal bool `json:"internal,omitempty"`
}

type Crypto

type Crypto struct {
	MAC        string        `json:"mac"`
	KDF        string        `json:"kdf"`
	AEAD       string        `json:"aead"`
	NonceBytes int           `json:"nonceBytes"`
	Encoding   string        `json:"encoding"`
	Context    CryptoContext `json:"context"`
}

type CryptoContext added in v0.2.0

type CryptoContext map[string]string

CryptoContext 把 context 键映射到握手字符串;protocol.json 中每项另带归属标注,只在生成各对端代码时使用。

func (*CryptoContext) UnmarshalJSON added in v0.2.0

func (c *CryptoContext) UnmarshalJSON(data []byte) error

type ErrorCode added in v0.2.0

type ErrorCode struct {
	Code  string `json:"code"`
	Peers []Peer `json:"peers"`
}

type Level added in v0.2.0

type Level string

Level 是方法的破坏级别。daemon 只执行 L1 的确认检查;L2 的人工审批由扩展侧完成, daemon 只是等待它的结果(与 blocking 为 approval/disclosure 的方法同一套阻塞语义)。

const (
	// LevelDirect 直接执行。
	LevelDirect Level = "L0"
	// LevelConfirm 要求调用方在 input 里显式传 confirm: true,否则 daemon 在转发前拒绝。
	LevelConfirm Level = "L1"
	// LevelApproval 要求用户在浏览器里批准后才执行。
	LevelApproval Level = "L2"
)

type Limits

type Limits struct {
	AuthTimeoutMs       int `json:"authTimeoutMs"`
	WriteDecisionTtlMs  int `json:"writeDecisionTtlMs"`
	ExtPairingCodeTtlMs int `json:"extPairingCodeTtlMs"`
	MaxSourceBytes      int `json:"maxSourceBytes"`
	MaxFrameBytes       int `json:"maxFrameBytes"`
	PingIntervalMs      int `json:"pingIntervalMs"`
}

type PairingCode

type PairingCode struct {
	Alphabet string `json:"alphabet"`
	Length   int    `json:"length"`
	Display  string `json:"display"`
}

type Peer added in v0.2.0

type Peer string

Peer 是协议定义的归属对端:方法由哪种扩展实现,错误码与握手常量由哪些扩展使用。

const (
	PeerScriptCat Peer = "scriptcat"
	PeerBrowser   Peer = "browser"
)

type Protocol

type Protocol struct {
	JSONRPCVersion string            `json:"jsonrpc"`
	SchemaVersion  string            `json:"schemaVersion"`
	Transport      Transport         `json:"transport"`
	SessionMethods []SessionMethod   `json:"sessionMethods"`
	Scopes         []string          `json:"scopes"`
	Actions        map[string]Action `json:"methods"`
	// Types 是 protocol.json 的类型定义(JSON Schema 原文),供需要按方法参数派生 schema 的一方使用。
	Types       map[string]json.RawMessage `json:"types"`
	ErrorCodes  []ErrorCode                `json:"errorCodes"`
	Crypto      Crypto                     `json:"crypto"`
	Limits      Limits                     `json:"limits"`
	PairingCode PairingCode                `json:"pairingCode"`
}

func Load

func Load() (*Protocol, error)

Load 解析内嵌的 protocol.json,只解析一次。

type SessionMethod added in v0.2.0

type SessionMethod struct {
	Method string `json:"method"`
	Peers  []Peer `json:"peers"`
}

SessionMethod 是会话层方法或通知(不经 /control/call 转发);Peers 标明哪些对端的会话里会出现它。

type Transport

type Transport struct {
	DefaultURL  string `json:"defaultUrl"`
	DefaultPort int    `json:"defaultPort"`
	Frame       string `json:"frame"`
}

Directories

Path Synopsis
Code generated by protocolgen; DO NOT EDIT.
Code generated by protocolgen; DO NOT EDIT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL