@chusky/sdk 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,22 @@ scopes, rotate, and revoke project keys. They never accept or return
20
20
  Each verified account may have at most 10 active projects. Root-created projects
21
21
  remain ownerless operator records and are not visible through account routes.
22
22
 
23
+ Company projects attach to a Better Auth organization ID. Owners/admins can
24
+ create and manage project credentials, policy, and up to 20 agent profiles;
25
+ verified members can list those project resources. Default company scopes are
26
+ least-privilege and intentionally exclude `approvals:write`, so a project key
27
+ cannot approve its own external tool actions. Composio app/OAuth and trigger
28
+ endpoints remain the existing integration surface and retain the stable Chusky
29
+ end-user identity supplied in `X-Chusky-User-Id`.
30
+
31
+ Company telemetry is project-scoped rather than caller-scoped: keys with the
32
+ `company:read` scope can read status-only run summaries, bounded audit events,
33
+ and monthly completed-run/model-cost totals at `/v1/company/runs`,
34
+ `/v1/company/audit-events`, and `/v1/company/usage`. The authenticated
35
+ workspace dashboard exposes the same views only to organization owners/admins.
36
+ Run inputs/outputs and user/provider payloads are never copied into this shared
37
+ ledger. Durable run completion accounting is idempotent by project and run ID.
38
+
23
39
  ## Resources
24
40
 
25
41
  | Resource | Endpoint | Notes |
@@ -27,6 +43,8 @@ remain ownerless operator records and are not visible through account routes.
27
43
  | Threads | `POST /v1/threads`, `GET /v1/threads/:threadId` | Conversation/memory boundary for one explicit SDK end user. |
28
44
  | Projects | `GET/POST /v1/admin/projects`, `DELETE /v1/admin/projects/:id` | Root-key-only project provisioning and key revocation. |
29
45
  | Dashboard projects | `GET/POST /v1/account/projects`, `PATCH /v1/account/projects/:id`, `POST .../rotate-key`, `DELETE .../:id` | Better-Auth-cookie-only, verified-user project management. |
46
+ | Company policy | `GET/PUT /v1/account/projects/:id/policy` | Organization members may read; only owners/admins may change bounded tool grants and per-run budgets. |
47
+ | Company agents | `GET/POST/PATCH/DELETE /v1/account/projects/:id/agents` and `/v1/agents` | Dashboard management is role-checked; SDK routes require project `agents:read/write` scopes. Templates are listed at `GET /v1/agents/templates`. |
30
48
  | Runs | `POST /v1/threads/:threadId/runs` | Executes durable Chusky work. `wait` is bounded. |
31
49
  | Run stream | `POST /v1/threads/:threadId/runs/stream` | `application/x-ndjson`; emits typed run events. |
32
50
  | Runs | `GET /v1/threads/:threadId/runs/:runId`, `POST .../cancel` | Cancellation is request-specific; durable task results stay queryable. |
@@ -35,7 +53,16 @@ remain ownerless operator records and are not visible through account routes.
35
53
  | Files | `POST /v1/files`, `POST /v1/files/:fileId/complete`, `GET/DELETE /v1/files/:fileId` | Direct R2 upload URLs are short-lived; a `HEAD` verification must succeed before download; deletion is owner-scoped. |
36
54
  | Webhooks | `POST /v1/webhooks`, `GET /v1/webhooks`, `DELETE /v1/webhooks/:id` | HTTPS-only subscription; secret is encrypted at rest and returned only on creation. |
37
55
  | Delivery history | `GET /v1/webhooks/:id/deliveries` | Bounded, safe delivery status for operational diagnosis; delete disables future deliveries. |
56
+ | Trigger catalogue | `GET /v1/triggers/catalog/toolkits`, `GET /v1/triggers/catalog/toolkits/:toolkit` | Composio-backed, paginated trigger types for connected apps; the dashboard uses the same catalogue as Telegram. `POST /v1/triggers` can pin creation to a verified `connectedAccountId`. |
38
57
  | Observability | `GET /v1/audit-events`, `GET /v1/usage` | Bounded per-user audit trail and current usage snapshot. |
