@kazzle/app 0.1.944 → 0.1.946

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.
Files changed (41) hide show
  1. package/README.md +2 -2
  2. package/dist/definition.d.ts +434 -0
  3. package/dist/definition.js +171 -0
  4. package/dist/index.d.ts +1 -105
  5. package/dist/index.js +3 -15
  6. package/dist/installations.d.ts +13 -0
  7. package/dist/installations.js +69 -0
  8. package/dist/vendor/kazzle/agents.d.ts +38 -0
  9. package/dist/vendor/kazzle/agents.js +46 -0
  10. package/dist/vendor/kazzle/generated/operations.js +18 -1
  11. package/dist/vendor/kazzle/index.d.ts +3 -0
  12. package/dist/vendor/kazzle/index.js +4 -2
  13. package/dist/vendor/kazzle/kazzle.d.ts +4 -0
  14. package/dist/vendor/kazzle/kazzle.js +7 -2
  15. package/dist/vendor/kazzle/thread-stream.d.ts +11 -0
  16. package/dist/vendor/kazzle/thread-stream.js +41 -0
  17. package/dist/vendor/kazzle/threads.d.ts +77 -0
  18. package/dist/vendor/kazzle/threads.js +70 -0
  19. package/dist/vite.d.ts +1 -1
  20. package/dist/vite.js +1 -1
  21. package/package.json +8 -4
  22. package/templates/ai-app/README.md +3 -0
  23. package/templates/ai-app/kazzle.config.ts +10 -2
  24. package/templates/empty-app/README.md +3 -0
  25. package/templates/empty-app/kazzle.config.ts +10 -2
  26. package/templates/login-app/KAZZLE.md +1 -1
  27. package/templates/login-app/README.md +3 -0
  28. package/templates/login-app/kazzle.config.ts +10 -2
  29. package/templates/process-app/README.md +3 -0
  30. package/templates/process-app/components/process/index.ts +1 -1
  31. package/templates/process-app/kazzle.config.ts +12 -6
  32. package/templates/realtime-app/KAZZLE.md +1 -1
  33. package/templates/realtime-app/README.md +3 -0
  34. package/templates/realtime-app/kazzle.config.ts +10 -2
  35. package/templates/ui-app/README.md +3 -0
  36. package/templates/ui-app/kazzle.config.ts +10 -2
  37. package/templates/ui-db-app/KAZZLE.md +1 -1
  38. package/templates/ui-db-app/README.md +3 -0
  39. package/templates/ui-db-app/kazzle.config.ts +10 -2
  40. package/dist/connections.d.ts +0 -11
  41. package/dist/connections.js +0 -56
