{"modulePath":"github.com/xmapst/taskflow","version":"v0.0.0-20261127030116-2fa33bcfeb3e","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\nPackage api holds the wire types shared by the HTTP API and its clients: the response envelope and the multiplexed stream frames.\n\n## Constants\n\n```go\nconst (\n\tExecConsoleStart = \"TASK_FLOW::CONSOLE::START\"\n\tExecConsoleDone  = \"TASK_FLOW::CONSOLE::DONE\"\n)\n```\nThese markers delimit console output in stored step logs.\n\n```go\nconst (\n\t// StreamUpdate carries a fresh value for a subscription.\n\tStreamUpdate = \"update\"\n\t// StreamDone ends a subscription that will not produce anything else.\n\tStreamDone = \"done\"\n\t// StreamError reports a failed request or a subscription that broke.\n\tStreamError = \"error\"\n\t// StreamResult carries the reply to a call.\n\tStreamResult = \"result\"\n)\n```\nServer-to-client frame events.\n\n```go\nconst (\n\t// ActionSubscribe opens a long-lived subscription to a topic.\n\tActionSubscribe = \"subscribe\"\n\t// ActionUnsubscribe closes the subscription opened by the request with the same ID.\n\tActionUnsubscribe = \"unsubscribe\"\n\t// ActionCall invokes a one-shot method and is answered by a result or error frame.\n\tActionCall = \"call\"\n\t// ActionPing is answered by an empty result frame; it checks the link is alive.\n\tActionPing = \"ping\"\n)\n```\nClient-to-server actions of a StreamRequest.\n\n```go\nconst (\n\t// TopicEvent streams worker events.\n\tTopicEvent = \"event\"\n\t// TopicSystem streams resource metrics.\n\tTopicSystem = \"system\"\n\t// TopicTasks streams the paged task list.\n\tTopicTasks = \"tasks\"\n\t// TopicTask streams one task's detail.\n\tTopicTask = \"task\"\n\t// TopicSteps streams the step list of a task.\n\tTopicSteps = \"steps\"\n\t// TopicStep streams one step's detail.\n\tTopicStep = \"step\"\n\t// TopicStepLog streams one step's log output.\n\tTopicStepLog = \"step-log\"\n\t// TopicTerminalSessions streams the live terminal sessions.\n\tTopicTerminalSessions = \"terminal-sessions\"\n\t// TopicTerminalWatch streams the output of one live terminal session.\n\tTopicTerminalWatch = \"terminal-watch\"\n\t// TopicTerminalReplay streams a recorded terminal session.\n\tTopicTerminalReplay = \"terminal-replay\"\n)\n```\nTopics a client can subscribe to over the multiplexed stream. The values are the wire names; the web UI and any other client send them verbatim.\n\n```go\nconst (\n\t// MethodTaskCreate creates a task.\n\tMethodTaskCreate = \"task.create\"\n\t// MethodTaskManage pauses, resumes or kills a task.\n\tMethodTaskManage = \"task.manage\"\n\t// MethodTaskDelete deletes a task.\n\tMethodTaskDelete = \"task.delete\"\n\t// MethodTaskDump exports a task definition.\n\tMethodTaskDump = \"task.dump\"\n\t// MethodStepManage pauses, resumes or kills a step.\n\tMethodStepManage = \"step.manage\"\n\t// MethodSystemUpdate resizes the worker pool.\n\tMethodSystemUpdate = \"system.update\"\n\t// MethodTerminalDisconnect closes a live terminal session.\n\tMethodTerminalDisconnect = \"terminal.disconnect\"\n\t// MethodReplayList lists the recorded terminal sessions.\n\tMethodReplayList = \"replay.list\"\n)\n```\nOne-shot calls a client can make over the multiplexed stream.\n\n```go\nconst MessageSeparator = \"; \"\n```\n\n## Variables\n\n```go\nvar (\n\tErrExecTimeOut = errors.New(\"forced termination by timeout\")\n\tErrExecKilled  = errors.New(\"artificial force kill\")\n)\n```\n\n```go\nvar JSONDuration = json.JoinOptions(\n\tjson.WithMarshalers(json.MarshalFunc(func(value time.Duration) ([]byte, error) {\n\t\treturn json.Marshal(int64(value))\n\t})),\n\tjson.WithUnmarshalers(json.UnmarshalFunc(func(data []byte, value *time.Duration) error {\n\t\tif len(data) \u003e 0 \u0026\u0026 data[0] == '\"' {\n\t\t\tvar text string\n\t\t\tif err := json.Unmarshal(data, \u0026text); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tduration, err := time.ParseDuration(text)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\t*value = duration\n\t\t\treturn nil\n\t\t}\n\t\treturn json.Unmarshal(data, (*int64)(value))\n\t})),\n)\n```\nJSONDuration is the JSON option set of the HTTP API for time.Duration: it is written as integer nanoseconds and read as either nanoseconds or a Go duration string such as \"30s\". Pass it to json.Marshal and json.Unmarshal when encoding requests or decoding responses that carry durations.\n\n```go\nvar ServiceName = \"taskflow\"\n```\n\n## Types\n\n```go\ntype Code int\n```\nCode 响应状态码\n\n```go\nconst (\n\tCodeSuccess Code = 0\n\tCodeRunning Code = iota + 1000\n\tCodeFailed\n\tCodeNoData\n\tCodePending\n\tCodePaused\n\tCodeSkipped\n)\n```\n\n```go\ntype ExecCode int64\n```\n\n```go\nconst (\n\tExecCodeSuccess   ExecCode = 0\n\tExecCodeFailed    ExecCode = -1\n\tExecCodeSkipped   ExecCode = -2\n\tExecCodeKilled    ExecCode = -997\n\tExecCodeTimeout   ExecCode = -998\n\tExecCodeSystemErr ExecCode = -999\n)\n```\n\n```go\nfunc (e ExecCode) Int64() int64\n```\n\n```go\ntype IResponse[T any] interface {\n\tWithCode(code Code) IResponse[T]\n\tWithError(err error) IResponse[T]\n\tWithData(data T) IResponse[T]\n\tWithMessage(msg string) IResponse[T]\n\tGetCode() Code\n\tGetData() T\n}\n```\nIResponse 定义构造和读取 API 响应的方法。\n\n```go\nfunc Fail[T any](message string) IResponse[T]\n```\nFail 创建失败响应的便捷方法\n\n```go\nfunc NewResponse[T any]() IResponse[T]\n```\nNewResponse 创建新的成功响应对象。\n\n```go\nfunc Success[T any](data T) IResponse[T]\n```\nSuccess 创建成功响应的便捷方法\n\n```go\nfunc WithCode[T any](code Code) IResponse[T]\n```\nWithCode 创建带状态码的响应\n\n```go\nfunc WithData[T any](data T) IResponse[T]\n```\nWithData 创建带数据的成功响应\n\n```go\nfunc WithError[T any](err error) IResponse[T]\n```\nWithError 创建错误响应\n\n```go\ntype Messages []string\n```\nMessages 消息列表类型\n\n```go\nfunc (msgs Messages) MarshalJSON() ([]byte, error)\n```\nMarshalJSON 自定义 JSON 序列化\n\n```go\nfunc (msgs Messages) MarshalYAML() (any, error)\n```\nMarshalYAML 自定义 YAML 序列化\n\n```go\nfunc (msgs Messages) String() string\n```\nString 将消息列表转为字符串\n\n```go\nfunc (msgs *Messages) UnmarshalJSON(data []byte) error\n```\nUnmarshalJSON 自定义 JSON 反序列化\n\n```go\nfunc (msgs *Messages) UnmarshalYAML(unmarshal func(any) error) error\n```\nUnmarshalYAML 自定义 YAML 反序列化\n\n```go\ntype Response[T any] struct {\n\tCode      Code     `json:\"code\" yaml:\"code\"`\n\tMessage   Messages `json:\"msg\" yaml:\"message\" swaggertype:\"string\"`\n\tTimestamp int64    `json:\"timestamp\" yaml:\"timestamp\"`\n\tData      T        `json:\"data\" yaml:\"data\"`\n}\n```\nResponse 是 API 响应的通用包络。\n\n```go\nfunc (r *Response[T]) GetCode() Code\n```\nGetCode 获取状态码\n\n```go\nfunc (r *Response[T]) GetData() T\n```\nGetData 获取数据\n\n```go\nfunc (r *Response[T]) WithCode(code Code) IResponse[T]\n```\nWithCode 设置业务状态码。\n\n```go\nfunc (r *Response[T]) WithData(data T) IResponse[T]\n```\nWithData 设置响应数据\n\n```go\nfunc (r *Response[T]) WithError(err error) IResponse[T]\n```\nWithError 设置错误信息\n\n```go\nfunc (r *Response[T]) WithMessage(msg string) IResponse[T]\n```\nWithMessage 添加自定义消息\n\n```go\ntype StreamFrame struct {\n\tID      string `json:\"id,omitempty\"`\n\tTopic   string `json:\"topic,omitempty\"`\n\tEvent   string `json:\"event\"`\n\tCode    Code   `json:\"code,omitzero\"`\n\tMessage string `json:\"message,omitempty\"`\n\tData    any    `json:\"data,omitempty\"`\n}\n```\nStreamFrame is one server-to-client frame. Sessions fill Code, Message and Data; the transport adds ID, Topic and Event.\n\n```go\ntype StreamRequest struct {\n\tID     string         `json:\"id\"`\n\tAction string         `json:\"action\"`\n\tTopic  string         `json:\"topic\"`\n\tMethod string         `json:\"method\"`\n\tParams jsontext.Value `json:\"params\"`\n}\n```\nStreamRequest is one client-to-server frame. Params is passed verbatim to the topic or method that the request addresses.\n\n","path":"github.com/xmapst/taskflow/api","name":"api","synopsis":"Package api holds the wire types shared by the HTTP API and its clients: the response envelope and the multiplexed stream frames.","isRedistributable":true}