58
+ | Company telemetry | `GET /v1/company/runs`, `/v1/company/audit-events`, `/v1/company/usage`; dashboard `GET /v1/account/projects/:id/company/{runs,audit-events,usage}` | Requires `company:read` for project keys; dashboard reads require workspace owner/admin. Run summaries contain no prompt or output. |
59
+ | Calls | `GET/POST /v1/account/calls` | Lists redacted call metadata and creates an approval-gated outbound call request. SDK callers use `calls:read/write`; dashboard callers must be verified and Telegram-linked. |
60
+ | Voice | `GET /v1/account/voice-options`, `PATCH /v1/account/preferences` | Lists Flux and optional Bland catalogue entries and stores the account's live voice preference. Use `voice:read` for the catalogue and `account:write` for preferences. |
61
+ | Meetings | `GET/POST /v1/meetings`, `POST /v1/meetings/prepare`, `GET/PATCH /v1/meetings/profile`, `POST /v1/meetings/preparations/:id/join`, `GET /v1/meetings/:id`, `POST /v1/meetings/:id/leave`, `GET /v1/meetings/:id/context`, `DELETE /v1/meetings/contacts/:id` | Recall lifecycle for Zoom, Google Meet, Microsoft Teams, and Webex. SDK callers use `meetings:read/write`; meeting URLs and sealed calendar links are never returned by list endpoints. |
62
+ | Connected apps | `GET /v1/apps`, `POST /v1/apps/:toolkit/connect`, `GET /v1/apps/connections`, `DELETE /v1/apps/connections/:id` | Composio toolkit discovery, OAuth connection links, connected-account listing, and disconnect. Credentials remain server-side. |
63
+ | Native schedules | `GET/POST/DELETE /v1/reminders`, `GET/POST/DELETE /v1/jobs` | One-time reminders and recurring QStash schedules owned by the SDK user. |
64
+ | Memory and scratchpad | `GET/POST/DELETE /v1/memory`, `GET/PUT/DELETE /v1/scratchpad` | Explicit structured memory and temporary working notes; both are user-scoped. |
65
+ | Channel and device management | `GET/POST/PATCH/DELETE /v1/channels`, `GET/DELETE /v1/devices` | Link supported channels, control proactive delivery, and revoke CLI devices without exposing credentials. |
39
66
 
40
67
  ## Event stream
41
68
 
package/docs/budgets.mdx CHANGED
@@ -23,3 +23,19 @@ Recommended responses:
23
23
  Expose usage through the usage endpoint and include bounded cost metadata in run and webhook records. Never trust a client-provided cost value.
24
24
 
25
25
  For asynchronous work, combine the budget with `wait: false`; the QStash-backed task resumes from persisted state after a process restart. Treat the returned task as the source of truth for progress and retry state.