package/dist/index.d.ts CHANGED
@@ -1,105 +1 @@
1
- export interface KazzleComponentEnv {
2
- /** Secret collection slug */
3
- collection: string;
4
- /** Environment slug for secret injection */
5
- environment: string;
6
- /** Only inject these env var names. If omitted, inject all from collection+environment. */
7
- include?: string[];
8
- }
9
- export interface KazzleRuntimeMode {
10
- /** Command to start the component in this mode (e.g. "bun run dev", "bun run start") */
11
- command: string;
12
- /** Command to build for this mode (used by production deploys, e.g. "bun run build") */
13
- build?: string;
14
- /** Mode-specific secret collection + environment. Falls back to the component env. */
15
- env?: KazzleComponentEnv;
16
- }
17
- export interface KazzleComponentRuntime {
18
- /** Local dev / preview runtime */
19
- dev?: KazzleRuntimeMode;
20
- /** Production runtime */
21
- prod?: KazzleRuntimeMode;
22
- }
23
- /**
24
- * A single trigger entry on a process component. One component can declare
25
- * many triggers — for example, a daily cron AND a webhook handler that both
26
- * route into the same code.
27
- *
28
- * - `kind: 'schedule'` → fires on the cron expression in `schedule`.
29
- * `schedule` is a 5-field cron expression with minute resolution.
30
- *
31
- * - `kind: 'webhook'` → fires when the platform receives
32
- * `POST /webhooks/{spaceId}/{appId}/{componentName}/{name}`.
33
- *
34
- * `path` is the HTTP route on the running server that handles this trigger.
35
- * Required when `processMode: 'persistent'` (the platform POSTs the trigger
36
- * into the long-running server at this path with `Authorization: Bearer
37
- * ${KAZZLE_TRIGGER_SECRET}`). Ignored for `processMode: 'triggered'` — those
38
- * components run as one-off ephemeral processes that read `TRIGGER_NAME`
39
- * from the environment instead.
40
- */
41
- export interface KazzleTrigger {
42
- /** Stable identifier, unique within the component (kebab-case, e.g. "daily-digest"). */
43
- name: string;
44
- /** Trigger kind — schedule (cron) or webhook (HTTP POST). */
45
- kind: 'schedule' | 'webhook';
46
- /** Cron expression (5-field, minute resolution). Required for kind="schedule". */
47
- schedule?: string;
48
- /** HTTP path on the running server. Required when processMode="persistent". */
49
- path?: string;
50
- }
51
- export interface KazzleComponent {
52
- /** Unique component name within the app */
53
- name: string;
54
- /** Component type — ui (max 1) or process */
55
- type: 'ui' | 'process';
56
- /** Entry path within the app directory */
57
- path: string;
58
- /** Default secret collection + environment for env var injection. */
59
- env?: KazzleComponentEnv;
60
- /** Commands and optional env overrides for dev and production modes */
61
- runtime?: KazzleComponentRuntime;
62
- /**
63
- * Execution lifecycle for process components.
64
- *
65
- * - 'persistent' — long-running server. Triggers are POSTed into the
66
- * server at the declared `path`. This is the default.
67
- * - 'triggered' — ephemeral one-off run per trigger. The platform
68
- * spawns the entry script with `TRIGGER_NAME`, `RUN_ID`, and an
69
- * optional `WEBHOOK_PAYLOAD` env var, then waits for exit.
70
- */
71
- processMode?: 'persistent' | 'triggered';
72
- /** Schedule and webhook triggers. One component may declare many. */
73
- triggers?: KazzleTrigger[];
74
- }
75
- export interface KazzleSkill {
76
- /** Skill name */
77
- name: string;
78
- /** Path to the SKILL.md file relative to the app root */
79
- path: string;
80
- }
81
- export interface KazzleConfig {
82
- /** Marketing display name shown in the app catalog. Falls back to the slug when omitted. */
83
- name?: string;
84
- /** One-line catalog tagline. Required to publish. */
85
- subtitle?: string;
86
- /** Author-set version label (e.g. "1.2.0"). Display-only; snapshotted on publish. */
87
- version?: string;
88
- /** Where the published app runs — remote (Fly.io) or local (user computer). Defaults to remote. */
89
- target?: 'local' | 'remote';
90
- /** Path to the app icon file (png, jpg, svg, webp, ico) */
91
- icon?: string;
92
- /**
93
- * End-user login for this app (via @kazzle/app/auth — Google today).
94
- * Distinct from `kazzleAuth`, which gates the launch surface by Kazzle
95
- * account; appLogin is the app's OWN users, stored in its own database.
96
- * Requires a process + database.
97
- */
98
- appLogin?: boolean;
99
- /** Executable components — UI frontends or background processes */
100
- components?: KazzleComponent[];
101
- /** AI skill definitions — markdown files the AI reads for domain knowledge */
102
- skills?: KazzleSkill[];
103
- }
104
- /** Type-safe config helper. Use: export default defineConfig({ ... }) */
105
- export declare function defineConfig(config: KazzleConfig): KazzleConfig;
1
+ export { AppDefinitionSchema, defineApp, type AppDefinition, type AppDefinitionComponent, type AppDefinitionComponentEnv, type AppDefinitionRuntimeMode, type AppDefinitionSetup, type AppDefinitionSetupField, type AppDefinitionToolSource, type AppDefinitionTrigger, } from './definition';
package/dist/index.js CHANGED
@@ -1,15 +1,3 @@
1
- // @kazzle/app — root export. App config contract + `defineConfig`.
2
- //
3
- // SOURCE OF TRUTH for the app config types that generated apps author in
4
- // kazzle.config.ts. The server validates the runtime shape with the Zod
5
- // `ManifestSchema` in server/apps/apps.manifest.ts; these interfaces are the
6
- // hand-authored TypeScript mirror app code imports. Keep the two in sync — if
7
- // you add a config field here, add it to ManifestSchema in the same change.
8
- //
9
- // This module must stay dependency-free. Tools live in `@kazzle/app/tools`,
10
- // the Vite helper in `@kazzle/app/vite` — do not re-export them here or the
11
- // root import pulls in zod/vite for every consumer. See README.md.
12
- /** Type-safe config helper. Use: export default defineConfig({ ... }) */
13
- export function defineConfig(config) {
14
- return config;
15
- }
1
+ // @kazzle/app — canonical app-definition contract.
2
+ // Other helpers stay on their dedicated package subpaths.
3
+ export { AppDefinitionSchema, defineApp, } from './definition';
@@ -0,0 +1,13 @@
1
+ export declare class InstallationNotConnectedError extends Error {
2
+ readonly installationId: string;
3
+ constructor(installationId: string, message?: string);
4
+ }
5
+ /**
6
+ * A fresh vendor access token for a installation, e.g.
7
+ * `new Stripe(await getInstallationToken('8f2a…'))`.
8
+ */
9
+ export declare function getInstallationToken(installationId: string): Promise<string>;
10
+ /** Read values submitted through an app definition's credential form. */
11
+ export declare function getInstallationCredentials<T extends Record<string, unknown> = Record<string, string>>(installationId: string): Promise<T>;
12
+ /** Forget cached tokens (tests, or after a reconnect). */
13
+ export declare function clearInstallationTokenCache(): void;
@@ -0,0 +1,69 @@
1
+ // @kazzle/app/installations — use the accounts a person connected in Kazzle
2
+ // (Stripe, Gmail, Slack, …) from app code.
3
+ //
4
+ // Kazzle keeps the OAuth tokens; this asks Kazzle for a fresh one and caches it
5
+ // until it expires. Identify the installation by its installation id (the AI that
6
+ // built the app has it from the vault). Requires KAZZLE_API_KEY and
7
+ // KAZZLE_API_URL, both injected into every component at deploy and `kazzle run`.
8
+ //
9
+ // Dependency-free on purpose (uses global fetch). Do not add zod/vite here.
10
+ import { kazzleApiUrl } from './client';
11
+ export class InstallationNotConnectedError extends Error {
12
+ installationId;
13
+ constructor(installationId, message) {
14
+ super(message ?? `Installation ${installationId} is not connected. Connect it on the Integrations page in Kazzle.`);
15
+ this.installationId = installationId;
16
+ this.name = 'InstallationNotConnectedError';
17
+ }
18
+ }
19
+ const DEFAULT_TTL_MS = 60 * 60_000;
20
+ const REFRESH_MARGIN_MS = 60_000;
21
+ const cache = new Map();
22
+ function apiKey() {
23
+ const key = process.env['KAZZLE_API_KEY'];
24
+ if (!key) {
25
+ throw new Error('KAZZLE_API_KEY is not set — installation credentials are only available to deployed Kazzle app components.');
26
+ }
27
+ return key;
28
+ }
29
+ /**
30
+ * A fresh vendor access token for a installation, e.g.
31
+ * `new Stripe(await getInstallationToken('8f2a…'))`.
32
+ */
33
+ export async function getInstallationToken(installationId) {
34
+ const hit = cache.get(installationId);
35
+ if (hit && hit.expiresAt - Date.now() > REFRESH_MARGIN_MS)
36
+ return hit.token;
37
+ const res = await fetch(`${kazzleApiUrl()}/installations/${encodeURIComponent(installationId)}/token`, {
38
+ headers: { authorization: `Bearer ${apiKey()}` },
39
+ });
40
+ if (res.status === 404 || res.status === 409) {
41
+ const body = await res.json().catch(() => ({}));
42
+ cache.delete(installationId);
43
+ throw new InstallationNotConnectedError(installationId, body.message);
44
+ }
45
+ if (!res.ok) {
46
+ throw new Error(`Kazzle installation credential request failed: HTTP ${res.status}`);
47
+ }
48
+ const body = await res.json();
49
+ const expiresAt = body.expiresAt ? Date.parse(body.expiresAt) : Date.now() + DEFAULT_TTL_MS;
50
+ cache.set(installationId, { token: body.token, expiresAt: Number.isFinite(expiresAt) ? expiresAt : Date.now() + DEFAULT_TTL_MS });
51
+ return body.token;
52
+ }
53
+ /** Read values submitted through an app definition's credential form. */
54
+ export async function getInstallationCredentials(installationId) {
55
+ const res = await fetch(`${kazzleApiUrl()}/installations/${encodeURIComponent(installationId)}/credentials`, {
56
+ headers: { authorization: `Bearer ${apiKey()}` },
57
+ });
58
+ if (res.status === 404) {
59
+ const body = await res.json().catch(() => ({}));
60
+ throw new InstallationNotConnectedError(installationId, body.message);
61
+ }
62
+ if (!res.ok)
63
+ throw new Error(`Kazzle installation credential request failed: HTTP ${res.status}`);
64
+ return (await res.json()).values;
65
+ }
66
+ /** Forget cached tokens (tests, or after a reconnect). */
67
+ export function clearInstallationTokenCache() {
68
+ cache.clear();
69
+ }
@@ -0,0 +1,38 @@
1
+ import { type KazzleHttp } from './http';
2
+ export interface AgentAvatarConfig {
3
+ shape: 'round' | 'square';
4
+ faceColor: string;
5
+ eyeColor: string;
6
+ }
7
+ export interface AgentWrite {
8
+ name: string;
9
+ instructions: string;
10
+ avatarUrl?: string | null;
11
+ avatarConfig?: AgentAvatarConfig | null;
12
+ description?: string | null;
13
+ modelId?: string | null;
14
+ skillIds?: string[];
15
+ appInstallationIds?: string[];
16
+ computerIds?: string[];
17
+ browserProfileIds?: string[];
18
+ enabled?: boolean;
19
+ }
20
+ export type AgentUpdate = Partial<AgentWrite>;
21
+ export interface AgentRow extends AgentWrite {
22
+ id: string;
23
+ enabled: boolean;
24
+ createdAt: number;
25
+ updatedAt: number;
26
+ mainThreadId?: string;
27
+ }
28
+ export declare class AgentsApi {
29
+ private readonly http;
30
+ constructor(http: KazzleHttp);
31
+ create(input: AgentWrite): Promise<AgentRow>;
32
+ list(): Promise<AgentRow[]>;
33
+ get(agentId: string): Promise<AgentRow>;
34
+ update(agentId: string, patch: AgentUpdate): Promise<AgentRow>;
35
+ delete(agentId: string): Promise<{
36
+ success: boolean;
37
+ }>;
38
+ }
@@ -0,0 +1,46 @@
1
+ import { apiPath } from './http';
2
+ function fromApi(row) {
3
+ return {
4
+ id: row.id,
5
+ name: row.name,
6
+ instructions: row.instructions,
7
+ avatarUrl: row.avatar_url,
8
+ avatarConfig: row.avatar_config ? {
9
+ shape: row.avatar_config.shape,
10
+ faceColor: row.avatar_config.face_color,
11
+ eyeColor: row.avatar_config.eye_color,
12
+ } : row.avatar_config,
13
+ description: row.description,
14
+ modelId: row.model_id,
15
+ skillIds: row.skill_ids ?? [],
16
+ appInstallationIds: row.app_installation_ids ?? [],
17
+ computerIds: row.computer_ids ?? [],
18
+ browserProfileIds: row.browser_profile_ids ?? [],
19
+ enabled: row.enabled,
20
+ createdAt: row.created_at,
21
+ updatedAt: row.updated_at,
22
+ ...(row.main_thread_id ? { mainThreadId: row.main_thread_id } : {}),
23
+ };
24
+ }
25
+ export class AgentsApi {
26
+ http;
27
+ constructor(http) {
28
+ this.http = http;
29
+ }
30
+ async create(input) {
31
+ return fromApi(await this.http.json('POST', '/agents', input));
32
+ }
33
+ async list() {
34
+ const response = await this.http.json('GET', '/agents');
35
+ return response.items.map(fromApi);
36
+ }
37
+ async get(agentId) {
38
+ return fromApi(await this.http.json('GET', apiPath `/agents/${agentId}`));
39
+ }
40
+ async update(agentId, patch) {
41
+ return fromApi(await this.http.json('PATCH', apiPath `/agents/${agentId}`, patch));
42
+ }
43
+ async delete(agentId) {
44
+ return this.http.json('DELETE', apiPath `/agents/${agentId}`);
45
+ }
46
+ }
@@ -1,9 +1,14 @@
1
1
  // GENERATED FILE — do not edit.
