runwork 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.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +134 -0
  3. package/bin/runwork.js +2 -0
  4. package/bundled-types/agents.d.ts +3 -0
  5. package/bundled-types/ai.d.ts +2 -0
  6. package/bundled-types/app-registry.d.ts +74 -0
  7. package/bundled-types/channels.d.ts +2 -0
  8. package/bundled-types/components.d.ts +1 -0
  9. package/bundled-types/core-agent.d.ts +265 -0
  10. package/bundled-types/core-ai.d.ts +170 -0
  11. package/bundled-types/core-base-agent.d.ts +89 -0
  12. package/bundled-types/core-channels.d.ts +42 -0
  13. package/bundled-types/core-components.d.ts +21 -0
  14. package/bundled-types/core-endpoints.d.ts +198 -0
  15. package/bundled-types/core-entities.d.ts +276 -0
  16. package/bundled-types/core-entity-do.d.ts +119 -0
  17. package/bundled-types/core-events.d.ts +52 -0
  18. package/bundled-types/core-file-storage.d.ts +216 -0
  19. package/bundled-types/core-integration-entities.d.ts +147 -0
  20. package/bundled-types/core-integrations.d.ts +143 -0
  21. package/bundled-types/core-routes.d.ts +33 -0
  22. package/bundled-types/core-scheduler.d.ts +180 -0
  23. package/bundled-types/core-utils.d.ts +85 -0
  24. package/bundled-types/core-workflow-cloudflare.d.ts +85 -0
  25. package/bundled-types/core-workflow-config.d.ts +18 -0
  26. package/bundled-types/core-workflow-coordinator.d.ts +78 -0
  27. package/bundled-types/core-workflow-instance.d.ts +82 -0
  28. package/bundled-types/core-workflow-types.d.ts +251 -0
  29. package/bundled-types/core-workflows.d.ts +75 -0
  30. package/bundled-types/core-workspace.d.ts +454 -0
  31. package/bundled-types/create-app.d.ts +57 -0
  32. package/bundled-types/endpoints.d.ts +2 -0
  33. package/bundled-types/entities.d.ts +5 -0
  34. package/bundled-types/events.d.ts +2 -0
  35. package/bundled-types/index.d.ts +19 -0
  36. package/bundled-types/integrations.d.ts +2 -0
  37. package/bundled-types/routes.d.ts +2 -0
  38. package/bundled-types/scheduler.d.ts +2 -0
  39. package/bundled-types/storage.d.ts +2 -0
  40. package/bundled-types/test-entry.d.ts +21 -0
  41. package/bundled-types/types.d.ts +1 -0
  42. package/bundled-types/vite.d.ts +23 -0
  43. package/bundled-types/workflows.d.ts +14 -0
  44. package/bundled-types/workspace.d.ts +2 -0
  45. package/dist/__tests__/types-manager.test.d.ts +1 -0
  46. package/dist/__tests__/types-manager.test.js +85 -0
  47. package/dist/api/__tests__/client.test.d.ts +1 -0
  48. package/dist/api/__tests__/client.test.js +264 -0
  49. package/dist/api/client.d.ts +72 -0
  50. package/dist/api/client.js +144 -0
  51. package/dist/auth/__tests__/store.test.d.ts +1 -0
  52. package/dist/auth/__tests__/store.test.js +103 -0
  53. package/dist/auth/browser.d.ts +2 -0
  54. package/dist/auth/browser.js +7 -0
  55. package/dist/auth/store.d.ts +5 -0
  56. package/dist/auth/store.js +33 -0
  57. package/dist/commands/clone.d.ts +2 -0
  58. package/dist/commands/clone.js +90 -0
  59. package/dist/commands/deploy.d.ts +2 -0
  60. package/dist/commands/deploy.js +43 -0
  61. package/dist/commands/dev.d.ts +2 -0
  62. package/dist/commands/dev.js +188 -0
  63. package/dist/commands/init.d.ts +2 -0
  64. package/dist/commands/init.js +87 -0
  65. package/dist/commands/login.d.ts +2 -0
  66. package/dist/commands/login.js +32 -0
  67. package/dist/commands/logout.d.ts +2 -0
  68. package/dist/commands/logout.js +13 -0
  69. package/dist/commands/logs.d.ts +2 -0
  70. package/dist/commands/logs.js +166 -0
  71. package/dist/generated/bundled-types.d.ts +1 -0
  72. package/dist/generated/bundled-types.js +44 -0
  73. package/dist/generated/version.d.ts +1 -0
  74. package/dist/generated/version.js +2 -0
  75. package/dist/git/__tests__/credentials.test.d.ts +1 -0
  76. package/dist/git/__tests__/credentials.test.js +128 -0
  77. package/dist/git/auto-commit.d.ts +3 -0
  78. package/dist/git/auto-commit.js +209 -0
  79. package/dist/git/credentials.d.ts +15 -0
  80. package/dist/git/credentials.js +65 -0
  81. package/dist/index.d.ts +1 -0
  82. package/dist/index.js +31 -0
  83. package/dist/logs/tailer.d.ts +13 -0
  84. package/dist/logs/tailer.js +135 -0
  85. package/dist/template/manifest.d.ts +17 -0
  86. package/dist/template/manifest.js +102 -0
  87. package/dist/types-manager.d.ts +1 -0
  88. package/dist/types-manager.js +35 -0
  89. package/dist/types.d.ts +27 -0
  90. package/dist/types.js +1 -0
  91. package/dist/utils/__tests__/prompt.test.d.ts +1 -0
  92. package/dist/utils/__tests__/prompt.test.js +103 -0
  93. package/dist/utils/fs.d.ts +5 -0
  94. package/dist/utils/fs.js +23 -0
  95. package/dist/utils/prompt.d.ts +4 -0
  96. package/dist/utils/prompt.js +34 -0
  97. package/dist/utils/zip.d.ts +1 -0
  98. package/dist/utils/zip.js +17 -0
  99. package/package.json +66 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Runwork
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # runwork
2
+
3
+ The CLI for [Runwork](https://www.runwork.ai) -- develop, preview, and deploy Runwork apps from your local machine using any editor or AI coding tool.
4
+
5
+ ## The Runwork Platform
6
+
7
+ Runwork is an AI workspace that brings AI agents, custom apps, and human teams into one place. Teams talk to the workspace to get quick answers, automate recurring work, or spin up full custom tools -- without switching between dozens of SaaS products.
8
+
9
+ This CLI is the local development interface to the platform. You write TypeScript, and the platform handles deployment, infrastructure, AI, and integrations:
10
+
11
+ - **Full-stack apps, zero infrastructure** -- Data storage, file hosting, background jobs, durable workflows, AI, and 3,200+ third-party integrations are all built into the platform. You write application code; Runwork runs it.
12
+ - **Zero to app in seconds** -- Describe what you need and Runwork generates it. Developers customize with code using the [`@runworkai/framework`](https://www.npmjs.com/package/@runworkai/framework).
13
+ - **Instant deployments** -- Push code and get a live URL. Preview environments while you develop, production at the edge.
14
+ - **Built-in AI agents** -- Conversational agents that read data, take actions, and coordinate across apps. No API keys or model configuration to manage.
15
+ - **Connected apps** -- Apps in a workspace share entities, call each other's APIs, communicate through channels, and present a unified experience.
16
+ - **Every app is an MCP server and a skill** -- Deploy an app, and it automatically becomes an MCP server and a callable skill. Your AI tools and workspace agents can use your apps directly -- completing the loop from development to AI consumption.
17
+ - **AI-native local development** -- Every scaffolded project includes `CLAUDE.md`, `AGENTS.md`, and full framework type definitions in `.runwork/types/`. AI coding tools (Claude Code, Cursor, Codex, or any editor) understand the Runwork framework out of the box -- no setup, no guessing. The CLI keeps code and preview in sync while you or your AI agent write code.
18
+
19
+ ## Install
20
+
21
+ ### macOS / Linux (recommended)
22
+
23
+ ```bash
24
+ curl -fsSL https://runwork.ai/install.sh | sh
25
+ ```
26
+
27
+ ### macOS (Homebrew)
28
+
29
+ ```bash
30
+ brew install runwork-ai/tap/runwork
31
+ ```
32
+
33
+ ### npm
34
+
35
+ ```bash
36
+ npm install -g runwork
37
+ ```
38
+
39
+ ### Direct download
40
+
41
+ Download from [GitHub Releases](https://github.com/runwork-ai/cli/releases).
42
+
43
+ ## Quick Start
44
+
45
+ ```bash
46
+ runwork login # Authenticate with Runwork
47
+ runwork init # Create a new app
48
+ runwork dev # Start developing with live preview
49
+ ```
50
+
51
+ ## Commands
52
+
53
+ | Command | Description |
54
+ |---------|-------------|
55
+ | `runwork login` | Authenticate with the Runwork platform via browser OAuth |
56
+ | `runwork init` | Create a new app -- prompts for name and workspace, scaffolds the project |
57
+ | `runwork clone` | Clone an existing Runwork app to your machine |
58
+ | `runwork dev` | Start local development with live preview and auto-sync |
59
+ | `runwork deploy` | Deploy to production |
60
+ | `runwork logout` | Remove stored credentials |
61
+
62
+ ### `runwork dev`
63
+
64
+ The main development command. When you run `runwork dev`:
65
+
66
+ 1. Pulls the latest code from the Runwork git remote
67
+ 2. Starts a cloud preview sandbox
68
+ 3. Watches local files for changes
69
+ 4. Auto-commits and pushes changes to sync with the preview
70
+ 5. Prints the preview URL for browser access
71
+ 6. Populates `.runwork/types/` with framework type definitions for AI coding tools
72
+
73
+ Edit files in your editor, and changes appear in the preview automatically.
74
+
75
+ ## How It Works
76
+
77
+ Runwork apps are full-stack TypeScript projects built with the [`@runworkai/framework`](https://www.npmjs.com/package/@runworkai/framework). The CLI handles the development lifecycle:
78
+
79
+ - **Git-based sync** -- Your app is backed by a git repository on the Runwork platform. The CLI uses git push/pull to sync code between your machine and the cloud.
80
+ - **Cloud preview** -- `runwork dev` spins up a live preview sandbox. Changes sync automatically as you edit files.
81
+ - **Framework types** -- The CLI populates `.runwork/types/` with framework type definitions so AI coding tools can understand the full API without needing `node_modules`.
82
+ - **Zero config** -- Project settings live in `.runwork.json`. No deployment scripts to manage locally.
83
+
84
+ ## What You Can Build
85
+
86
+ Every Runwork app gets built-in access to:
87
+
88
+ - **Data storage** -- Persistent entities with search, sort, filter, and pagination
89
+ - **AI agents** -- Conversational agents with tool use, memory, and integration access
90
+ - **Backend AI** -- `generateText`, `generateObject`, `streamText` for routes, workflows, and jobs
91
+ - **Durable workflows** -- Multi-step processes that survive failures, with retries and event waiting
92
+ - **Scheduled jobs** -- Cron-based background tasks
93
+ - **File storage** -- Upload and manage files and media
94
+ - **Public endpoints** -- Authenticated APIs for external consumers
95
+ - **Cross-app workspaces** -- Shared entities, channels, and notifications between apps
96
+ - **3,200+ integrations** -- OAuth-managed connections to third-party services
97
+
98
+ ## Project Structure
99
+
100
+ After `runwork init`, your project looks like this:
101
+
102
+ ```
103
+ my-app/
104
+ .runwork.json # App config (app ID, workspace, remote URL)
105
+ .runwork/
106
+ blueprint.json # App feature blueprint (entities, agents, etc.)
107
+ types/ # Framework type definitions (auto-populated)
108
+ worker/ # Backend code
109
+ entities.ts # Data entities
110
+ routes.ts # API routes
111
+ agents.ts # AI agents
112
+ workflows.ts # Durable workflows
113
+ schedules.ts # Scheduled jobs
114
+ endpoints.ts # Public API endpoints
115
+ src/ # Frontend React code
116
+ pages/ # Page components
117
+ components/ # UI components
118
+ shared/types.ts # Shared types between frontend and backend
119
+ ```
120
+
121
+ ## Requirements
122
+
123
+ - Git
124
+ - A [Runwork](https://www.runwork.ai) account
125
+ - Node.js 18+ (only required when installing via npm)
126
+
127
+ ## Links
128
+
129
+ - [Runwork Platform](https://www.runwork.ai)
130
+ - [`@runworkai/framework`](https://www.npmjs.com/package/@runworkai/framework) -- The TypeScript framework for building Runwork apps
131
+
132
+ ## License
133
+
134
+ MIT
package/bin/runwork.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import('../dist/index.js');
@@ -0,0 +1,3 @@
1
+ export { INITIAL_AGENT_STATE, createAgentRegistry, getEntityToolDefs, getIntegrationToolDefs, getCustomToolDefs, getAgentToolDefs, toolDefToMeta, getAgentToolMeta, agentRoutes, entityListSchema, entityGetSchema, integrationApiSchema, } from './core-agent';
2
+ export type { AgentState, AgentMessage, MemoryStrategy, AgentDefinition, AgentToolDefinition, AgentToolContext, AgentRegistry, RegisterAgentRequest, AgentToolMeta, AgentToolDef, AgentToolStatus, IntegrationStatus, AgentRuntimeStatus, } from './core-agent';
3
+ export { BaseAgent } from './core-base-agent';
@@ -0,0 +1,2 @@
1
+ export { tool, generateText, streamText, generateObject, aiRoutes, } from './core-ai';
2
+ export type { ModelMessage, ModelMessage as CoreMessage, Tool, ToolSet, ToolChoice, TextPart, ImagePart, FilePart, UserContent, DataContent, ChatMessage, AICallSettings, GenerateTextOptions, StreamTextOptions, GenerateObjectOptions, } from './core-ai';
@@ -0,0 +1,74 @@
1
+ /**
2
+ * App Registry - Global registration point for user-defined application code.
3
+ *
4
+ * Framework core files call the getRegistered*() functions to access user code
5
+ * instead of importing directly from user files. This enables the framework
6
+ * to be distributed as an npm package while still accessing user-defined
7
+ * agents, entities, routes, etc.
8
+ *
9
+ * Users register their code via createApp() which calls setAppConfig() internally.
10
+ */
11
+ import type { AgentDefinition } from './core-agent';
12
+ import type { EntityClass } from './core-entities';
13
+ import type { ScheduledJob } from './core-scheduler';
14
+ import type { WorkflowDefinition } from './core-workflow-types';
15
+ import type { EndpointDefinition } from './core-endpoints';
16
+ import type { IntegrationRequirement } from './core-integrations';
17
+ import type { Hono } from 'hono';
18
+ import type { Env } from './core-utils';
19
+ /** Component metadata for workspace registration */
20
+ export interface ComponentMetadata {
21
+ tag: string;
22
+ description?: string;
23
+ attributes?: Record<string, string>;
24
+ }
25
+ /** Component definition for registerable UI components */
26
+ export interface ComponentDefinition {
27
+ name: string;
28
+ title: string;
29
+ description?: string;
30
+ chatId?: string;
31
+ frontend: boolean;
32
+ backend: boolean;
33
+ metadata: ComponentMetadata;
34
+ }
35
+ /** A user-defined route function or an EndpointDefinition */
36
+ export type AppRoute = (app: Hono<{
37
+ Bindings: Env;
38
+ }>) => void;
39
+ export type RouteEntry = AppRoute | EndpointDefinition;
40
+ /**
41
+ * Configuration for all registerable application features.
42
+ */
43
+ export interface AppConfig {
44
+ agents: AgentDefinition[];
45
+ entities: Array<EntityClass<{
46
+ id: string;
47
+ }>>;
48
+ routes: RouteEntry[];
49
+ endpoints: EndpointDefinition[];
50
+ workflows: WorkflowDefinition[];
51
+ schedules: ScheduledJob[];
52
+ integrationRequirements: IntegrationRequirement[];
53
+ components: ComponentDefinition[];
54
+ }
55
+ /**
56
+ * Store the app configuration. Called internally by createApp().
57
+ * Should not be called directly by user code.
58
+ */
59
+ export declare function setAppConfig(config: AppConfig): void;
60
+ /**
61
+ * Retrieve the full app configuration.
62
+ * Throws if createApp() has not been called yet.
63
+ */
64
+ export declare function getAppConfig(): AppConfig;
65
+ export declare function getRegisteredAgents(): AgentDefinition[];
66
+ export declare function getRegisteredEntities(): Array<EntityClass<{
67
+ id: string;
68
+ }>>;
69
+ export declare function getRegisteredRoutes(): RouteEntry[];
70
+ export declare function getRegisteredEndpoints(): EndpointDefinition[];
71
+ export declare function getRegisteredWorkflows(): WorkflowDefinition[];
72
+ export declare function getRegisteredSchedules(): ScheduledJob[];
73
+ export declare function getRegisteredIntegrationRequirements(): IntegrationRequirement[];
74
+ export declare function getRegisteredComponents(): ComponentDefinition[];
@@ -0,0 +1,2 @@
1
+ export { postToChannel } from './core-channels';
2
+ export type { PostToChannelParams } from './core-channels';
@@ -0,0 +1 @@
1
+ export { componentRoutes } from './core-components';
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Core Agent Types and Utilities
3
+ * DO NOT MODIFY THIS FILE - You may break the agent functionality
4
+ *
5
+ * This module provides types and utilities for AI agents.
6
+ * The actual agent implementation is in core-base-agent.ts.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // In agents.ts
11
+ * import type { AgentDefinition } from './core-agent';
12
+ *
13
+ * const supportAgent: AgentDefinition = {
14
+ * name: 'support-assistant',
15
+ * description: 'Helps users with common questions',
16
+ * systemPrompt: 'You are a helpful support assistant...',
17
+ * integrations: ['slack', 'github'],
18
+ * entities: ['ticket', 'user'],
19
+ * };
20
+ *
21
+ * export const APP_AGENTS: AgentDefinition[] = [supportAgent];
22
+ * ```
23
+ */
24
+ import { z } from 'zod';
25
+ import type { Env } from './core-utils';
26
+ import type { IntegrationClient } from './core-integrations';
27
+ /**
28
+ * Agent state persisted across conversations
29
+ */
30
+ export interface AgentState {
31
+ /** Conversation history */
32
+ messages: AgentMessage[];
33
+ /** Custom memory data */
34
+ memory: Record<string, unknown>;
35
+ /** Session metadata */
36
+ sessionId: string;
37
+ /** User identifier for per-user memory */
38
+ userId?: string;
39
+ /** Last activity timestamp */
40
+ lastActivityAt: number;
41
+ }
42
+ /**
43
+ * Message in agent conversation
44
+ */
45
+ export interface AgentMessage {
46
+ id: string;
47
+ role: 'user' | 'assistant' | 'system' | 'tool';
48
+ content: string;
49
+ timestamp: number;
50
+ toolCalls?: Array<{
51
+ id: string;
52
+ name: string;
53
+ arguments: Record<string, unknown>;
54
+ }>;
55
+ toolResults?: Array<{
56
+ id: string;
57
+ result: unknown;
58
+ }>;
59
+ }
60
+ /**
61
+ * Memory strategy for agents
62
+ * - session: Memory resets when conversation ends
63
+ * - user: Memory persists per user across conversations
64
+ * - shared: Memory is shared across all users
65
+ */
66
+ export type MemoryStrategy = 'session' | 'user' | 'shared';
67
+ /**
68
+ * Agent definition schema
69
+ */
70
+ export interface AgentDefinition {
71
+ /** Unique agent name (kebab-case, e.g., 'support-assistant') */
72
+ name: string;
73
+ /** Human-readable description */
74
+ description: string;
75
+ /** System prompt defining agent behavior */
76
+ systemPrompt: string;
77
+ /** Agent type for UI hints */
78
+ type?: 'conversational' | 'task';
79
+ /** Integration IDs the agent can access */
80
+ integrations?: string[];
81
+ /** Entity names the agent can read/write */
82
+ entities?: string[];
83
+ /** Memory strategy */
84
+ memoryStrategy?: MemoryStrategy;
85
+ /** Custom tools for this agent */
86
+ customTools?: AgentToolDefinition[];
87
+ }
88
+ /**
89
+ * Custom tool definition for agents
90
+ */
91
+ export interface AgentToolDefinition {
92
+ name: string;
93
+ description: string;
94
+ parameters: z.ZodObject<z.ZodRawShape>;
95
+ execute: (args: Record<string, unknown>, context: AgentToolContext) => Promise<unknown>;
96
+ }
97
+ /**
98
+ * Context passed to tool execution
99
+ */
100
+ export interface AgentToolContext {
101
+ env: Env;
102
+ agentName: string;
103
+ integrationClient: IntegrationClient;
104
+ state: AgentState;
105
+ }
106
+ /**
107
+ * Initial state for new agent instances
108
+ */
109
+ export declare const INITIAL_AGENT_STATE: AgentState;
110
+ /**
111
+ * Agent registry - maps agent names to their definitions
112
+ */
113
+ export type AgentRegistry = Record<string, AgentDefinition>;
114
+ /**
115
+ * Create an agent registry from an array of definitions.
116
+ *
117
+ * NOTE: This function is defensive against undefined/null inputs because it's called
118
+ * at module-level in core-base-agent.ts. During Vite HMR, when files are being rewritten,
119
+ * there's a race condition where APP_AGENTS may be undefined momentarily. Without
120
+ * this guard, the worker crashes with "definitions is not iterable", which triggers
121
+ * cascading HMR failures and eventually causes "@cloudflare/vite-plugin" to lose its
122
+ * miniflare instance ("Expected `miniflare` to be defined" error).
123
+ */
124
+ export declare function createAgentRegistry(definitions?: AgentDefinition[] | null): AgentRegistry;
125
+ /**
126
+ * Workspace agent registration request
127
+ */
128
+ export interface RegisterAgentRequest {
129
+ appId: string;
130
+ appName: string;
131
+ agentName: string;
132
+ description: string;
133
+ type: 'conversational' | 'task';
134
+ integrations: string[];
135
+ entities: string[];
136
+ tools?: AgentToolMeta[];
137
+ }
138
+ /**
139
+ * Tool metadata for API responses (JSON-serializable, no Zod)
140
+ */
141
+ export interface AgentToolMeta {
142
+ name: string;
143
+ description: string;
144
+ source: 'entity' | 'integration' | 'custom';
145
+ sourceId?: string;
146
+ parameters: {
147
+ type: 'object';
148
+ properties: Record<string, {
149
+ type: string;
150
+ description?: string;
151
+ }>;
152
+ required?: string[];
153
+ };
154
+ }
155
+ /**
156
+ * Tool definition with Zod schema (for buildTools)
157
+ */
158
+ export interface AgentToolDef {
159
+ name: string;
160
+ description: string;
161
+ source: 'entity' | 'integration' | 'custom';
162
+ sourceId?: string;
163
+ parameters: z.ZodObject<z.ZodRawShape>;
164
+ }
165
+ /** Zod schema for entity list tool */
166
+ export declare const entityListSchema: z.ZodObject<{
167
+ limit: z.ZodOptional<z.ZodNumber>;
168
+ cursor: z.ZodOptional<z.ZodString>;
169
+ }, "strip", z.ZodTypeAny, {
170
+ cursor?: string | undefined;
171
+ limit?: number | undefined;
172
+ }, {
173
+ cursor?: string | undefined;
174
+ limit?: number | undefined;
175
+ }>;
176
+ /** Zod schema for entity get tool */
177
+ export declare const entityGetSchema: z.ZodObject<{
178
+ id: z.ZodString;
179
+ }, "strip", z.ZodTypeAny, {
180
+ id: string;
181
+ }, {
182
+ id: string;
183
+ }>;
184
+ /**
185
+ * Get tool definitions for entity access
186
+ */
187
+ export declare function getEntityToolDefs(entities: string[]): AgentToolDef[];
188
+ /** Zod schema for integration API tool */
189
+ export declare const integrationApiSchema: z.ZodObject<{
190
+ method: z.ZodDefault<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "DELETE"]>>;
191
+ endpoint: z.ZodString;
192
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
193
+ }, "strip", z.ZodTypeAny, {
194
+ method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
195
+ endpoint: string;
196
+ data?: Record<string, unknown> | undefined;
197
+ }, {
198
+ endpoint: string;
199
+ data?: Record<string, unknown> | undefined;
200
+ method?: "POST" | "GET" | "PUT" | "PATCH" | "DELETE" | undefined;
201
+ }>;
202
+ /**
203
+ * Get tool definitions for integration access
204
+ */
205
+ export declare function getIntegrationToolDefs(integrations: string[]): AgentToolDef[];
206
+ /**
207
+ * Get tool definitions from custom tools (extracts metadata from AgentToolDefinition)
208
+ */
209
+ export declare function getCustomToolDefs(customTools: AgentToolDefinition[]): AgentToolDef[];
210
+ /**
211
+ * Get all tool definitions for an agent
212
+ */
213
+ export declare function getAgentToolDefs(agent: AgentDefinition): AgentToolDef[];
214
+ /**
215
+ * Convert tool definition to JSON-serializable metadata
216
+ */
217
+ export declare function toolDefToMeta(def: AgentToolDef): AgentToolMeta;
218
+ /**
219
+ * Get all tool metadata for an agent (JSON-serializable)
220
+ * Use this for API responses and workspace registration
221
+ */
222
+ export declare function getAgentToolMeta(agent: AgentDefinition): AgentToolMeta[];
223
+ /**
224
+ * Tool availability status at runtime
225
+ */
226
+ export interface AgentToolStatus {
227
+ name: string;
228
+ source: 'entity' | 'integration' | 'custom';
229
+ sourceId?: string;
230
+ available: boolean;
231
+ reason?: string;
232
+ }
233
+ /**
234
+ * Integration connection status
235
+ */
236
+ export interface IntegrationStatus {
237
+ id: string;
238
+ connected: boolean;
239
+ reason?: string;
240
+ }
241
+ /**
242
+ * Agent runtime status - actual availability of capabilities
243
+ */
244
+ export interface AgentRuntimeStatus {
245
+ /** Agent name */
246
+ name: string;
247
+ /** Whether agent definition was found */
248
+ initialized: boolean;
249
+ /** Integration connection status */
250
+ integrations: IntegrationStatus[];
251
+ /** Tool availability status */
252
+ tools: AgentToolStatus[];
253
+ /** AI proxy configured */
254
+ aiProxyConfigured: boolean;
255
+ /** Timestamp of status check */
256
+ checkedAt: number;
257
+ }
258
+ import type { Hono } from 'hono';
259
+ /**
260
+ * Mount agent routes on the Hono app
261
+ * Provides REST API for AI agent interactions
262
+ */
263
+ export declare function agentRoutes(app: Hono<{
264
+ Bindings: Env;
265
+ }>): void;
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Core AI Utilities
3
+ *
4
+ * Simple LLM helpers for vibe-apps. Provides generateText(), streamText(), and generateObject()
5
+ * functions that work with the platform's AI proxy - no API keys needed.
6
+ *
7
+ * Uses the same AI proxy infrastructure as agents, but without the agent overhead.
8
+ * Ideal for simple completion tasks, text analysis, and structured output generation.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { generateText, streamText, generateObject } from './core-ai';
13
+ *
14
+ * // Simple completion
15
+ * const result = await generateText(env, {
16
+ * prompt: 'Summarize this: ...',
17
+ * });
18
+ * console.log(result.text);
19
+ *
20
+ * // Streaming
21
+ * const stream = await streamText(env, {
22
+ * prompt: 'Write a story about...',
23
+ * });
24
+ * for await (const chunk of stream.textStream) {
25
+ * console.log(chunk);
26
+ * }
27
+ *
28
+ * // Structured output
29
+ * import { z } from 'zod';
30
+ * const result = await generateObject(env, {
31
+ * prompt: 'Extract entities from: ...',
32
+ * schema: z.object({
33
+ * people: z.array(z.string()),
34
+ * places: z.array(z.string()),
35
+ * }),
36
+ * });
37
+ * console.log(result.object);
38
+ * ```
39
+ */
40
+ import { type ModelMessage, type UserContent, type ToolSet, type ToolChoice } from 'ai';
41
+ import type { Hono } from 'hono';
42
+ import type { z } from 'zod';
43
+ import { type Env } from './core-utils';
44
+ export { tool, type ModelMessage, type ModelMessage as CoreMessage, type Tool, type ToolSet, type ToolChoice, type TextPart, type ImagePart, type FilePart, type UserContent, type DataContent, } from 'ai';
45
+ /**
46
+ * Message format for chat-style completions
47
+ */
48
+ export interface ChatMessage {
49
+ role: 'user' | 'assistant' | 'system';
50
+ content: string;
51
+ }
52
+ /**
53
+ * Call settings for LLM requests
54
+ */
55
+ export interface AICallSettings {
56
+ maxOutputTokens?: number;
57
+ temperature?: number;
58
+ topP?: number;
59
+ topK?: number;
60
+ presencePenalty?: number;
61
+ frequencyPenalty?: number;
62
+ stopSequences?: string[];
63
+ seed?: number;
64
+ maxRetries?: number;
65
+ abortSignal?: AbortSignal;
66
+ }
67
+ /**
68
+ * Options for text generation
69
+ */
70
+ export interface GenerateTextOptions extends AICallSettings {
71
+ /** Text prompt string, or content parts array for multimodal input (images, files) */
72
+ prompt?: UserContent;
73
+ /** Chat-style messages (alternative to prompt) - use for multi-turn or complex multimodal */
74
+ messages?: Array<ChatMessage | ModelMessage>;
75
+ /** System prompt for context/behavior */
76
+ system?: string;
77
+ /** Tools for function calling */
78
+ tools?: ToolSet;
79
+ /** How the model should choose which tool to use */
80
+ toolChoice?: ToolChoice<ToolSet>;
81
+ /** Maximum number of tool-use steps */
82
+ maxSteps?: number;
83
+ }
84
+ /**
85
+ * Options for streaming text generation (same parameters as GenerateTextOptions)
86
+ */
87
+ export type StreamTextOptions = GenerateTextOptions;
88
+ /**
89
+ * Options for structured object generation
90
+ */
91
+ export interface GenerateObjectOptions<T> extends Omit<AICallSettings, 'stopSequences'> {
92
+ /** Text prompt string, or content parts array for multimodal input (images, files) */
93
+ prompt?: UserContent;
94
+ /** Chat-style messages (alternative to prompt) - use for multi-turn or complex multimodal */
95
+ messages?: Array<ChatMessage | ModelMessage>;
96
+ /** System prompt for context/behavior */
97
+ system?: string;
98
+ /** Zod schema for structured output */
99
+ schema: z.ZodType<T>;
100
+ }
101
+ /**
102
+ * Generate text completion using the AI proxy.
103
+ *
104
+ * @param env - Worker environment bindings
105
+ * @param options - Generation options (prompt, messages, system)
106
+ * @returns AI SDK result with text, usage stats, etc.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const result = await generateText(env, {
111
+ * prompt: 'Explain quantum computing in simple terms',
112
+ * });
113
+ * console.log(result.text);
114
+ * ```
115
+ */
116
+ export declare function generateText(env: Env, options: GenerateTextOptions): Promise<import("ai").GenerateTextResult<ToolSet, never>>;
117
+ /**
118
+ * Stream text generation using the AI proxy.
119
+ *
120
+ * @param env - Worker environment bindings
121
+ * @param options - Generation options (prompt, messages, system)
122
+ * @returns AI SDK streaming result with textStream, fullStream, etc.
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const result = await streamText(env, {
127
+ * prompt: 'Write a poem about the ocean',
128
+ * });
129
+ *
130
+ * // Option 1: Iterate over text chunks
131
+ * for await (const chunk of result.textStream) {
132
+ * process.stdout.write(chunk);
133
+ * }
134
+ *
135
+ * // Option 2: Return as HTTP streaming response
136
+ * return result.toTextStreamResponse();
137
+ * ```
138
+ */
139
+ export declare function streamText(env: Env, options: StreamTextOptions): Promise<import("ai").StreamTextResult<ToolSet, never>>;
140
+ /**
141
+ * Generate structured output (JSON) using the AI proxy.
142
+ * Uses Zod schema for type-safe structured generation.
143
+ *
144
+ * @param env - Worker environment bindings
145
+ * @param options - Generation options including Zod schema
146
+ * @returns AI SDK result with typed object, usage stats, etc.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * import { z } from 'zod';
151
+ *
152
+ * const result = await generateObject(env, {
153
+ * prompt: 'Extract contact info from: John Smith, john@example.com, 555-1234',
154
+ * schema: z.object({
155
+ * name: z.string(),
156
+ * email: z.string().email(),
157
+ * phone: z.string().optional(),
158
+ * }),
159
+ * });
160
+ * console.log(result.object); // { name: 'John Smith', email: 'john@example.com', phone: '555-1234' }
161
+ * ```
162
+ */
163
+ export declare function generateObject<T>(env: Env, options: GenerateObjectOptions<T>): Promise<import("ai").GenerateObjectResult<(T extends string ? "enum" : "object") extends infer T_1 ? T_1 extends (T extends string ? "enum" : "object") ? T_1 extends "array" ? T[] : T : never : never>>;
164
+ /**
165
+ * Mount AI routes on the Hono app.
166
+ * Provides /api/ai/generate and /api/ai/stream endpoints.
167
+ */
168
+ export declare function aiRoutes(app: Hono<{
169
+ Bindings: Env;
170
+ }>): void;