@heedwork/engine 0.0.0-stage → 0.1.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.
@@ -0,0 +1,9 @@
1
+ import type { Actor } from "@heedwork/core";
2
+ import type { AppContext } from "./app.js";
3
+ import type { getWorkspaceStub } from "./workspace.js";
4
+ export declare function readBearer(request: Request): string | undefined;
5
+ export declare function bearerUnauthorized(): Response;
6
+ export declare function requireAgent(request: Request, app: AppContext, handle: (actor: Extract<Actor, {
7
+ kind: "agent";
8
+ }>, workspace: ReturnType<typeof getWorkspaceStub>, workspaceId: string) => Response | Promise<Response>): Promise<Response>;
9
+ export declare function requireAgentToken(request: Request, { auth, limits, workspace: getWorkspace }: AppContext, handle: (secret: string, workspace: ReturnType<typeof getWorkspaceStub>, workspaceId: string) => Promise<Response>): Promise<Response>;
@@ -0,0 +1,8 @@
1
+ import type { LimitError } from "./seams.js";
2
+ export declare function apiError(status: number, code: string, message: string): Response;
3
+ export declare function workspaceOperationError(error: unknown): {
4
+ status: number;
5
+ code: string;
6
+ message: string;
7
+ };
8
+ export declare function limitResponse(error: LimitError): Response;
package/dist/app.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { TokenAdminEnv } from "./token-admin.js";
2
+ import type { PushEnv } from "./web-push.js";
3
+ import type { Workspace } from "./workspace.js";
4
+ import { getWorkspaceStub } from "./workspace.js";
5
+ import type { AppSeams, WorkspaceSession } from "./seams.js";
6
+ export interface AppEnv extends TokenAdminEnv, PushEnv {
7
+ WORKSPACE: DurableObjectNamespace<Workspace>;
8
+ }
9
+ export interface AppOptions<Bindings extends AppEnv = AppEnv> {
10
+ /** Optional postprocessing for browser session responses, such as sliding cookies. */
11
+ sessionResponse?(request: Request, response: Response, env: Bindings): Promise<Response>;
12
+ /** Enable the admin-secret token bootstrap for this workspace. */
13
+ bootstrapWorkspace?: string;
14
+ }
15
+ export interface SeamContext {
16
+ request: Request;
17
+ /** The resolved browser session, available when checking an authenticated action. */
18
+ session(): WorkspaceSession | undefined;
19
+ /** Returns the request's cached stub for the given workspace. */
20
+ workspace(id: string): ReturnType<typeof getWorkspaceStub>;
21
+ }
22
+ export interface AppContext extends AppSeams, SeamContext {
23
+ ctx: ExecutionContext;
24
+ }
25
+ /** Builds a Worker from seams or a factory for request-bound seams. */
26
+ export declare function createApp<Bindings extends AppEnv = AppEnv>(seams: AppSeams | ((env: Bindings, context: SeamContext) => AppSeams), options?: AppOptions<Bindings>): {
27
+ fetch(request: Request, env: Bindings, ctx: ExecutionContext): Promise<Response>;
28
+ };
package/dist/auth.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { AuthProvider } from "./seams.js";
2
+ export declare const SESSION_COOKIE = "__Host-heed_session";
3
+ export declare function issueSession(email: string, secret: string, sessionId?: string): Promise<string>;
4
+ /** Google and localhost sign-in for the self-hosted, single-workspace deployment. */
5
+ export declare function googleAllowlistAuth(env: AuthEnv): AuthProvider;
6
+ export declare function openSessionId(request: Request): string | undefined;
7
+ /** Sliding session cookies, the dev login hint and the self-hosted token bootstrap. */
8
+ export declare const openAuthOptions: {
9
+ sessionResponse(request: Request, response: Response, env: AuthEnv): Promise<Response>;
10
+ bootstrapWorkspace: string;
11
+ };
12
+ export interface AuthEnv {
13
+ GOOGLE_CLIENT_ID?: string;
14
+ GOOGLE_CLIENT_SECRET?: string;
15
+ SESSION_SECRET?: string;
16
+ ALLOWED_EMAILS?: string;
17
+ DEV_LOGIN_EMAIL?: string;
18
+ }
@@ -0,0 +1,13 @@
1
+ import type { Limits } from "./seams.js";
2
+ import type { SeamContext } from "./app.js";
3
+ export interface BasicLimitsEnv {
4
+ TOKEN_RATE_LIMITER: RateLimit;
5
+ TOKEN_RATE_LIMIT_PER_MINUTE?: string;
6
+ COMMAND_RATE_LIMIT_PER_MINUTE?: string;
7
+ COMMAND_DAILY_LIMIT?: string;
8
+ TRANSCRIBE_DAILY_LIMIT?: string;
9
+ PUSH_RATE_LIMIT_PER_HOUR?: string;
10
+ }
11
+ /** Preserves self-hosted token, command and transcription quotas. */
12
+ export declare function basicLimits(env: BasicLimitsEnv, { request, session, workspace }: SeamContext): Limits;
13
+ export declare function basicPushCap(env: Pick<BasicLimitsEnv, "PUSH_RATE_LIMIT_PER_HOUR">): number;
@@ -0,0 +1,14 @@
1
+ import type { CommandCapabilities, CommandResult } from "@heedwork/core";
2
+ import type { CommandProvider } from "./command-provider.js";
3
+ import type { HumanActor } from "./session.js";
4
+ import type { AppContext } from "./app.js";
5
+ import type { CommandConfiguration } from "./seams.js";
6
+ import { getWorkspaceStub } from "./workspace.js";
7
+ type WorkspaceStub = ReturnType<typeof getWorkspaceStub>;
8
+ export declare function runCommand(workspace: WorkspaceStub, provider: CommandProvider, text: string, request?: {
9
+ app: AppContext;
10
+ actor: HumanActor;
11
+ }): Promise<CommandResult>;
12
+ export declare function commandCapabilities(configuration: CommandConfiguration | null): CommandCapabilities;
13
+ export declare function handleCommandApi(request: Request, actor: HumanActor, app: AppContext, kind: "command" | "transcribe"): Promise<Response>;
14
+ export {};
@@ -0,0 +1,43 @@
1
+ import type { ToolDefinition } from "./command-tools.js";
2
+ import type { KeyProvider } from "./seams.js";
3
+ export interface EnvKeysEnv {
4
+ AI?: Ai;
5
+ WORKERS_AI_COMMAND_MODEL?: string;
6
+ ANTHROPIC_API_KEY?: string;
7
+ ANTHROPIC_COMMAND_MODEL?: string;
8
+ }
9
+ export interface ToolCall {
10
+ id: string;
11
+ name: string;
12
+ input: unknown;
13
+ }
14
+ export interface CommandTurn {
15
+ text: string;
16
+ calls: ToolCall[];
17
+ /** Provider-reported token counts for this model call, when available. */
18
+ usage?: {
19
+ inputTokens: number;
20
+ outputTokens: number;
21
+ };
22
+ }
23
+ export interface ToolReply {
24
+ call: ToolCall;
25
+ content: string;
26
+ isError: boolean;
27
+ }
28
+ export interface CommandExchange {
29
+ turn: CommandTurn;
30
+ replies: ToolReply[];
31
+ }
32
+ export interface CommandProvider {
33
+ /** Model identifier used when recording usage. */
34
+ model?: string;
35
+ next(input: {
36
+ system: string;
37
+ text: string;
38
+ tools: ToolDefinition[];
39
+ history: CommandExchange[];
40
+ }): Promise<CommandTurn>;
41
+ }
42
+ /** Uses self-hosted model settings and the Workers AI binding when available. */
43
+ export declare function envKeys(env: EnvKeysEnv): KeyProvider;
@@ -0,0 +1,172 @@
1
+ import { z } from "zod";
2
+ import type { WorkspaceUser } from "@heedwork/core";
3
+ import type { Workspace } from "./workspace.js";
4
+ export interface ToolDefinition {
5
+ name: string;
6
+ description: string;
7
+ parameters: Record<string, unknown>;
8
+ }
9
+ export declare function compactCanvas(canvas: ReturnType<Workspace["getCanvas"]>, limit?: number, includeLinks?: boolean): {
10
+ items: {
11
+ ref_url?: string | undefined;
12
+ id: string;
13
+ title: string;
14
+ project: string;
15
+ status: "queued" | "active" | "blocked" | "done" | "cancelled";
16
+ parent_id: string | null;
17
+ band: "today" | "this-week" | "later" | "backlog" | "done-today" | "tomorrow" | null;
18
+ }[];
19
+ may_have_more: boolean;
20
+ guidance: string;
21
+ guidance_updated_at: string | null;
22
+ };
23
+ export declare const commandTools: ({
24
+ definition: {
25
+ name: string;
26
+ description: string;
27
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
28
+ project: z.ZodOptional<z.ZodString>;
29
+ parent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
+ query: z.ZodOptional<z.ZodString>;
31
+ include_done: z.ZodDefault<z.ZodBoolean>;
32
+ limit: z.ZodDefault<z.ZodInt>;
33
+ }, z.core.$strict>>;
34
+ };
35
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
36
+ } | {
37
+ definition: {
38
+ name: string;
39
+ description: string;
40
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
41
+ title: z.ZodString;
42
+ external_key: z.ZodOptional<z.ZodString>;
43
+ status: z.ZodOptional<z.ZodEnum<{
44
+ queued: "queued";
45
+ active: "active";
46
+ blocked: "blocked";
47
+ done: "done";
48
+ cancelled: "cancelled";
49
+ }>>;
50
+ agent_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
51
+ note: z.ZodOptional<z.ZodNullable<z.ZodString>>;
52
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
53
+ ref_url: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
54
+ priority: z.ZodOptional<z.ZodInt>;
55
+ scheduled_on: z.ZodOptional<z.ZodNullable<z.ZodISODate>>;
56
+ time_type: z.ZodOptional<z.ZodEnum<{
57
+ flexible: "flexible";
58
+ fixed: "fixed";
59
+ deadline: "deadline";
60
+ }>>;
61
+ time_at: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
62
+ parent_id: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
63
+ project: z.ZodOptional<z.ZodOptional<z.ZodString>>;
64
+ }, z.core.$strict>>;
65
+ };
66
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
67
+ } | {
68
+ definition: {
69
+ name: string;
70
+ description: string;
71
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
72
+ item_id: z.ZodOptional<z.ZodString>;
73
+ external_key: z.ZodOptional<z.ZodString>;
74
+ status: z.ZodOptional<z.ZodEnum<{
75
+ active: "active";
76
+ blocked: "blocked";
77
+ done: "done";
78
+ cancelled: "cancelled";
79
+ }>>;
80
+ ref_url: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
81
+ agent_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
82
+ note: z.ZodOptional<z.ZodNullable<z.ZodString>>;
83
+ }, z.core.$strict>>;
84
+ };
85
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
86
+ } | {
87
+ definition: {
88
+ name: string;
89
+ description: string;
90
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
91
+ item_id: z.ZodString;
92
+ hidden: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<0>, z.ZodLiteral<1>]>>;
93
+ sort_key: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
94
+ layout_pos: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodNumber>>>;
95
+ unlock: z.ZodOptional<z.ZodEnum<{
96
+ priority: "priority";
97
+ scheduled_on: "scheduled_on";
98
+ sort_key: "sort_key";
99
+ layout_pos: "layout_pos";
100
+ }>>;
101
+ title: z.ZodOptional<z.ZodString>;
102
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
103
+ ref_url: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
104
+ priority: z.ZodOptional<z.ZodInt>;
105
+ scheduled_on: z.ZodOptional<z.ZodNullable<z.ZodISODate>>;
106
+ time_type: z.ZodOptional<z.ZodEnum<{
107
+ flexible: "flexible";
108
+ fixed: "fixed";
109
+ deadline: "deadline";
110
+ }>>;
111
+ time_at: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
112
+ parent_id: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
113
+ project: z.ZodOptional<z.ZodOptional<z.ZodString>>;
114
+ }, z.core.$strict>>;
115
+ };
116
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
117
+ } | {
118
+ definition: {
119
+ name: string;
120
+ description: string;
121
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
122
+ item_id: z.ZodString;
123
+ blocked_by_id: z.ZodString;
124
+ action: z.ZodEnum<{
125
+ add: "add";
126
+ remove: "remove";
127
+ }>;
128
+ }, z.core.$strict>>;
129
+ };
130
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
131
+ } | {
132
+ definition: {
133
+ name: string;
134
+ description: string;
135
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
136
+ item_id: z.ZodString;
137
+ note: z.ZodString;
138
+ notify: z.ZodOptional<z.ZodBoolean>;
139
+ }, z.core.$strict>>;
140
+ };
141
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
142
+ } | {
143
+ definition: {
144
+ name: string;
145
+ description: string;
146
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
147
+ item_id: z.ZodOptional<z.ZodString>;
148
+ external_key: z.ZodOptional<z.ZodString>;
149
+ reason: z.ZodString;
150
+ }, z.core.$strict>>;
151
+ };
152
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
153
+ } | {
154
+ definition: {
155
+ name: string;
156
+ description: string;
157
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
158
+ text: z.ZodString;
159
+ }, z.core.$strict>>;
160
+ };
161
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
162
+ } | {
163
+ definition: {
164
+ name: string;
165
+ description: string;
166
+ parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
167
+ project_id: z.ZodString;
168
+ hidden: z.ZodBoolean;
169
+ }, z.core.$strict>>;
170
+ };
171
+ execute(workspace: Workspace, args: unknown, user: WorkspaceUser | undefined, allowItemCreation: boolean): unknown;
172
+ })[];
@@ -0,0 +1,4 @@
1
+ import type { AppContext } from "./app.js";
2
+ import type { HumanActor } from "./session.js";
3
+ import type { PushEnv } from "./web-push.js";
4
+ export declare function handleHumanApi(request: Request, url: URL, session: HumanActor, env: PushEnv, app: AppContext): Promise<Response>;
@@ -0,0 +1,14 @@
1
+ export { createApp } from "./app.js";
2
+ export type { AppEnv, AppOptions, SeamContext } from "./app.js";
3
+ export { googleAllowlistAuth, openAuthOptions } from "./auth.js";
4
+ export type { AuthEnv } from "./auth.js";
5
+ export { basicLimits } from "./basic-limits.js";
6
+ export type { BasicLimitsEnv } from "./basic-limits.js";
7
+ export { envKeys } from "./command-provider.js";
8
+ export type { CommandExchange, CommandProvider, CommandTurn, EnvKeysEnv, ToolCall, ToolReply, } from "./command-provider.js";
9
+ export type { ToolDefinition } from "./command-tools.js";
10
+ export { noUsage } from "./seams.js";
11
+ export type { AppSeams, AuthProvider, CommandConfiguration, CommandKeys, KeyProvider, LimitAction, LimitDecision, Limits, UsageEvent, UsageSink, WorkspaceSession, } from "./seams.js";
12
+ export { Workspace } from "./workspace.js";
13
+ export type { WorkspaceEnv } from "./workspace.js";
14
+ export { default } from "./worker.js";