2
- // Source of truth: shared/api/openapi.json (Computers API + Browsers API tags).
2
+ // Source of truth: shared/api/openapi.json (customer API tags).
3
3
  // Regenerate with `bun run generate` in packages/kazzle-sdk after the server
4
4
  // API surface changes; src/operations.sync.test.ts fails on drift.
5
5
  /** Every customer API operation the SDK must cover. */
6
6
  export const API_OPERATIONS = [
7
+ { method: 'GET', path: '/agents' },
8
+ { method: 'POST', path: '/agents' },
9
+ { method: 'DELETE', path: '/agents/{agentId}' },
10
+ { method: 'GET', path: '/agents/{agentId}' },
11
+ { method: 'PATCH', path: '/agents/{agentId}' },
7
12
  { method: 'GET', path: '/browsers' },
8
13
  { method: 'POST', path: '/browsers' },
9
14
  { method: 'DELETE', path: '/browsers/{browserId}' },
@@ -97,6 +102,18 @@ export const API_OPERATIONS = [
97
102
  { method: 'POST', path: '/computers/{computerId}/terminals/{sessionId}/wait' },
98
103
  { method: 'POST', path: '/computers/{computerId}/terminals/{sessionId}/write' },
99
104
  { method: 'POST', path: '/computers/{computerId}/wake' },
105
+ { method: 'GET', path: '/threads' },
106
+ { method: 'POST', path: '/threads' },
107
+ { method: 'DELETE', path: '/threads/{threadId}' },
108
+ { method: 'GET', path: '/threads/{threadId}' },
109
+ { method: 'PATCH', path: '/threads/{threadId}' },
110
+ { method: 'POST', path: '/threads/{threadId}/approvals' },
111
+ { method: 'GET', path: '/threads/{threadId}/messages' },
112
+ { method: 'POST', path: '/threads/{threadId}/messages' },
113
+ { method: 'POST', path: '/threads/{threadId}/resume' },
114
+ { method: 'POST', path: '/threads/{threadId}/retry' },
115
+ { method: 'POST', path: '/threads/{threadId}/stop' },
116
+ { method: 'GET', path: '/threads/{threadId}/stream' },
100
117
  ];
101
118
  /** URL segments under /browsers/{browserId}/tabs/{tabId}/. */
102
119
  export const TAB_ACTION_SEGMENTS = [
@@ -8,4 +8,7 @@ export { DesktopApi } from './computers.desktop';
8
8
  export { Browser, BrowsersApi } from './browsers';
9
9
  export { TabsApi } from './browsers.tabs';
10
10
  export { ProfilesApi } from './browsers.profiles';
11
+ export { ThreadStream, type ThreadStreamEvent } from './thread-stream';
12
+ export { AgentsApi, type AgentAvatarConfig, type AgentRow, type AgentUpdate, type AgentWrite, } from './agents';
13
+ export { Thread, ThreadsApi, type ThreadCreate, type ThreadDecision, type ThreadMessage, type ThreadRow, type ThreadSegment, type ThreadUpdate, } from './threads';
11
14
  export type { ActionResult, BrowserCreateOptions, BrowserCreateResponse, BrowserRow, BrowserState, ComputerCreateResponse, ComputerRow, ExecOptions, FsDeleteResponse, FsGlobResponse, FsGrepMatch, FsGrepResponse, FsReadResponse, FsTransferResponse, FsWriteResponse, ListResponse, OkResponse, ProfileCreateOptions, ProfileCreateResponse, ProfileRow, TabRow, } from './sdk.types';
@@ -1,5 +1,4 @@
1
- // kazzle — typed client for the Kazzle computers and browsers REST API.
2
- // Quickstart in README.md; endpoint semantics in docs/platform/computers-api.mdx.
1
+ // kazzle — typed client for Kazzle agents, threads, computers, and browsers.
3
2
  export { Kazzle } from './kazzle';
4
3
  export { KazzleApiError } from './http';
5
4
  export { ExecStream, KazzleExecError } from './sse';
@@ -10,3 +9,6 @@ export { DesktopApi } from './computers.desktop';
10
9
  export { Browser, BrowsersApi } from './browsers';
11
10
  export { TabsApi } from './browsers.tabs';
12
11
  export { ProfilesApi } from './browsers.profiles';
12
+ export { ThreadStream } from './thread-stream';
13
+ export { AgentsApi, } from './agents';
14
+ export { Thread, ThreadsApi, } from './threads';
@@ -1,9 +1,13 @@
1
1
  import { type KazzleOptions } from './http';
2
2
  import { ComputersApi } from './computers';
3
3
  import { BrowsersApi } from './browsers';
4
+ import { AgentsApi } from './agents';
5
+ import { ThreadsApi } from './threads';
4
6
  export declare class Kazzle {
5
7
  readonly computers: ComputersApi;
6
8
  readonly browsers: BrowsersApi;
9
+ readonly agents: AgentsApi;
10
+ readonly threads: ThreadsApi;
7
11
  /** Resolved API base URL (option, then KAZZLE_API_URL, then https://api.kazzle.app). */
8
12
  readonly baseUrl: string;
9
13
  constructor(options?: KazzleOptions);
@@ -1,12 +1,15 @@
1
- // Kazzle SDK entry: `new Kazzle({ apiKey })` → kazzle.computers.* and
2
- // kazzle.browsers.*. One KazzleHttp instance owns auth and error mapping for
1
+ // Kazzle SDK entry. One KazzleHttp instance owns auth and error mapping for
3
2
  // every namespace.
4
3
  import { KazzleHttp } from './http';
5
4
  import { ComputersApi } from './computers';
6
5
  import { BrowsersApi } from './browsers';
6
+ import { AgentsApi } from './agents';
7
+ import { ThreadsApi } from './threads';
7
8
  export class Kazzle {
8
9
  computers;
9
10
  browsers;
11
+ agents;
12
+ threads;
10
13
  /** Resolved API base URL (option, then KAZZLE_API_URL, then https://api.kazzle.app). */
11
14
  baseUrl;
12
15
  constructor(options = {}) {
@@ -14,5 +17,7 @@ export class Kazzle {
14
17
  this.baseUrl = http.baseUrl;
15
18
  this.computers = new ComputersApi(http);
16
19
  this.browsers = new BrowsersApi(http);
20
+ this.agents = new AgentsApi(http);
21
+ this.threads = new ThreadsApi(http);
17
22
  }
18
23
  }
@@ -0,0 +1,11 @@
1
+ export interface ThreadStreamEvent {
2
+ type: string;
3
+ data: unknown;
4
+ }
5
+ export declare class ThreadStream implements AsyncIterable<ThreadStreamEvent> {
6
+ private readonly response;
7
+ constructor(response: Promise<Response>);
8
+ [Symbol.asyncIterator](): AsyncIterator<ThreadStreamEvent>;
9
+ /** Drain the response and return the assistant's text. */
10
+ text(): Promise<string>;
11
+ }
@@ -0,0 +1,41 @@
1
+ import { parseSseStream } from './sse';
2
+ function parseData(data) {
3
+ if (!data)
4
+ return null;
5
+ try {
6
+ return JSON.parse(data);
7
+ }
8
+ catch {
9
+ return data;
10
+ }
11
+ }
12
+ export class ThreadStream {
13
+ response;
14
+ constructor(response) {
15
+ this.response = response;
16
+ }
17
+ async *[Symbol.asyncIterator]() {
18
+ const response = await this.response;
19
+ if (!response.body)
20
+ throw new Error('Thread response has no body stream');
21
+ for await (const frame of parseSseStream(response.body)) {
22
+ yield { type: frame.event, data: parseData(frame.data) };
23
+ }
24
+ }
25
+ /** Drain the response and return the assistant's text. */
26
+ async text() {
27
+ const chunks = [];
28
+ for await (const event of this) {
29
+ if (event.type === 'error') {
30
+ const message = typeof event.data === 'string' ? event.data : 'Thread response failed';
31
+ throw new Error(message);
32
+ }
33
+ if (event.type !== 'text' || !event.data || typeof event.data !== 'object')
34
+ continue;
35
+ const content = event.data.content;
36
+ if (typeof content === 'string')
37
+ chunks.push(content);
38
+ }
39
+ return chunks.join('');
40
+ }
41
+ }
@@ -0,0 +1,77 @@
1
+ import { ThreadStream } from './thread-stream';
2
+ import { type KazzleHttp } from './http';
3
+ export interface ThreadCreate {
4
+ title?: string;
5
+ agentId?: string;
6
+ }
7
+ export interface ThreadUpdate {
8
+ title?: string;
9
+ agentId?: string | null;
10
+ modelId?: string | null;
11
+ archived?: boolean;
12
+ }
13
+ export interface ThreadRow {
14
+ id: string;
15
+ title: string;
16
+ agentId: string | null;
17
+ modelId: string | null;
18
+ mode: string;
19
+ status: string | null;
20
+ archived: boolean;
21
+ createdAt: number;
22
+ updatedAt: number;
23
+ }
24
+ export interface ThreadSegment {
25
+ id: string;
26
+ type: string;
27
+ content: unknown;
28
+ order: number;
29
+ createdAt: number;
30
+ }
31
+ export interface ThreadMessage {
32
+ id: string;
33
+ role: string;
34
+ modelId: string | null;
35
+ createdAt: number;
36
+ segments: ThreadSegment[];
37
+ }
38
+ export interface ThreadDecision {
39
+ toolCallId: string;
40
+ elementId: string;
41
+ input?: Record<string, unknown>;
42
+ }
43
+ export declare class Thread {
44
+ private readonly http;
45
+ readonly id: string;
46
+ constructor(http: KazzleHttp, id: string);
47
+ send(content: string, options?: {
48
+ messageId?: string;
49
+ }): ThreadStream;
50
+ retry(messageId: string, options?: {
51
+ content?: string;
52
+ }): ThreadStream;
53
+ watch(): ThreadStream;
54
+ resume(decisions?: ThreadDecision[]): ThreadStream;
55
+ approve(decisions: ThreadDecision[]): ThreadStream;
56
+ stop(): Promise<{
57
+ success: boolean;
58
+ }>;
59
+ get(): Promise<ThreadRow>;
60
+ update(patch: ThreadUpdate): Promise<ThreadRow>;
61
+ delete(): Promise<{
62
+ success: boolean;
63
+ }>;
64
+ messages(): Promise<ThreadMessage[]>;
65
+ }
66
+ export declare class ThreadsApi {
67
+ private readonly http;
68
+ constructor(http: KazzleHttp);
69
+ create(input?: ThreadCreate): Promise<Thread>;
70
+ list(): Promise<ThreadRow[]>;
71
+ get(threadId: string): Promise<ThreadRow>;
72
+ update(threadId: string, patch: ThreadUpdate): Promise<ThreadRow>;
73
+ delete(threadId: string): Promise<{
74
+ success: boolean;
75
+ }>;
76
+ fromId(threadId: string): Thread;
77
+ }
@@ -0,0 +1,70 @@
1
+ import { ThreadStream } from './thread-stream';
2
+ import { apiPath } from './http';
3
+ function fromApi(row) {
4
+ return {
5
+ id: row.id,
6
+ title: row.title,
7
+ agentId: row.agent_id,
8
+ modelId: row.model_id,
9
+ mode: row.mode,
10
+ status: row.status,
11
+ archived: row.archived,
12
+ createdAt: row.created_at,
13
+ updatedAt: row.updated_at,
14
+ };
15
+ }
16
+ export class Thread {
17
+ http;
18
+ id;
19
+ constructor(http, id) {
20
+ this.http = http;
21
+ this.id = id;
22
+ }
23
+ send(content, options = {}) {
24
+ return new ThreadStream(this.http.request('POST', apiPath `/threads/${this.id}/messages`, { content, ...options }));
25
+ }
26
+ retry(messageId, options = {}) {
27
+ return new ThreadStream(this.http.request('POST', apiPath `/threads/${this.id}/retry`, { messageId, ...options }));
28
+ }
29
+ watch() { return new ThreadStream(this.http.request('GET', apiPath `/threads/${this.id}/stream`)); }
30
+ resume(decisions) { return new ThreadStream(this.http.request('POST', apiPath `/threads/${this.id}/resume`, { decisions })); }
31
+ approve(decisions) { return new ThreadStream(this.http.request('POST', apiPath `/threads/${this.id}/approvals`, { decisions })); }
32
+ stop() { return this.http.json('POST', apiPath `/threads/${this.id}/stop`, {}); }
33
+ get() { return this.http.json('GET', apiPath `/threads/${this.id}`).then(fromApi); }
34
+ update(patch) { return this.http.json('PATCH', apiPath `/threads/${this.id}`, patch).then(fromApi); }
35
+ delete() { return this.http.json('DELETE', apiPath `/threads/${this.id}`); }
36
+ async messages() {
37
+ const response = await this.http.json('GET', apiPath `/threads/${this.id}/messages`);
38
+ return response.items.map(message => ({
39
+ id: message.id,
40
+ role: message.role,
41
+ modelId: message.model_id,
42
+ createdAt: message.created_at,
43
+ segments: message.segments.map(segment => ({
44
+ id: segment.id,
45
+ type: segment.type,
46
+ content: segment.content,
47
+ order: segment.order,
48
+ createdAt: segment.created_at,
49
+ })),
50
+ }));
51
+ }
52
+ }
53
+ export class ThreadsApi {
54
+ http;
55
+ constructor(http) {
56
+ this.http = http;
57
+ }
58
+ async create(input = {}) {
59
+ const row = await this.http.json('POST', '/threads', input);
60
+ return new Thread(this.http, row.id);
61
+ }
62
+ async list() {
63
+ const response = await this.http.json('GET', '/threads');
64
+ return response.items.map(fromApi);
65
+ }
66
+ get(threadId) { return this.fromId(threadId).get(); }
67
+ update(threadId, patch) { return this.fromId(threadId).update(patch); }
68
+ delete(threadId) { return this.fromId(threadId).delete(); }
69
+ fromId(threadId) { return new Thread(this.http, threadId); }
70
+ }
package/dist/vite.d.ts CHANGED
@@ -29,7 +29,7 @@ export type KazzleAppPwaOptions = {
29
29
  /**
30
30
  * Kazzle preview/runtime Vite config. Spread the result into your Vite config:
31
31
  *
32
- * export default defineConfig(({ command }) => ({
32
+ * export default defineApp(({ command }) => ({
33
33
  * plugins: [react(), tailwindcss(), ...kazzleAppPwa()],
34
34
  * ...kazzleAppVite(command, { apiComponent: 'server', proxyPaths: ['/todos'] }),
35
35
  * }));
package/dist/vite.js CHANGED
@@ -32,7 +32,7 @@ function componentUrlEnvName(componentName) {
32
32
  /**
33
33
  * Kazzle preview/runtime Vite config. Spread the result into your Vite config:
34
34
  *
35
- * export default defineConfig(({ command }) => ({
35
+ * export default defineApp(({ command }) => ({
36
36
  * plugins: [react(), tailwindcss(), ...kazzleAppPwa()],
37
37
  * ...kazzleAppVite(command, { apiComponent: 'server', proxyPaths: ['/todos'] }),
38
38
  * }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kazzle/app",
3
- "version": "0.1.944",
3
+ "version": "0.1.946",
4
4
  "description": "Contracts, tool helpers, Vite helper, and templates for building Kazzle apps.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -16,6 +16,10 @@
16
16
  "types": "./dist/index.d.ts",
17
17
  "import": "./dist/index.js"
18
18
  },
19
+ "./definition": {
20
+ "types": "./dist/definition.d.ts",
21
+ "import": "./dist/definition.js"
22
+ },
19
23
  "./tools": {
20
24
  "types": "./dist/tools.d.ts",
21
25
  "import": "./dist/tools.js"
@@ -24,9 +28,9 @@
24
28
  "types": "./dist/client.d.ts",
25
29
  "import": "./dist/client.js"
26
30
  },
27
- "./connections": {
28
- "types": "./dist/connections.d.ts",
29
- "import": "./dist/connections.js"
31
+ "./installations": {
32
+ "types": "./dist/installations.d.ts",
33
+ "import": "./dist/installations.js"
30
34
  },
31
35
  "./auth": {
32
36
  "types": "./dist/auth.d.ts",
@@ -0,0 +1,3 @@
1
+ # {{APP_NAME}}
2
+
3
+ Describe what this app does and how people use it.