> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uplink.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Displaying invocation state

> Observe connector progress and sign-in state, and render a live stepper

`UplinkConnect` shows progress for you. If you [build your own flow](https://docs.uplink.build/connectors-ios/invoking-actions.md#build-your-own-flow) or want progress in your own UI, observe each invocation by its `invocationId`. There are three ways to do it:

* **`InvocationHandle`** — an `@Observable` object that streams updates and falls back to polling on its own. Start here.
* **`StreamingInvocationSource`** — the raw server-sent-events stream.
* **`HTTPInvocationPoller`** — plain HTTP polling on your own schedule.

All three produce the same state: a status, a status log, and the output once the invocation finishes.

## `InvocationHandle`

```swift theme={null}
let handle = client.connectors.observe(invocationId: invocationId)

// Bind SwiftUI to handle.status, handle.statusLog, handle.signInStage, ...
// or wait for the end:
let status = await handle.awaitTerminal()
if status == .completed, let output = handle.output {
    render(output)
}
```

The handle opens the stream immediately, reconnects up to five times, then polls until the invocation finishes. Its properties:

| Property | Type | Description |
| - | - | - |
| `status` | `InvocationStatus` | `.pending`, `.running`, `.completed`, `.failed`, or `.cancelled` |
| `statusLog` | `[StatusEntry]` | Progress messages the connector reported, in order |
| `signInStage` | `SignInStage?` | Where the connector is in sign-in (see below) |
| `signInDeadline` | `Date?` | When the connector stops waiting for the user to sign in |
| `output` | `Data?` | The output as a JSON object, once completed |
| `outputType` | `String?` | The action's declared output label |
| `errorMessage` | `String?` | Why it failed or was cancelled |
| `isTerminal` | `Bool` | True for `.completed`, `.failed`, and `.cancelled` |

`handle.cancel()` stops observing. It doesn't stop the run on the server; use `client.connectors.cancelRun(sessionId:)` for that.

## Sign-in state

Connectors report where they are in sign-in on each `StatusEntry` (`stage`), which the handle surfaces as `signInStage`:

* `.connecting` — the connector is starting up and checking whether the user is already signed in.
* `.needsSignIn` — the site is waiting for the user to sign in. `signInDeadline`, when set, is when the connector gives up.
* `.signedIn` — the user is signed in and the connector is fetching data.

Use `.needsSignIn` to prompt the user back to the sign-in screen, with a countdown from `signInDeadline`.

## Streaming with `StreamingInvocationSource`

```swift theme={null}
for try await snapshot in client.connectors.stream.snapshots(invocationId: invocationId) {
    updateUI(with: snapshot)
}
```

The stream:

* Emits the current state on connect, then again every time the invocation changes.
* Sends a heartbeat every 15 seconds to keep intermediaries from closing the idle connection.
* Ends when the invocation finishes, which ends the `for try await` loop.
* Throws on network failure or a non-2xx response when opening.

If the stream throws or closes before the invocation finishes, reconnect or fall back to polling. `InvocationHandle` does this for you.

## Polling with `HTTPInvocationPoller`

```swift theme={null}
let poller = client.connectors.poller

var snapshot = try await poller.fetch(invocationId: invocationId)
while !snapshot.isTerminal {
    updateUI(with: snapshot)
    try await Task.sleep(for: .milliseconds(750))
    snapshot = try await poller.fetch(invocationId: invocationId)
}
updateUI(with: snapshot)
```

Under a second between polls keeps the UI responsive without hammering the service.

Both the stream and the poller yield an `InvocationSnapshot`:

```swift theme={null}
public struct InvocationSnapshot {
    public let status: InvocationStatus
    public let statusLog: [StatusEntry]
    public let outputData: Data?      // JSON object once completed
    public let outputType: String?    // the action's declared output label
    public let errorMessage: String?  // set on .failed
    public var isTerminal: Bool
}

public struct StatusEntry: Identifiable {
    public let id: UUID
    public let text: String
    public let at: Date
    public let stage: SignInStage?
    public let signInDeadline: Date?
}
```

## Rendering `statusLog` as a stepper

`statusLog` is an append-only list of the connector's progress messages. Render it as a vertical stepper: earlier messages are checked off, the latest is in progress while the invocation is running, and everything is checked off once it completes.

```swift theme={null}
struct StepperView: View {
    let handle: InvocationHandle

    var body: some View {
        ForEach(handle.statusLog) { entry in
            HStack {
                Image(systemName: isDone(entry) ? "checkmark.circle.fill" : "circle")
                Text(entry.text)
            }
        }
    }

    private func isDone(_ entry: StatusEntry) -> Bool {
        handle.status == .completed || entry.id != handle.statusLog.last?.id
    }
}
```

## Handling the result

When `status` is `.completed`, the output is a JSON object whose fields hold [vocabulary](https://docs.uplink.build/vocabulary/overview.md) types. When it's `.failed`, `errorMessage` says why. See [Semantic schemas](https://docs.uplink.build/connectors-ios/semantic-schemas.md) for finding and decoding the fields you care about.

## What's next

> [card] [Semantic schemas](https://docs.uplink.build/connectors-ios/semantic-schemas.md)
>
> Decode output into vocabulary types


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.