{"modulePath":"github.com/eadwinCode/flow-sdk","version":"v0.10.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package flow\n\nPackage flow is the Go SDK for clevix-worker, a durable workflow engine on Cloudflare. Its API follows Inngest's inngestgo.\n\nMake a client with NewClient, add functions with CreateFunction, and serve them with client.Serve(), which returns an http.Handler for your app's one endpoint (for example /api/flow). Steps are in the step package, parallel steps in the group package.\n\n## Constants\n\n```go\nconst DefaultBaseURL = \"https://worker.flow.clevixstudio.com\"\n```\nDefaultBaseURL is the engine URL when neither ClientOpts.BaseURL nor FLOW\\_BASE\\_URL is set. Self-hosters set FLOW\\_BASE\\_URL.\n\n```go\nconst Version = \"0.10.0\"\n```\nVersion is this SDK's version, sent in the manifest.\n\n## Variables\n\n```go\nvar ErrStreamClosed = errors.New(\"flow: stream is closed\")\n```\nErrStreamClosed is the error for an append to a closed stream. Check for it with errors.Is.\n\n```go\nvar ErrStreamGone = errors.New(\"flow: stream is gone\")\n```\nErrStreamGone is the error for a stream that does not exist: never opened, deleted, or past its TTL or grace time. Check for it with errors.Is.\n\n## Functions\n\n```go\nfunc BoolPtr(b bool) *bool\n```\nBoolPtr returns a pointer to b.\n\n```go\nfunc IntPtr(i int) *int\n```\nIntPtr returns a pointer to i.\n\n```go\nfunc NoRetryError(err error) error\n```\nNoRetryError wraps err so it is not retried. Returned from a step.Run callback, the step fails at once. Returned from the handler, the run fails at once.\n\n```go\nfunc RetryAtError(err error, at time.Time) error\n```\nRetryAtError wraps err so the next attempt runs at the given time.\n\n```go\nfunc StrPtr(s string) *string\n```\nStrPtr returns a pointer to s.\n\n## Types\n\n```go\ntype AppManifest struct {\n\tAppID string `json:\"appId\"`\n\t// URL is left out of the sync at boot: the engine keeps the URL it has.\n\tURL       string           `json:\"url,omitempty\"`\n\tSDK       *SDKInfo         `json:\"sdk,omitempty\"`\n\tFunctions []FunctionConfig `json:\"functions\"`\n\t// ManifestHash is the SDK's hash of SDK and Functions (see ManifestHash).\n\tManifestHash string `json:\"manifestHash,omitempty\"`\n}\n```\nAppManifest is what the app sends on sync and returns on GET.\n\n```go\ntype BatchEvents struct {\n\tMaxSize int\n\tTimeout time.Duration\n\tKey     *string\n\tIf      *string\n}\n```\nBatchEvents runs the function with up to MaxSize events, or after Timeout.\n\n```go\ntype CancelOn struct {\n\tEvent string\n\t// Match is a field path in both events, for example \"data.orderId\".\n\tMatch *string\n\t// If is an expression over event (the trigger) and async (the new event).\n\tIf *string\n\t// Timeout stops listening after this long. Zero means as long as the run lives.\n\tTimeout time.Duration\n}\n```\nCancelOn cancels a run when a matching event arrives.\n\n```go\ntype CancelOpts struct {\n\t// RunID cancels one run.\n\tRunID string\n\t// Function is the function's own ID. Needed with SingletonKey and Tag.\n\tFunction string\n\t// SingletonKey cancels the run that holds this singleton key. Set when\n\t// not nil.\n\tSingletonKey any\n\t// Tag cancels the runs with this tag value: one name and its value.\n\tTag map[string]string\n\t// Status, with Tag only, cancels only runs in these active statuses.\n\t// Nil: every active status. Empty but not nil is an error.\n\tStatus []string\n\t// Cursor, with Tag only, goes on after the page before: pass\n\t// CancelResult.Next. Sent when not empty.\n\tCursor string\n}\n```\nCancelOpts says which runs Runs().Cancel cancels. Set exactly one of RunID, SingletonKey and Tag.\n\n```go\ntype CancelResult struct {\n\t// Cancelled are the runs it cancelled.\n\tCancelled []string `json:\"cancelled\"`\n\t// NotActive are runs that had ended already, or are not this app's.\n\tNotActive []string `json:\"notActive\"`\n\t// More is true when more runs match a Tag than one call cancels (500).\n\t// Call again with Next as CancelOpts.Cursor.\n\tMore bool `json:\"more\"`\n\t// Next is the cursor for the next call by Tag. Empty when there is no\n\t// more.\n\tNext string `json:\"next\"`\n}\n```\nCancelResult says what Runs().Cancel did.\n\n```go\ntype Client struct {\n\t// contains filtered or unexported fields\n}\n```\nClient holds an app's functions and talks to the engine.\n\n```go\nfunc NewClient(opts ClientOpts) (*Client, error)\n```\nNewClient makes a client. It fails if AppID or a signing key is not valid.\n\n```go\nfunc (c *Client) AppID() string\n```\nAppID returns the app's ID.\n\n```go\nfunc (c *Client) Close()\n```\nClose stops the sync checks that Serve started, and waits until a check on its way has ended. Call it when the server shuts down. Serve still answers after Close; it just checks no more.\n\n```go\nfunc (c *Client) Functions() Functions\n```\nFunctions returns the client's functions API.\n\n```go\nfunc (c *Client) Manifest(serveURL string) AppManifest\n```\nManifest builds the app's manifest with serveURL as the app URL.\n\n```go\nfunc (c *Client) ManifestHash() string\n```\nManifestHash is the SDK's hash of the app's manifest: \"v1:\" and the sha256 of its SDK and functions as JSON with sorted keys. The URL is left out, so every copy of the app has the same hash. The engine stores it on sync, and the sync at boot syncs only when the engine has a different one.\n\n```go\nfunc (c *Client) Realtime() Realtime\n```\nRealtime returns the client's realtime API.\n\n```go\nfunc (c *Client) Runs() Runs\n```\nRuns returns the client's runs API.\n\n```go\nfunc (c *Client) Send(ctx context.Context, event Event) (string, error)\n```\nSend sends one event and returns its ID.\n\n```go\nfunc (c *Client) SendMany(ctx context.Context, events []Event) ([]string, error)\n```\nSendMany sends up to 100 events in one request and returns their IDs.\n\n```go\nfunc (c *Client) Serve() http.Handler\n```\nServe returns the http.Handler for the app's one endpoint:\n\n  - POST runs a function (signed by the engine).\n  - PUT syncs: sends the manifest to the engine and returns its answer. Signed like GET; in dev mode an unsigned PUT works too.\n  - GET returns the manifest (signed GET with an empty body).\n\nWithout a signing key, and not in dev mode, it answers every request with 500 NoSigningKey.\n\nThe first call also starts the sync at boot in the background (see ClientOpts.NoSyncOnBoot), so call Serve after the functions are made. The checks go on until Close.\n\n```go\nfunc (c *Client) Start(ctx context.Context, functionID string, opts StartOpts) (StartResult, error)\n```\nStart starts a run of one of this app's functions now, without an event name to match (POST /v1/functions/{id}/start). functionID is the function's own ID, as in FunctionOpts.ID. Singleton, throttle, concurrency and priority apply; rate limit, debounce and batching do not.\n\nThe run exists when Start returns, so a Runs().Cancel right after it can not miss it. Start does not fail when no run started: then Started is false and Reason says why. It fails for any answer other than 200 (for example 429 when the workspace sends too many events a second).\n\n```go\nfunc (c *Client) Streams() Streams\n```\nStreams returns the client's streams API.\n\n```go\nfunc (c *Client) Sync(ctx context.Context, serveURL string) (int, []byte, error)\n```\nSync sends the manifest to the engine (PUT {base}/apps/{appId}/sync) and returns the engine's status code and body.\n\n```go\ntype ClientOpts struct {\n\t// AppID names the app. Required.\n\tAppID string\n\t// SigningKey checks calls from the engine and signs sync. Env: FLOW_SIGNING_KEY.\n\tSigningKey *string\n\t// SigningKeyFallback is the old key while rotating. Env: FLOW_SIGNING_KEY_FALLBACK.\n\tSigningKeyFallback *string\n\t// EventKey is used to send events. Env: FLOW_EVENT_KEY.\n\tEventKey *string\n\t// BaseURL is the engine URL. Env: FLOW_BASE_URL. Default: DefaultBaseURL.\n\tBaseURL *string\n\t// Dev turns off signature checks. With no keys it also calls the engine with\n\t// none, which only a local engine (local mode) takes. Env: FLOW_LOCAL_DEV=1.\n\t// For local development only.\n\tDev *bool\n\t// HTTPClient is used for every call to the engine, and for sockets\n\t// (Subscribe, Streams().Read). Default: http.DefaultClient.\n\tHTTPClient *http.Client\n\t// NoStreaming turns off streamed answers: answers are sent whole at the end.\n\t// By default a POST answer is streamed when the engine asks for it, so a\n\t// proxy in front of the app does not end a long step (see docs/protocol.md).\n\tNoStreaming bool\n\t// HeartbeatInterval is the time between heartbeats in a streamed answer.\n\t// Default: 20s. At least 1ms. It also moves the server's write deadline\n\t// (http.Server.WriteTimeout) on, so that does not end a long step.\n\tHeartbeatInterval time.Duration\n\t// NoSyncOnBoot turns off the sync at boot. By default Serve checks in the\n\t// background whether the engine has this app's manifest, and syncs when it\n\t// changed, so a deploy needs no Resync. Then it checks again every\n\t// checkEveryMs the engine gives (5 min) until Client.Close. It needs the\n\t// signing key; without one it does nothing, except in dev mode, where it\n\t// checks with no key (for a local engine).\n\tNoSyncOnBoot bool\n}\n```\nClientOpts configures a client. Fields left nil are read from environment variables; values set here win.\n\n```go\ntype Concurrency struct {\n\tLimit int     `json:\"limit\"`\n\tKey   *string `json:\"key,omitempty\"`\n\tScope string  `json:\"scope,omitempty\"`\n}\n```\nConcurrency limits how many steps of the function run at once. Key is an expression over event; Scope is \"fn\" (default), \"env\" or \"account\".\n\n```go\ntype Debounce struct {\n\tPeriod  time.Duration\n\tKey     *string\n\tTimeout time.Duration\n}\n```\nDebounce waits for Period of quiet before running, with the last event. Timeout is the longest it may wait in all (zero: no limit).\n\n```go\ntype Event = core.Event\n```\nEvent is an event to send with client.Send or step.Send.\n\n```go\ntype FailedEventData struct {\n\t// FunctionID is the failed function's full ID, \"\u003cappId\u003e-\u003cid\u003e\".\n\tFunctionID string `json:\"function_id\"`\n\tRunID      string `json:\"run_id\"`\n\t// Error is why the run failed.\n\tError *StepError `json:\"error\"`\n\t// Event is the failed run's trigger event, as JSON.\n\tEvent json.RawMessage `json:\"event\"`\n\t// Attempts is how many times the step that failed the run was tried. It\n\t// is 0 when no step try failed it (for example a finish timeout).\n\tAttempts int `json:\"attempts\"`\n}\n```\nFailedEventData is the data of an inngest/function.failed event. Use it as the T of a failure function (see CreateFunction).\n\n```go\ntype FunctionConfig struct {\n\tID          string            `json:\"id\"`\n\tName        string            `json:\"name,omitempty\"`\n\tTriggers    []Trigger         `json:\"triggers\"`\n\tRetries     *int              `json:\"retries,omitempty\"`\n\tTimeouts    *timeoutsJSON     `json:\"timeouts,omitempty\"`\n\tCancelOn    []cancelOnJSON    `json:\"cancelOn,omitempty\"`\n\tConcurrency []Concurrency     `json:\"concurrency,omitempty\"`\n\tThrottle    *throttleJSON     `json:\"throttle,omitempty\"`\n\tRateLimit   *rateLimitJSON    `json:\"rateLimit,omitempty\"`\n\tDebounce    *debounceJSON     `json:\"debounce,omitempty\"`\n\tBatchEvents *batchEventsJSON  `json:\"batchEvents,omitempty\"`\n\tPriority    *Priority         `json:\"priority,omitempty\"`\n\tIdempotency *string           `json:\"idempotency,omitempty\"`\n\tSingleton   *Singleton        `json:\"singleton,omitempty\"`\n\tTags        map[string]string `json:\"tags,omitempty\"`\n}\n```\nFunctionConfig is one function in the manifest, with Inngest's key names.\n\n```go\ntype FunctionOpts struct {\n\tID          string\n\tName        string\n\tRetries     *int\n\tTimeouts    *Timeouts\n\tCancelOn    []CancelOn\n\tConcurrency []Concurrency\n\tThrottle    *Throttle\n\tRateLimit   *RateLimit\n\tDebounce    *Debounce\n\tBatchEvents *BatchEvents\n\tPriority    *Priority\n\t// Idempotency is an expression over event; one run per value.\n\tIdempotency *string\n\tSingleton   *Singleton\n\t// Tags names up to 3 values of a run, each an expression over event, for\n\t// example {\"agentRun\": \"event.data.job.runId\"}. The engine works them out\n\t// once, when the run starts, and Runs().List and Runs().Cancel can find\n\t// runs by them. A name is a letter, then letters, digits or _, up to 32.\n\t// A value that is not a string, number or boolean, or is over 256\n\t// characters, is left out.\n\tTags map[string]string\n}\n```\nFunctionOpts configures a function. Only ID is required.\n\nDurations are sent to the engine as \"\\\u003cn\u003es\" when they are whole seconds, else as \"\\\u003cn\u003ems\".\n\n```go\ntype Functions struct {\n\t// contains filtered or unexported fields\n}\n```\nFunctions pauses and resumes this app's functions. Get it with Client.Functions.\n\n```go\nfunc (f Functions) Pause(ctx context.Context, functionID string) (PauseResult, error)\n```\nPause pauses one of this app's functions, as the dashboard does (POST /v1/functions/{id}/pause): new runs are refused (or held, with StartOpts.WhenPaused), and its active runs pause at their next step.\n\n```go\nfunc (f Functions) Resume(ctx context.Context, functionID string) (PauseResult, error)\n```\nResume resumes a paused function and its paused runs (POST /v1/functions/{id}/resume).\n\n```go\ntype GenericEvent[T any] struct {\n\tID        string `json:\"id\"`\n\tName      string `json:\"name\"`\n\tData      T      `json:\"data\"`\n\tTimestamp int64  `json:\"ts\"`\n\tUser      any    `json:\"user,omitempty\"`\n}\n```\nGenericEvent is an event a function receives, with typed data.\n\n```go\ntype Handler[T any] func(ctx context.Context, input Input[T]) (any, error)\n```\nHandler is a function's code.\n\n```go\ntype Input[T any] struct {\n\tEvent    GenericEvent[T]\n\tEvents   []GenericEvent[T]\n\tInputCtx InputCtx\n}\n```\nInput is what a handler gets: the trigger event, the batch (one item unless batching) and the run details.\n\n```go\ntype InputCtx struct {\n\tFunctionID string\n\tRunID      string\n\t// Attempt counts from 0.\n\tAttempt     int\n\tMaxAttempts int\n}\n```\nInputCtx says which run and attempt this is.\n\n```go\ntype ListRunsOpts struct {\n\t// Function is a function's own ID. Needed with Tags.\n\tFunction string\n\t// Status keeps runs in these statuses, for example \"queued\", \"running\".\n\t// Empty: every status.\n\tStatus []string\n\t// Tags keeps runs with all these tag values (up to 3). See FunctionOpts.Tags.\n\tTags map[string]string\n\t// Limit is the page size, 1 to 200. Default: 50.\n\tLimit int\n\t// Before is RunPage.Next of the page before, to read the next page.\n\tBefore string\n\t// Order is \"newest\" (the default) or \"oldest\": oldest first.\n\tOrder string\n}\n```\nListRunsOpts filters Runs().List. Every field is optional.\n\n```go\ntype MultipleTriggers []Trigger\n```\nMultipleTriggers starts a function from any of several triggers.\n\n```go\ntype PauseResult struct {\n\tPaused bool `json:\"paused\"`\n\t// Runs is how many of the function's runs were paused, or resumed.\n\tRuns int `json:\"runs\"`\n}\n```\nPauseResult says what Functions().Pause or Resume did.\n\n```go\ntype Priority struct {\n\tRun *string `json:\"run,omitempty\"`\n}\n```\nPriority orders waiting runs. Run is an expression giving a boost in seconds (-600 to 600).\n\n```go\ntype RateLimit struct {\n\tLimit  int\n\tPeriod time.Duration\n\tKey    *string\n}\n```\nRateLimit drops events over Limit per Period.\n\n```go\ntype Realtime struct {\n\t// contains filtered or unexported fields\n}\n```\nRealtime sends small live messages from functions to browsers. A message goes to the browsers connected right now; nothing is stored or replayed. A server can read them too, with Subscribe. Get it with Client.Realtime.\n\nA publish is a plain call, not a step: if the step around it is retried, the message is sent again. Treat messages as hints (progress, logs), and keep anything that must happen once in a step's result.\n\n```go\nfunc (r Realtime) Publish(ctx context.Context, channel, topic string, data any) error\n```\nPublish sends data (any JSON value, up to about 64 KB) to the browsers subscribed to topic on channel. Log its error and go on: a realtime outage should not fail a run.\n\n```go\nfunc (r Realtime) PublishMany(ctx context.Context, messages []RealtimeOut) error\n```\nPublishMany sends 1 to 100 messages in one call. Each message's data is up to about 64 KB, and the whole call up to 1 MB. The engine checks them all first: if one is bad, none is sent.\n\n```go\nfunc (r Realtime) Subscribe(ctx context.Context, opts SubscribeOpts) (stop func(), err error)\n```\nSubscribe reads live messages on a server, the way the TypeScript subscribe does in a browser. It makes a new token (Token or TokenMany) before every connect, so no token route is needed. It connects to the client's base URL with the path of the token's URL, not to the host in the token. It sends \"ping\" every 30s. When the socket drops it connects again after a wait (1s, doubling up to 30s, with some random), and at once when the engine ends the socket at the end of its 1-hour life (close code 4001).\n\nMessages are lost while the socket reconnects and at the 1-hour renewal. Treat them as hints: read missed state from your own store after a reconnect (OnState gets RealtimeOpen).\n\nIt runs until stop is called or ctx ends. stop waits until the subscription has ended, so no callback runs after it returns. It may be called more than once. Do not call stop from inside OnMessage or OnState: it would wait for itself. To end from a callback, cancel the ctx given to Subscribe, or call go stop(). err is only for bad options: no channel, no topics, or no OnMessage.\n\n```go\nfunc (r Realtime) Token(ctx context.Context, channel string, topics ...string) (RealtimeToken, error)\n```\nToken makes a subscription token for channel and topics (1 to 10). Call it in your own HTTP handler, after you checked that the user may see that channel.\n\n```go\nfunc (r Realtime) TokenMany(ctx context.Context, channels []string, topics ...string) (RealtimeToken, error)\n```\nTokenMany makes one token for 1 to 100 channels, with at most 8,000 characters of names in all (so the token fits in a connect URL). The topics apply to every channel. One socket then gets the messages of all of them.\n\n```go\ntype RealtimeMessage struct {\n\tChannel string          `json:\"channel\"`\n\tTopic   string          `json:\"topic\"`\n\tData    json.RawMessage `json:\"data\"`\n\t// TS is when the engine got the publish, ms since epoch.\n\tTS int64 `json:\"ts\"`\n}\n```\nRealtimeMessage is one message a subscription gets.\n\n```go\ntype RealtimeOut struct {\n\tChannel string `json:\"channel\"`\n\tTopic   string `json:\"topic\"`\n\tData    any    `json:\"data\"`\n}\n```\nRealtimeOut is one message for PublishMany.\n\n```go\ntype RealtimeState string\n```\nRealtimeState is the state of a subscription, given to SubscribeOpts.OnState.\n\n```go\nconst (\n\tRealtimeConnecting RealtimeState = \"connecting\"\n\tRealtimeOpen       RealtimeState = \"open\"\n\tRealtimeClosed     RealtimeState = \"closed\"\n\tRealtimeError      RealtimeState = \"error\"\n)\n```\nThe states of a subscription.\n\n```go\ntype RealtimeToken struct {\n\tToken string `json:\"token\"`\n\tURL   string `json:\"url\"`\n\t// Channel is set for a token made by Token.\n\tChannel string `json:\"channel,omitempty\"`\n\t// Channels is set for a token made by TokenMany.\n\tChannels []string `json:\"channels,omitempty\"`\n\tTopics   []string `json:\"topics\"`\n\t// ExpiresAt is the connect deadline (ms since epoch), about a minute away.\n\tExpiresAt int64 `json:\"expiresAt\"`\n}\n```\nRealtimeToken lets one browser (or server) connect to one channel, or to a list of channels, and read the listed topics. Hand it to the browser as JSON; the TypeScript client reads it.\n\n```go\ntype RetryResult struct {\n\t// Retried is false when the run had not failed or been cancelled, its\n\t// function is paused (Reason \"paused\"), or another run holds its singleton\n\t// key now (Reason \"singleton\").\n\tRetried bool   `json:\"retried\"`\n\tReason  string `json:\"reason,omitempty\"`\n}\n```\nRetryResult says what Runs().Retry did.\n\n```go\ntype RunCounts struct {\n\tQueued        int `json:\"queued\"`\n\tRunning       int `json:\"running\"`\n\tSleeping      int `json:\"sleeping\"`\n\tWaiting       int `json:\"waiting\"`\n\tWaitingForApp int `json:\"waiting_for_app\"`\n\tPaused        int `json:\"paused\"`\n\tCompleted     int `json:\"completed\"`\n\tFailed        int `json:\"failed\"`\n\tCancelled     int `json:\"cancelled\"`\n\t// Since is ms since epoch. Ended runs older than this may be gone from\n\t// the counts already.\n\tSince int64 `json:\"since\"`\n}\n```\nRunCounts is how many of a function's runs are in each status.\n\n```go\ntype RunDetail struct {\n\tRunSummary\n\t// Attempts is, for a failed run, how many times the call that failed it\n\t// was tried (as the failure function's attempts); for any other run, how\n\t// many times it was called.\n\tAttempts int `json:\"attempts\"`\n\t// Error is why the run failed or was cancelled; nil otherwise.\n\tError *RunError `json:\"error\"`\n\t// Event is the event that started the run. For a run from Start, its Data\n\t// is StartOpts.Data.\n\tEvent RunEvent `json:\"event\"`\n}\n```\nRunDetail is one run, as Runs().Get gives it.\n\n```go\ntype RunError struct {\n\tName    string `json:\"name\"`\n\tMessage string `json:\"message\"`\n\tStack   string `json:\"stack,omitempty\"`\n}\n```\nRunError is a run's error, as the engine keeps it.\n\n```go\ntype RunEvent struct {\n\tID   string          `json:\"id\"`\n\tName string          `json:\"name\"`\n\tData json.RawMessage `json:\"data\"`\n\t// TS is ms since epoch.\n\tTS int64 `json:\"ts\"`\n}\n```\nRunEvent is the event that started a run.\n\n```go\ntype RunPage struct {\n\tItems []RunSummary `json:\"items\"`\n\t// Next reads the next page as ListRunsOpts.Before. Empty on the last page.\n\tNext string `json:\"next\"`\n}\n```\nRunPage is one page of runs, newest first.\n\n```go\ntype RunSummary struct {\n\tID string `json:\"id\"`\n\t// FunctionID is the function's own ID, without the app.\n\tFunctionID string `json:\"functionId\"`\n\tStatus     string `json:\"status\"`\n\t// CreatedAt is ms since epoch.\n\tCreatedAt int64 `json:\"createdAt\"`\n\t// EndedAt is ms since epoch, or 0 while the run has not ended.\n\tEndedAt int64 `json:\"endedAt\"`\n\t// Tags are the run's tags; empty when it has none.\n\tTags map[string]string `json:\"tags\"`\n}\n```\nRunSummary is one run in a RunPage.\n\n```go\ntype Runs struct {\n\t// contains filtered or unexported fields\n}\n```\nRuns finds, counts and cancels this app's runs. Get it with Client.Runs.\n\n```go\nfunc (r Runs) Cancel(ctx context.Context, opts CancelOpts) (CancelResult, error)\n```\nCancel cancels runs of this app (POST /v1/runs/cancel): one run by ID, the run that holds a singleton key, or the runs with a tag value. A run that has ended already is not an error: it is in NotActive. A cancel by tag cancels up to 500 runs; when More is true, call again with Next as Cursor.\n\n```go\nfunc (r Runs) Counts(ctx context.Context, functionID string) (RunCounts, error)\n```\nCounts counts a function's runs by status (GET /v1/runs/counts). Like List, it is a few seconds behind the runs.\n\n```go\nfunc (r Runs) Delete(ctx context.Context, runID string) (bool, error)\n```\nDelete deletes a run that has ended now, as its retention would later (POST /v1/runs/{id}/delete): its state, files and index row. It is false for an active run, one that is not found, and one kept for debugging (the dashboard's Keep).\n\n```go\nfunc (r Runs) Get(ctx context.Context, runID string) (*RunDetail, error)\n```\nGet gives one of this app's runs, with its event and error (GET /v1/runs/{id}). It asks the run itself, so it does not lag. Nil, nil when there is no such run.\n\n```go\nfunc (r Runs) List(ctx context.Context, opts ListRunsOpts) (RunPage, error)\n```\nList lists this app's runs, newest first (GET /v1/runs). It reads the engine's run index, which is a few seconds behind the runs.\n\n```go\nfunc (r Runs) Retry(ctx context.Context, runID string) (RetryResult, error)\n```\nRetry retries a failed or cancelled run from where it stopped, under the same run ID, as the dashboard's Retry (POST /v1/runs/{id}/retry). A run that is missing, or has not ended that way, is not retried: Retried is false, with no error.\n\n```go\nfunc (r Runs) Singleton(ctx context.Context, functionID string, key any) (SingletonRun, error)\n```\nSingleton finds the active run that holds a singleton key of a function (GET /v1/functions/{id}/singleton). key is the value the function's singleton key expression gives: a string, or any other JSON value. This is exact, with no index lag.\n\n```go\ntype SDKInfo struct {\n\tLanguage string `json:\"language\"`\n\tVersion  string `json:\"version\"`\n}\n```\nSDKInfo names the SDK in the manifest.\n\n```go\ntype ServableFunction interface {\n\t// ID is the function ID without the app prefix.\n\tID() string\n\t// FullyQualifiedID is \"\u003cappId\u003e-\u003cid\u003e\", used by step.Invoke and in\n\t// inngest/function.failed events.\n\tFullyQualifiedID() string\n\t// Config is the function's manifest entry.\n\tConfig() FunctionConfig\n\t// contains filtered or unexported methods\n}\n```\nServableFunction is a function made by CreateFunction.\n\n```go\nfunc CreateFunction[T any](c *Client, opts FunctionOpts, trigger Triggerable, handler Handler[T]) (ServableFunction, error)\n```\nCreateFunction defines a function and adds it to the client.\n\nFor failure handling (onFailure in TypeScript), create a second function of type FailedEventData with trigger EventTrigger(\"inngest/function.failed\", StrPtr(\"event.data.function\\_id == '\\\u003cappId\u003e-\\\u003cid\u003e'\")). Its event data holds function\\_id, run\\_id, error, event (the original trigger event) and attempts (how many times the failed step was tried).\n\n```go\ntype Singleton struct {\n\tKey  *string `json:\"key,omitempty\"`\n\tMode string  `json:\"mode\"`\n}\n```\nSingleton keeps one active run per key. Mode is \"skip\" or \"cancel\".\n\n```go\ntype SingletonRun struct {\n\t// RunID is empty when no active run holds the key.\n\tRunID string `json:\"runId\"`\n\t// Status is the run's status, or empty with RunID.\n\tStatus string `json:\"status\"`\n}\n```\nSingletonRun is the run that holds a singleton key.\n\n```go\ntype StartOpts struct {\n\t// Data is the run's event data. Default: {}.\n\tData any\n\t// ID makes a retry safe: a second Start with the same ID (1 to 256\n\t// characters) finds the same run, and does not start another. Optional.\n\tID string\n\t// User is the event's user field. Optional.\n\tUser any\n\t// WhenPaused says what a paused function does with the start: \"refuse\"\n\t// (the default: Reason is \"paused\") or \"hold\" (the run is made paused, and\n\t// starts when the function is resumed).\n\tWhenPaused string\n}\n```\nStartOpts is the input of Client.Start.\n\n```go\ntype StartResult struct {\n\tStarted bool   `json:\"started\"`\n\tRunID   string `json:\"runId,omitempty\"`\n\tEventID string `json:\"eventId,omitempty\"`\n\t// Existed is true when a run with this StartOpts.ID was there already.\n\tExisted bool `json:\"existed,omitempty\"`\n\t// Reason says why no run started: \"singleton\", \"paused\", \"not_found\", or\n\t// \"deleted\": a run with this StartOpts.ID was just deleted and is not gone\n\t// yet, so try again in a few seconds.\n\tReason string `json:\"reason,omitempty\"`\n\t// ActiveRunID is the run that holds the singleton when Reason is\n\t// \"singleton\". It is empty if that run ended in between.\n\tActiveRunID string `json:\"activeRunId,omitempty\"`\n}\n```\nStartResult says whether Start started a run.\n\n```go\ntype StepError = core.StepError\n```\nStepError is what a step returns when its stored result is an error.\n\n```go\ntype StreamItem struct {\n\t// Offset is the item's place in the stream. Treat it as opaque text: keep\n\t// the last one you read, and read again after it.\n\tOffset string          `json:\"offset\"`\n\tItem   json.RawMessage `json:\"item\"`\n\t// End is true for the end item, which Close writes. It is always last.\n\tEnd bool `json:\"end,omitempty\"`\n}\n```\nStreamItem is one item of a stream.\n\n```go\ntype StreamOpenOpts struct {\n\t// Meta is any JSON value (up to 4 KB) kept with the stream. Optional.\n\tMeta any\n\t// TTL deletes the stream this long after Open if it is not closed\n\t// before. 1s to 7 days.\n\tTTL time.Duration\n}\n```\nStreamOpenOpts is the input of Streams().Open.\n\n```go\ntype StreamSnapshot struct {\n\tMeta  json.RawMessage `json:\"meta\"`\n\tItems []StreamItem    `json:\"items\"`\n\t// Ended is true when the stream is closed. Then the last item is the\n\t// end item.\n\tEnded bool `json:\"ended\"`\n}\n```\nStreamSnapshot is a stream as it is now.\n\n```go\ntype StreamToken struct {\n\tToken  string `json:\"token\"`\n\tURL    string `json:\"url\"`\n\tStream string `json:\"stream\"`\n\t// ExpiresAt is the connect deadline (ms since epoch), about a minute away.\n\tExpiresAt int64 `json:\"expiresAt\"`\n}\n```\nStreamToken lets one reader (a browser, for example) connect to one stream. Hand it to the browser as JSON; the TypeScript readStream reads it.\n\n```go\ntype Streams struct {\n\t// contains filtered or unexported fields\n}\n```\nStreams keeps short lists of items (for example the output of one run) that readers can read from any offset, then follow live. A stream belongs to this app. Get it with Client.Streams.\n\nOne writer per stream: Open it, Append to it, then Close it with an end item. Readers use Snapshot (what is there now) or Read (what is there, then new items, until the end item). See docs/limits.md for the limits.\n\n```go\nfunc (s Streams) Append(ctx context.Context, id string, items ...any) ([]string, error)\n```\nAppend adds 1 to 100 items (each any JSON value, up to 64 KB) in order, and returns one offset for each. It fails with ErrStreamGone when the stream does not exist, and ErrStreamClosed after Close.\n\n```go\nfunc (s Streams) Close(ctx context.Context, id string, end any, grace time.Duration) (closed bool, err error)\n```\nClose writes end (any JSON value) as the stream's last item and closes the stream. The stream is deleted grace later (0 to 7 days), so late readers still get the end. closed is false when it was closed already; then nothing changes. It fails with ErrStreamGone when the stream does not exist.\n\n```go\nfunc (s Streams) Delete(ctx context.Context, id string) (deleted bool, err error)\n```\nDelete deletes a stream now. Its readers get ErrStreamGone. deleted is false when there was none.\n\n```go\nfunc (s Streams) Open(ctx context.Context, id string, opts StreamOpenOpts) (created bool, err error)\n```\nOpen makes a stream. created is false when it exists already; then nothing changes.\n\n```go\nfunc (s Streams) Read(ctx context.Context, id, after string) iter.Seq2[StreamItem, error]\n```\nRead yields the items after the offset after (\"\" is from the start), then new items as they are appended, until the end item, which it yields too. It makes a new token (Token) before every connect, and connects to the client's base URL with the path of the token's URL, not to the host in the token.\n\nWhen the socket drops, it connects again from the last offset it yielded, after a wait (1s, doubling up to 30s, with some random), or at once when the engine ends the socket at the end of its 1-hour life. So no item is lost or yielded twice.\n\nIt yields ErrStreamGone (and stops) when the stream does not exist, or is deleted while read. It stops with no error when ctx ends or the loop breaks, and closes the socket. It also stops with no error, and no item, when the stream is closed and has nothing after after (you had the end item already; the engine closes the socket with code 4100).\n\nOther errors: a bad id or after, or a token call the engine refuses (4xx), is yielded, and Read stops. Anything else is tried again.\n\n```go\nfunc (s Streams) Snapshot(ctx context.Context, id, after string) (*StreamSnapshot, error)\n```\nSnapshot returns the items after the offset after (\"\" is from the start), without waiting for more. It reads every page. It returns nil, nil when the stream does not exist.\n\n```go\nfunc (s Streams) Token(ctx context.Context, id string) (StreamToken, error)\n```\nToken makes a token to read one stream. Call it in your own HTTP handler, after you checked that the user may read that stream.\n\n```go\ntype SubscribeOpts struct {\n\t// Channel is the one channel to read. Set Channel or Channels, not both.\n\tChannel string\n\t// Channels reads 1 to 100 channels over one socket, with at most 8,000\n\t// characters of names in all.\n\tChannels []string\n\t// Topics are the topics to read (1 to 10), on every channel.\n\tTopics []string\n\t// OnMessage gets each message. Required. It runs on the subscription's\n\t// own goroutine, one message at a time, so a slow OnMessage holds up the\n\t// next ones.\n\tOnMessage func(RealtimeMessage)\n\t// OnState gets each change of state. err is set with RealtimeError, and\n\t// says why the connect or the socket failed. Optional.\n\tOnState func(state RealtimeState, err error)\n}\n```\nSubscribeOpts says what Subscribe reads and where the messages go.\n\n```go\ntype Throttle struct {\n\tLimit  int\n\tPeriod time.Duration\n\tBurst  int\n\tKey    *string\n}\n```\nThrottle delays runs over Limit per Period (plus Burst).\n\n```go\ntype Timeouts struct {\n\tStep   time.Duration\n\tFinish time.Duration\n}\n```\nTimeouts sets time limits. Step is the longest one step's HTTP call may take. Finish is the longest the whole run may take, counted from its first step call (time spent queued does not count); a run still going then is cancelled. Zero means the engine's default (Step) or no limit (Finish).\n\n```go\ntype Trigger struct {\n\tEvent string  `json:\"event,omitempty\"`\n\tIf    *string `json:\"if,omitempty\"`\n\tCron  string  `json:\"cron,omitempty\"`\n}\n```\nTrigger starts a function: an event (with an optional \"if\" expression) or a cron schedule. Make one with EventTrigger or CronTrigger.\n\n```go\nfunc CronTrigger(cron string) Trigger\n```\nCronTrigger runs the function on a cron schedule, for example \"0 2 \\* \\* \\*\" or \"TZ=Africa/Lagos 0 2 \\* \\* \\*\".\n\n```go\nfunc EventTrigger(name string, expr *string) Trigger\n```\nEventTrigger runs the function for each event with this name. expr is an optional \"if\" expression over event, for example \"event.data.plan == 'pro'\".\n\n```go\ntype Triggerable interface {\n\t// contains filtered or unexported methods\n}\n```\nTriggerable is a Trigger or MultipleTriggers.\n\n","path":"github.com/eadwinCode/flow-sdk","name":"flow","synopsis":"Package flow is the Go SDK for clevix-worker, a durable workflow engine on Cloudflare.","isRedistributable":true}
