@scrydon/sdk
v0.1.8
Published
TypeScript SDK for Scrydon - AI workflow platform
Readme
@scrydon/sdk
TypeScript SDK for Scrydon. Sign in via OAuth, trigger workflows, query knowledge bases, upload files, and stream chat — from the browser or Node.
Installation
npm install @scrydon/sdkQuick start
import { ScrydonClient } from "@scrydon/sdk";
const client = new ScrydonClient({
baseUrl: "https://your-instance.scrydon.com",
clientId: "your-client-id",
redirectUri: "http://localhost:3000/callback",
});
await client.auth.signIn(); // redirects to login
const session = await client.auth.handleCallback(); // call this from your callback pageAfter handleCallback() resolves, every other call on client carries the access token automatically.
Authentication
OAuth 2.0 with PKCE. The PKCE verifier is stored in sessionStorage in browsers and in memory elsewhere.
await client.auth.signIn(); // start the flow
const session = await client.auth.handleCallback(callbackUrl);
const current = await client.auth.getSession(); // null if not signed in; auto-refreshes near expiry
await client.auth.signOut();
const unsubscribe = client.auth.onAuthStateChange((session) => {
// fires on sign-in, sign-out, and token refresh
});session.accessToken is issued by Scrydon's OAuth provider. The SDK refreshes it transparently within 60 seconds of expiry; if the refresh fails, listeners receive null.
Workflows
Trigger deployed workflows synchronously (waits up to 30 s for a result) or asynchronously.
const result = await client.workflows.trigger({
workflowId: "wf-123",
inputs: { prompt: "Analyse this data" },
});
const { executionId } = await client.workflows.triggerAsync({
workflowId: "wf-123",
inputs: { prompt: "Process in background" },
});
const status = await client.workflows.getStatus(executionId);Knowledge bases
Query and ingest documents.
const results = await client.knowledge.query({
question: "What is our refund policy?",
collection: "support-docs",
});
await client.knowledge.ingest({
documents: [file1, file2],
collection: "support-docs",
});Storage
Upload files (multipart) and generate presigned download URLs.
const { url } = await client.storage.upload(myFile, {
path: "documents/report.pdf",
});
const downloadUrl = await client.storage.getUrl("documents/report.pdf");Chat
Stream AI responses from a deployed chat surface.
const stream = client.chat.stream({
deploymentId: "deployment-id",
message: "Hello!",
});
for await (const token of stream) {
process.stdout.write(token);
}Platform API (data / ai / action) — preview
The client.data.*, client.ai.*, and client.action.* namespaces expose Scrydon's full platform surface — storage, memory, knowledge graphs, LLM completions, email, SMS, web search, and more — through the same OAuth bearer path as workflow, knowledge, storage, and chat calls.
// data — platform-managed durable state
const file = await client.data.storage.read({ path: "reports/q1.md" });
await client.data.memory.add({ role: "user", content: "Remember this", conversationId: "c1" });
// ai — model-backed inference
const completion = await client.ai.llm.complete({
model: "claude-sonnet-4-5",
messages: [{ role: "user", content: "Summarise the Q1 report." }],
});
// action — outbound side-effects
await client.action.email.send({
smtpHost: "smtp.example.com", smtpPort: 587,
smtpUsername: "u", smtpPassword: "p", smtpSecure: "tls",
from: "[email protected]", to: "[email protected]",
subject: "Q1 report", body: "See attached.",
});React integration
npm install @scrydon/sdk reactimport {
ScrydonProvider,
useScrydon,
useScrydonAuth,
useChatStream,
} from "@scrydon/sdk/react";
import { ScrydonClient } from "@scrydon/sdk";
const client = new ScrydonClient({ baseUrl: "...", clientId: "...", redirectUri: "..." });
function App() {
return (
<ScrydonProvider client={client}>
<Inner />
</ScrydonProvider>
);
}
function Inner() {
const { client } = useScrydon();
const { user, isAuthenticated, signIn, signOut } = useScrydonAuth();
const { messages, isStreaming, send, reset } = useChatStream("deployment-id");
// ...
}useScrydonAuth re-renders on sign-in, sign-out, and token refresh. useChatStream accumulates streamed tokens into messages and exposes isStreaming for UI state.
Errors
All SDK errors extend ScrydonError and carry a stable code:
import {
ScrydonAuthError,
ScrydonForbiddenError,
ScrydonRateLimitError,
ScrydonValidationError,
ScrydonServerError,
} from "@scrydon/sdk";
try {
await client.workflows.trigger({ workflowId: "wf-123" });
} catch (error) {
if (error instanceof ScrydonAuthError) client.auth.signIn(); // 401
else if (error instanceof ScrydonRateLimitError) wait(error.retryAfter); // 429
else if (error instanceof ScrydonValidationError) console.log(error.details); // 400
else throw error;
}| Error | HTTP | When |
|---|---|---|
| ScrydonAuthError | 401 | Token missing, expired, or rejected |
| ScrydonForbiddenError | 403 | Authenticated but not authorized |
| ScrydonValidationError | 400 | Bad input — error.details carries field-level info |
| ScrydonRateLimitError | 429 | error.retryAfter is seconds to wait |
| ScrydonServerError | 5xx | Server-side failure |
TypeScript
Full type support. Public types are exported from the root and from the /types subpath:
import type {
ScrydonConfig,
ScrydonSession,
WorkflowResult,
KnowledgeResult,
} from "@scrydon/sdk";Platform API types (ScrydonSDK plus per-route param/result types like StorageReadParams) are also exported from the root. Use ScrydonSDK["data"], ScrydonSDK["ai"], or ScrydonSDK["action"] for sliced domain types.
License
MIT
