{{ run.value.text }}
} `, }) export class ChatComponent { readonly threadId = signal('0198…'); readonly stream = injectPromptJugglerStream(() => { // Read the signal HERE, in the factory itself — that read is what the // adapter tracks. Inside getToken it would run too late to be seen. const thread = this.threadId(); return { getToken: () => fetch(`/api/stream-token?thread=${thread}`).then((r) => r.json()), }; }); } ``` `stream.connected` and `stream.runs` are signals holding the same shapes as the React hook. Reactivity follows Angular's grain: any signal read **during the factory call** — here `threadId`, hoisted into a local — is tracked, and changing it drops the old subscription (and its runs) and connects a fresh one. Reads deferred into `getToken` happen after tracking ends, so hoist them as above. Call it in an injection context (a field initializer or constructor); the subscription disconnects when the component is destroyed. Signals-only, so it works in zoneless applications. ## Workflows Every prompt node of a workflow streams into the same connection, keyed by `runId` and tagged with its [channel](/concepts/memory-and-threads#channels). Follow only the user-facing lanes with `channels: ['support']`. See the [chatbot guide](/guides/building-a-chatbot) for the full end-to-end walkthrough. # Go SDK Source: https://docs.promptjuggler.com/sdks/go/overview Run prompts and workflows, manage knowledge bases, and verify webhooks from Go. The PromptJuggler Go SDK is a thin, typed wrapper over the public REST API. You call flat, synchronous methods that take a `context.Context` and get back typed structs — authentication, request building, and JSON (de)serialization are handled for you. It runs on the standard library's `net/http`, so it pulls in no third-party HTTP stack. ## Requirements * Go 1.22 or newer ## Installation ```bash theme={null} go get go.promptjuggler.com/sdk ``` ## Set up the client Create an API key in [Settings](https://promptjuggler.com/settings), then construct the client once and reuse it (it is safe for concurrent use): ```go theme={null} import "go.promptjuggler.com/sdk" pj := promptjuggler.New("your-api-key") ``` The key is sent as a Bearer token to `https://promptjuggler.com`. Point the SDK at another host (e.g. for testing) with `promptjuggler.WithBaseURL(url)`, or swap the HTTP client (timeouts, proxy) with `promptjuggler.WithHTTPClient(h)`. ## Per-endpoint usage Every endpoint in the [API reference](/api/overview) includes a **Go SDK** code sample showing the exact call — that's the place to look for how to invoke each operation and what it returns. Typed models are returned from the `client` sub-package. A typical flow: ```go theme={null} import ( "context" "fmt" "go.promptjuggler.com/sdk/client" ) ctx := context.Background() // Trigger a run (async — returns immediately with the run ID) created, err := pj.RunPrompt(ctx, "greeting", "production", map[string]string{"name": "Ada"}) if err != nil { // handle err } // Poll for the result run, err := pj.GetPromptRun(ctx, created.Id) if err != nil { // handle err } if run.Status == client.RUNSTATUS_COMPLETED { fmt.Println(run.GetOutput()) } ``` Optional run parameters (priority, environment, metadata, …) are functional options on `RunPrompt` / `RunWorkflow`: ```go theme={null} pj.RunPrompt(ctx, "greeting", "production", map[string]string{"name": "Ada"}, promptjuggler.WithEnvironment("staging"), promptjuggler.WithPriority("onsite"), ) ``` > [!NOTE] > > Enum fields keep a value added to the API after your SDK version; `IsValid()` tells whether > the SDK declares it. ## Error handling When the API responds with an error status, the SDK returns an `*APIError` carrying the HTTP status code and the server's message. When the request never reaches the API (DNS failure, timeout, offline), it returns a `*NetworkError`. If the API replies with a success status whose body can't be decoded (a missing required field, say), it returns a `*DecodeError`. Match them with `errors.As`: ```go theme={null} import "errors" _, err := pj.GetPrompt(ctx, "does-not-exist", "production") var apiErr *promptjuggler.APIError if errors.As(err, &apiErr) { apiErr.StatusCode // e.g. 404 apiErr.Message // the server's error message } ``` You never inspect a generated-client error — the SDK translates the underlying client's errors into its own. ## Webhooks PromptJuggler signs every webhook with the `PromptJuggler-Signature` header. Verify it against the **raw** request body, before any JSON parsing: ```go theme={null} payload := string(rawBody) // the raw request body, as received signature := r.Header.Get("PromptJuggler-Signature") if !promptjuggler.VerifyWebhookSignature(payload, signature, "your-webhook-secret") { // reject the delivery (e.g. respond 403) } ``` `VerifyWebhookSignature` recomputes the HMAC-SHA256 of `{timestamp}.{raw_body}`, compares it in constant time, and rejects deliveries whose timestamp falls outside a tolerance window (default 300s) to prevent replay. A missing (empty) signature header returns false. Use `VerifyWebhookSignatureAt` to supply an explicit tolerance and clock. # Java SDK Source: https://docs.promptjuggler.com/sdks/java/overview Run prompts and workflows, manage knowledge bases, and verify webhooks from Java. The PromptJuggler Java SDK is a thin, typed wrapper over the public REST API. You call flat, synchronous methods and get back typed model objects — authentication, request building, and JSON (de)serialization are handled for you. It runs on the JDK's built-in HTTP client, so it pulls in no third-party HTTP stack. ## Requirements * Java 17 or newer ## Installation Replace `VERSION` with the latest release: [](https://central.sonatype.com/artifact/com.promptjuggler/promptjuggler-java) ```kotlin Gradle theme={null} implementation("com.promptjuggler:promptjuggler-java:VERSION") ``` ```xml Maven theme={null}