26
+
27
+ ## Inspecting a durable trace
28
+
29
+ Every synchronous SDK run is also checkpointed as a provider-neutral agent run.
30
+ Use the trace endpoint to inspect model turns, tool starts/results, approvals,
31
+ failures, and completion without loading the transcript into the normal run
32
+ response:
33
+
34
+ ```http
35
+ GET /v1/threads/{threadId}/runs/{runId}/trace
36
+ ```
37
+
38
+ Pass `?include_state=true` only when the checkpointed messages and tool results
39
+ are needed for debugging. The trace is owner-scoped, versioned for optimistic
40
+ concurrency, and retained independently from chat history. Worker handoffs use
41
+ the same trace model and expose their `runId` through the worker endpoints.
package/docs/calls.mdx ADDED
@@ -0,0 +1,58 @@
1
+ ---
2
+ title: Calls and live voice
3
+ description: Request approval-gated outbound calls and configure Chusky's live voices.
4
+ ---
5
+
6
+ ## Providers
7
+
8
+ Chusky supports outbound calls through the configured provider: Twilio for the
9
+ private live voice bridge, or Bland when Bland is enabled and fully configured.
10
+ The provider is selected by the Chusky deployment; application code does not
11
+ receive provider credentials.
12
+
13
+ ```ts
14
+ const voices = await chusky.account.voiceOptions();
15
+ console.log(voices.fluxVoices.map((voice) => voice.id), voices.blandVoices);
16
+ const current = await chusky.account.getPreferences();
17
+
18
+ await chusky.account.preferences({
19
+ liveVoice: { provider: "meetings", voice: "flux-haley-en" },
20
+ });
21
+ ```
22
+
23
+ `provider` may be `twilio`, `meetings`, or `bland`. Flux voice options include an
24
+ `id`, display `name`, and accent;
25
+ Bland selections use the `{ id, name }` object returned by `voiceOptions()`.
26
+ Set `voice: null` to restore the deployment default.
27
+
28
+ ## Requesting a call
29
+
30
+ Call creation creates the same exact, one-time approval used by Chusky's other
31
+ surfaces. It does not place the call until an authenticated owner approves it.
32
+
33
+ ```ts
34
+ const approval = await chusky.calls.request({
35
+ phoneNumber: "+14155550123",
36
+ purpose: "Confirm the test-drive appointment and answer final questions.",
37
+ profile: {
38
+ mode: "scheduling",
39
+ tone: "warm",
40
+ capabilities: ["memory_lookup", "schedule_lookup"],
41
+ },
42
+ }, { idempotencyKey: "test-drive-call-2026-09-15" });
43
+
44
+ if (approval.status === "pending") {
45
+ // Show the exact recipient, purpose, and profile to your authenticated owner.
46
+ await chusky.approvals.decide(approval.id, "approve", {
47
+ idempotencyKey: "approve-test-drive-call-2026-09-15",
48
+ });
49
+ }
50
+ ```
51
+
52
+ Use `chusky.calls.list()` to inspect safe call metadata. Phone numbers are not
53
+ used as identity keys, and call transcripts/audio are not exposed through this
54
+ resource.
55
+
56
+ The SDK endpoint requires the `calls:write` scope for requests and
57
+ `calls:read` for listing. On dashboard sessions, the Chusky account must be
58
+ verified and linked to its Telegram workspace.
@@ -37,3 +37,12 @@ Video generation is durable and independently cancellable. Submit a job with `vi
37
37
  ## Workers and channels
38
38
 
39
39
  Workers are durable scheduled routines. `workers.create()` accepts a schedule, task input, budget, and optional channel target. Channels and activity provide the control-plane view needed for dashboards and operational history.
40
+
41
+ ## Voice and meetings
42
+
43
+ Voice calls and Recall meetings are first-class API resources rather than
44
+ provider-specific SDK forks. Use `account.voiceOptions()` and
45
+ `account.preferences()` for the deployment's Flux/Bland choices, `calls.request()`
46
+ for an approval-gated outbound call, and `meetings.prepare()` plus
47
+ `meetings.join()` for a meeting representative. See the [calls guide](/docs/calls)
48
+ and [meetings guide](/docs/meetings) for provider details and lifecycle handling.
@@ -0,0 +1,76 @@
1
+ ---
2
+ title: Company workspaces
3
+ description: Configure shared Chusky agent projects and run governed business workflows.
4
+ ---
5
+
6
+ Company workspaces use Better Auth organizations for membership and invitations. Workspace owners and admins create a company API project in the Chusky dashboard. Members can see project profiles and policy; only owners/admins can create or rotate keys or change policy.
7
+
8
+ OAuth and connected-account lifecycle stay with Composio. Chusky calls its existing Composio integration for toolkit discovery, OAuth consent URLs, account listing, tool execution, and triggers. A company backend connects an app using the same stable Chusky identity it will later use to run the agent:
9
+
10
+ ```ts
11
+ import { Chusky } from "@chusky/sdk";
12
+
13
+ const chusky = new Chusky({
14
+ apiKey: process.env.CHUSKY_API_KEY!,
15
+ userId: "acme-crm-service",
16
+ });
17
+
18
+ const apps = await chusky.account.apps();
19
+ const { url } = await chusky.account.connectApp("GMAIL");
20
+ // Send the URL to an authorized company admin to complete Composio consent.
21
+ ```
22
+
23
+ Use a stable server-side user identifier, not a browser-controlled header or a person's email address. Chusky's thread history, tasks, approvals, and Composio session are scoped to the API project plus that identity. For multi-user products, provide each authenticated end user with their own stable identifier.
24
+
25
+ ## Choose a specialist profile
26
+
27
+ Built-in templates cover Sales Development, Lead Research, Competitive Intelligence, Customer Support, Executive Assistant, Recruiting, and Marketing Operations. Templates include bounded instructions, an allowlist, and default per-run limits. Project policy and saved profiles can further restrict tool use. The server applies the strictest budget and always requires approval before the Composio execution wrappers run.
28
+
29
+ ```ts
30
+ const templates = await chusky.agents.templates();
31
+ const leadAgent = await chusky.agents.create({
32
+ template: "lead-research",
33
+ name: "Fintech lead scout",
34
+ instructions: "Target companies with 50+ employees. Cite the source for headcount and prepare outreach drafts for review.",
35
+ });
36
+ ```
37
+
38
+ User-supplied company criteria are instructions/data for the profile, not tool permissions. A caller cannot expand the project or profile grant in a run request.
39
+
40
+ ## Run an outcome
41
+
42
+ ```ts
43
+ const { thread, run } = await chusky.runs.create({
44
+ input: "Find fintech companies that match our ICP and prepare CRM-ready profiles and outreach drafts.",
45
+ agentId: leadAgent.id,
46
+ wait: false,
47
+ budget: { duration: "30m", maxToolCalls: 20, maxCost: 2 },
48
+ }, { idempotencyKey: "acme-lead-research-2026-09-15" });
49
+
50
+ const latest = await chusky.runs.get(thread.id, run.id);
51
+ ```
52
+
53
+ The run is durable and task-backed when `wait: false` is used with the configured Redis/QStash execution service. Poll run/task status or receive signed webhook events. A human approves pending external actions through the authenticated dashboard or a separately authorized application. Company-project keys have approval-read scope, not approval-write scope, by default; the MCP server also cannot approve its own actions.
54
+
55
+ ## Read company-wide outcomes
56
+
57
+ Run content and Composio sessions stay scoped to each stable caller identity. Workspace admins can still monitor shared execution status and spend without exposing prompts or outputs:
58
+
59
+ ```ts
60
+ const [runs, events, usage] = await Promise.all([
61
+ chusky.company.runs({ limit: 20 }),
62
+ chusky.company.audit(),
63
+ chusky.company.usage(),
64
+ ]);
65
+
66
+ console.log(runs.data.map(({ id, status, agentName }) => ({ id, status, agentName })));
67
+ console.log(usage.currentMonth.completedRuns, usage.currentMonth.costUsd);
68
+ ```
69
+
70
+ These reads require the project key's `company:read` scope. The dashboard shows the same project-scoped view to workspace owners/admins. Audit entries contain bounded action paths, status, request IDs, and timestamps—not request bodies. Successful durable completion is counted once per project/run even if a workflow completion is retried.
71
+
72
+ ## Integrate a company system
73
+
74
+ Use the SDK in a trusted backend, call the versioned REST API directly, or connect the Cloudflare Streamable HTTP MCP server at `/mcp`. MCP clients pass the scoped `chsk_` key and the same stable `X-Chusky-User-Id` header. See [`cloudflare/chusky-mcp`](../../cloudflare/chusky-mcp/README.md) for tools and deployment configuration.
75
+
76
+ Use existing Composio triggers or Chusky's scheduling facilities for event-driven and delayed work. Make the business instruction explicit—for example, draft a follow-up after three days—and keep sending gated by human approval. The standard agent profile does not itself create a prospect-facing recurring schedule.
@@ -0,0 +1,76 @@
1
+ ---
2
+ title: Embedded chat
3
+ description: Add a safe customer-facing Chusky chat without exposing project credentials.
4
+ ---
5
+
6
+ The widget is a browser UI only. It never talks to Chusky with a project key.
7
+ Your server owns the key, authenticates the visitor, chooses the stable Chusky
8
+ user ID, and proxies the stream.
9
+
10
+ ## Add the widget
11
+
12
+ ```html
13
+ <script type="module">
14
+ import { defineChuskyChat } from "@chusky/sdk/widget";
15
+ defineChuskyChat();
16
+ </script>
17
+ <chusky-chat
18
+ endpoint="/api/chusky/chat"
19
+ title="Acme assistant"
20
+ accent-color="#111111"
21
+ ></chusky-chat>
22
+ ```
23
+
24
+ The element renders an accessible launcher, message list, loading state, retry
25
+ state, and approval-pending notice. It accepts bounded NDJSON events with
26
+ `run.delta`, `run.completed`, `run.requires_approval`, and `error` types.
27
+
28
+ ## Server route contract
29
+
30
+ `POST /api/chusky/chat` receives:
31
+
32
+ ```json
33
+ { "message": "Prepare a sales brief", "conversationId": "optional-client-id" }
34
+ ```
35
+
36
+ The route should:
37
+
38
+ 1. Authenticate the visitor using your own session.
39
+ 2. Derive a stable, non-PII customer identifier.
40
+ 3. Create or recover a Chusky thread for that customer.
41
+ 4. Call `threads.runs.stream()` with the server-side project key.
42
+ 5. Forward only bounded run events; never forward raw tool arguments, provider
43
+ payloads, prompts, tokens, or private account details.
44
+
45
+ The route must reject missing sessions, cross-customer conversation IDs,
46
+ oversized messages, and cross-origin requests. Add your own rate limit and
47
+ CSRF/origin policy.
48
+
49
+ ## Example server flow
50
+
51
+ ```ts
52
+ const chusky = new Chusky({
53
+ apiKey: process.env.CHUSKY_API_KEY!,
54
+ userId: `customer_${session.accountId}`,
55
+ });
56
+
57
+ const thread = await chusky.threads.create({ source: "embedded-chat" });
58
+ const stream = chusky.threads.runs(thread.id).stream({ input: message });
59
+ // Convert the SDK events to NDJSON and return a streaming Response.
60
+ ```
61
+
62
+ For durable business work, use `runs.create({ wait: false })` instead of the
63
+ interactive stream and show the widget a status link or task progress.
64
+
65
+ ## Approval behavior
66
+
67
+ The widget cannot approve an external action. When Chusky emits
68
+ `run.requires_approval`, show a neutral waiting state and direct the customer
69
+ to the authenticated company console or your own approved operator workflow.
70
+
71
+ ## Domain and branding
72
+
73
+ Workspace branding is configured by an owner/admin in Organizations. Custom
74
+ domains require provider-side DNS/TLS routing; Chusky reports `pending_dns`
75
+ until the operator has completed that step. Branding changes do not grant API
76
+ access and do not change project scopes.
package/docs/index.mdx CHANGED
@@ -17,6 +17,9 @@ Install the SDK, create a thread, and stream the first response.
17
17
  - Authenticated chat products with streaming responses
18
18
  - Human-in-the-loop workflows for sending, deleting, publishing, or changing data
19
19
  - File-aware assistants using verified Cloudflare R2 uploads
20
+ - Company workspaces with specialist agent templates and project-scoped run policies
21
+ - Voice workflows through Twilio or Bland, with deployment-supported voice selection
22
+ - Recall meeting representatives for Zoom, Google Meet, Microsoft Teams, and Webex
20
23
 
21
24
  ## The execution model
22
25
 
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: Meetings
3
+ description: Prepare, join, participate in, and leave Recall meetings from the SDK.
4
+ ---
5
+
6
+ ## Supported platforms
7
+
8
+ The meeting resource supports Recall links for Zoom, Google Meet, Microsoft
9
+ Teams, and Webex. Chusky validates the link and platform before sending
10
+ anything to Recall. Recall's optional shared-screen understanding is available
11
+ only where the deployment and Recall support it.
12
+
13
+ ## Configure the representative
14
+
15
+ The meeting profile controls how Chusky participates. It contains the display
16
+ identity, communication guidance, approved knowledge, meeting tools, account
17
+ aliases, and calendar auto-join preference.
18
+
19
+ ```ts
20
+ const profile = await chusky.meetings.updateProfile({
21
+ representativeName: "Chusky",
22
+ organizationName: "Acme Motors",
23
+ role: "sales",
24
+ communicationStyle: "Natural, concise, curious, and helpful.",
25
+ approvedKnowledge: "Only use the approved product and pricing facts.",
26
+ allowedComposioTools: ["GOOGLECALENDAR_CREATE_EVENT"],
27
+ autoJoinCalendar: false,
28
+ });
29
+ ```
30
+
31
+ ## Prepare and join
32
+
33
+ Preparation searches the owner's saved relationship/business context and
34
+ returns a private brief. It does not join a meeting. A direct join can receive
35
+ that brief as `clientContext`; a calendar-prepared join uses the opaque
36
+ preparation ID and never requires the caller to re-send the meeting URL.
37
+
38
+ ```ts
39
+ const brief = await chusky.meetings.prepare({
40
+ clientName: "Jordan Lee",
41
+ objective: "Understand whether Acme Motors is a fit for the fleet program.",
42
+ });
43
+
44
+ const meeting = await chusky.meetings.join({
45
+ meetingUrl: "https://meet.google.com/example-room",
46
+ title: "Acme Motors fleet discussion",
47
+ interactionMode: "representative",
48
+ clientName: "Jordan Lee",
49
+ objective: "Understand whether Acme Motors is a fit for the fleet program.",
50
+ }, { idempotencyKey: "acme-fleet-meeting-2026-09-15" });
51
+ ```
52
+
53
+ `joinAt` schedules the Recall bot when the event is at least ten minutes in the
54
+ future. For recurring calendar automation, use the preparation returned by
55
+ `meetings.list()` and call `joinPreparation(preparation.id)`.
56
+
57
+ ## Roster, context, and lifecycle
58
+
59
+ ```ts
60
+ const snapshot = await chusky.meetings.get(meeting.id);
61
+ const context = await chusky.meetings.context(meeting.id, "What approved facts are relevant to pricing?");
62
+ await chusky.meetings.leave(meeting.id);
63
+ ```
64
+
65
+ The meeting snapshot includes the provider platform, lifecycle status, mission
66
+ metadata, and safe retention state. Participant roster and outcomes are
67
+ available in `meetings.list()` for the authenticated owner. Meeting context is
68
+ available only for an active representative meeting and contains relevant
69
+ owner-stored facts, not arbitrary private history.
70
+
71
+ Use signed Recall webhooks and durable Redis/QStash in production. A successful
72
+ join request means Chusky accepted and persisted the meeting lifecycle; use
73
+ `get()` or `list()` to observe admission, in-call, ended, and failed states.
@@ -17,6 +17,8 @@ description: Deploy a reliable Chusky integration.
17
17
  - Monitor webhook delivery failures, run failures, rate limits, and spend.
18
18
  - Rotate project keys and webhook secrets on a schedule or incident.
19
19
  - Test duplicate requests, expired approvals, unauthorized IDs, provider outages, and reconnects.
20
+ - For calls, test provider-unavailable responses, redacted call history, approval expiry, and Bland/Twilio configuration separately.
21
+ - For meetings, test direct joins and calendar-prepared joins against an authorized staging meeting for each enabled Recall platform. Verify scheduled joins, cancellation, participant updates, meeting-end reconciliation, and idempotent retries before production use.
20
22
 
21
23
  ## Local validation
22
24
 
package/docs.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://mintlify.com/docs.json",
3
+ "name": "Chusky",
4
+ "colors": { "primary": "#111111", "light": "#f7f7f4", "dark": "#111111" },
5
+ "navigation": {
6
+ "tabs": [
7
+ { "tab": "Documentation", "groups": [
8
+ { "group": "Start here", "pages": ["docs/index", "docs/quickstart", "docs/concepts"] },
9
+ { "group": "Build with Chusky", "pages": ["docs/company-workspaces", "docs/embedded-chat", "docs/calls", "docs/meetings", "docs/streaming", "docs/models", "docs/files", "docs/approvals", "docs/tasks", "docs/policies", "docs/structured-output", "docs/fallbacks", "docs/budgets", "docs/capabilities", "docs/architecture"] },
10
+ { "group": "Production", "pages": ["docs/webhooks", "docs/security", "docs/errors", "docs/releases", "docs/production"] }
11
+ ] },
12
+ { "tab": "API Reference", "openapi": "openapi.yaml", "pages": ["docs/api-contract"] }
13
+ ]
14
+ }
15
+ }