robotrock 0.8.5 → 1.0.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,219 @@
1
+ import { TaskContextInput, AssignToInput as AssignToInput$1, TaskPriority, ThreadUpdateStatus, TaskResponse, Task, ThreadUpdate, TaskContextFormatVersion, DiscriminatedApprovalResult } from './schemas/index.js';
2
+ import { AssignToInput, AgentChatSeedMessage } from '@robotrock/core';
3
+
4
+ /** A chat created via {@link ChatsApi.create}. */
5
+ type CreatedChat = {
6
+ chatId: string;
7
+ sessionId: string;
8
+ userId?: string;
9
+ agentIdentifier: string;
10
+ deepLink: string;
11
+ };
12
+ type CreateChatResult = {
13
+ tenantSlug: string;
14
+ chats: CreatedChat[];
15
+ };
16
+ type CreateChatInput = {
17
+ /** Agent to run the chat. Required unless `parentChatId` is provided. */
18
+ agentIdentifier?: string;
19
+ /** Spawn a chat from an existing chat; inherits its agent/app/owner and links audit. */
20
+ parentChatId?: string;
21
+ /** Trigger connection id to run the chat under (defaults to the tenant's). */
22
+ connectionId?: string;
23
+ /** Inbox app bucket. Overrides the client `app` when set. */
24
+ app?: string;
25
+ /** Assign to tenant users (email) and/or groups (slug). Narrows inbox visibility. */
26
+ assignTo?: AssignToInput;
27
+ /** Chat title shown in the inbox. */
28
+ title: string;
29
+ /** Seed messages to preload the conversation. Defaults to a welcome message. */
30
+ messages?: AgentChatSeedMessage[];
31
+ /** How the chat was created (statistics/audit). @default "api" */
32
+ source?: string;
33
+ };
34
+ type CloseChatOptions = {
35
+ /** Optional human-readable reason recorded on the audit trail. */
36
+ reason?: string;
37
+ };
38
+ interface ChatsApi {
39
+ /** Create one or more agent chats and assign them (task-style). */
40
+ create(input: CreateChatInput): Promise<CreateChatResult>;
41
+ /** Close (archive) a chat by its public chatId — e.g. when an agent is done. */
42
+ close(chatId: string, options?: CloseChatOptions): Promise<void>;
43
+ }
44
+ /**
45
+ * Build the `client.chats` namespace. Mirrors the `client.tasks` surface for the
46
+ * long-lived chat resource, so a single client creates both tasks and chats.
47
+ */
48
+ declare function createChatsApi(config: {
49
+ baseUrl: string;
50
+ apiKey: string;
51
+ app?: string;
52
+ }): ChatsApi;
53
+
54
+ type RobotRockWebhookConfig = {
55
+ url: string;
56
+ headers?: Record<string, string>;
57
+ };
58
+ interface RobotRockPollingOptions {
59
+ /** Poll interval when no webhook is configured (ms). @default 2000 */
60
+ intervalMs?: number;
61
+ /**
62
+ * Max time to poll when no webhook is configured (ms).
63
+ * Polling also stops when the task's `validUntil` passes, whichever is sooner.
64
+ * @default 86400000 (24h)
65
+ */
66
+ timeoutMs?: number;
67
+ }
68
+ /** Advanced client settings rarely changed by integrators. */
69
+ type RobotRockAdvancedConfig = {
70
+ /** Task context wire format version sent on every request. @default 2 */
71
+ contextVersion?: TaskContextFormatVersion;
72
+ };
73
+ type RobotRockClientBaseConfig = {
74
+ /** Optional override for API key. Falls back to ROBOTROCK_API_KEY. */
75
+ apiKey?: string;
76
+ /**
77
+ * Base URL for the RobotRock API
78
+ * @default "https://api.robotrock.io/v1"
79
+ */
80
+ baseUrl?: string;
81
+ /**
82
+ * Default inbox app bucket for every task from this client.
83
+ * When omitted, the API uses your API key name.
84
+ */
85
+ app?: string;
86
+ /**
87
+ * Agent release version (semver, git SHA, deploy tag).
88
+ * Defaults to `AGENT_VERSION` or `ROBOTROCK_AGENT_VERSION` from env when omitted.
89
+ */
90
+ version?: string;
91
+ /** Advanced settings (context wire format, etc.). */
92
+ advanced?: RobotRockAdvancedConfig;
93
+ };
94
+ /** Client config with a webhook (mutually exclusive with `polling`). */
95
+ type RobotRockWebhookClientConfig = RobotRockClientBaseConfig & {
96
+ webhook: RobotRockWebhookConfig;
97
+ polling?: never;
98
+ };
99
+ /** Client config without a webhook; optional `polling` controls the wait loop. */
100
+ type RobotRockPollingClientConfig = RobotRockClientBaseConfig & {
101
+ webhook?: never;
102
+ polling?: RobotRockPollingOptions;
103
+ };
104
+ type RobotRockConfig = RobotRockWebhookClientConfig | RobotRockPollingClientConfig;
105
+ type SendToHumanActionInput = Omit<TaskContextInput["actions"][number], "handlers">;
106
+ type SendToHumanValidUntil = Date | string;
107
+ type SendToHumanInput<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]> = Omit<TaskContextInput, "app" | "actions" | "contextVersion" | "version" | "validUntil"> & {
108
+ actions: A;
109
+ /** Task deadline; serialized to an ISO 8601 string on the wire. */
110
+ validUntil?: SendToHumanValidUntil;
111
+ /** Optional idempotency key to prevent duplicate tasks */
112
+ idempotencyKey?: string;
113
+ /** Assign to tenant users (email) and/or groups (slug). Narrows inbox visibility. */
114
+ assignTo?: AssignToInput$1;
115
+ /**
116
+ * Groups related tasks together in the inbox. Omit to let the server generate
117
+ * one (returned as `task.threadId`) and reuse it on later tasks in the thread.
118
+ */
119
+ threadId?: string;
120
+ /**
121
+ * Optional thread priority. When set, applies to the whole thread and
122
+ * overwrites any previous priority. Omit on later tasks to leave unchanged.
123
+ */
124
+ priority?: TaskPriority;
125
+ /**
126
+ * Optional initial status update logged against the task's thread. Shows in
127
+ * the inbox status bar and the thread update log.
128
+ */
129
+ update?: {
130
+ /** A short status update (1-2 sentences). */
131
+ message: string;
132
+ /** Lifecycle status for the icon/color in the status bar. @default "info" */
133
+ status?: ThreadUpdateStatus;
134
+ };
135
+ /**
136
+ * Agent release version override. When omitted, uses the client `version`.
137
+ * Used for statistics and feedback analysis.
138
+ */
139
+ version?: string;
140
+ };
141
+ type SendToHumanWithAppInput<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]> = (SendToHumanInput<A> | Readonly<SendToHumanInput<A>>) & {
142
+ /** Inbox app bucket. Overrides the client `app` when set. */
143
+ app?: string;
144
+ };
145
+ type SendUpdateInput = {
146
+ /** The thread to log the update against (from `task.threadId`). */
147
+ threadId: string;
148
+ /** A short status update (1-2 sentences). */
149
+ message: string;
150
+ /** Lifecycle status for the icon/color in the status bar. @default "info" */
151
+ status?: ThreadUpdateStatus;
152
+ };
153
+ type SendToHumanResult<A extends readonly SendToHumanActionInput[] = readonly SendToHumanActionInput[]> = {
154
+ mode: "created";
155
+ task: TaskResponse["task"];
156
+ } | ({
157
+ mode: "handled";
158
+ task: TaskResponse["task"];
159
+ } & DiscriminatedApprovalResult<A>);
160
+
161
+ /** Task CRUD surface, exposed as `client.tasks`. */
162
+ interface TasksApi {
163
+ /** Create a task via POST /v1 without waiting for a human response. */
164
+ create<const A extends readonly SendToHumanActionInput[]>(task: SendToHumanWithAppInput<A>): Promise<TaskResponse["task"]>;
165
+ /** Get a task by public task id. */
166
+ get(taskId: string): Promise<Task | null>;
167
+ /** Cancel a task by public task id. */
168
+ cancel(taskId: string): Promise<void>;
169
+ /** Log a status update against a thread. */
170
+ sendUpdate(input: SendUpdateInput): Promise<ThreadUpdate>;
171
+ }
172
+ /**
173
+ * RobotRock API client for creating and querying human-in-the-loop tasks and
174
+ * chats. CRUD lives under `client.tasks` and `client.chats`; the headline
175
+ * `sendToHuman` verb stays top-level.
176
+ */
177
+ declare class RobotRock {
178
+ private readonly apiKey;
179
+ private readonly baseUrl;
180
+ private readonly app?;
181
+ private readonly agentVersion?;
182
+ private readonly contextVersion;
183
+ private readonly webhook?;
184
+ private readonly polling;
185
+ /** Task CRUD: `create`, `get`, `cancel`, `sendUpdate`. */
186
+ readonly tasks: TasksApi;
187
+ /** Chat CRUD: `create`, `close`. */
188
+ readonly chats: ChatsApi;
189
+ constructor(config: RobotRockConfig);
190
+ private createTaskRequest;
191
+ sendToHuman<const A extends readonly SendToHumanActionInput[]>(task: SendToHumanWithAppInput<A>): Promise<SendToHumanResult<A>>;
192
+ /**
193
+ * Create a task via POST /v1 without waiting for a human response.
194
+ * @deprecated Use `client.tasks.create()` instead.
195
+ */
196
+ createTask<const A extends readonly SendToHumanActionInput[]>(task: SendToHumanWithAppInput<A>): Promise<TaskResponse["task"]>;
197
+ /**
198
+ * Get a task by public task id (returned as `task.taskId` from {@link sendToHuman}).
199
+ * @deprecated Use `client.tasks.get()` instead.
200
+ */
201
+ getTask(taskId: string): Promise<Task | null>;
202
+ /**
203
+ * Log a status update against a thread.
204
+ * @deprecated Use `client.tasks.sendUpdate()` instead.
205
+ */
206
+ sendUpdate(input: SendUpdateInput): Promise<ThreadUpdate>;
207
+ /**
208
+ * Cancel a task by public task id.
209
+ * @deprecated Use `client.tasks.cancel()` instead.
210
+ */
211
+ cancelTask(taskId: string): Promise<void>;
212
+ private getTaskById;
213
+ private sendThreadUpdate;
214
+ private cancelTaskRequest;
215
+ }
216
+ declare function createClient(config: RobotRockConfig): RobotRock;
217
+ declare function attachWebhookToActions(actions: readonly SendToHumanActionInput[], webhook: RobotRockWebhookConfig): TaskContextInput["actions"];
218
+
219
+ export { type ChatsApi as C, RobotRock as R, type SendToHumanActionInput as S, type TasksApi as T, type SendToHumanInput as a, type RobotRockConfig as b, type CloseChatOptions as c, type CreateChatInput as d, type CreateChatResult as e, type CreatedChat as f, type RobotRockAdvancedConfig as g, type RobotRockPollingClientConfig as h, type RobotRockPollingOptions as i, type RobotRockWebhookClientConfig as j, type RobotRockWebhookConfig as k, type SendToHumanResult as l, type SendToHumanValidUntil as m, type SendUpdateInput as n, attachWebhookToActions as o, createChatsApi as p, createClient as q };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,17 @@
1
- import { R as RobotRock, b as RobotRockConfig } from './client-D-XEBOWd.js';
2
- export { c as RobotRockError, d as RobotRockPollingClientConfig, e as RobotRockPollingOptions, f as RobotRockWebhookClientConfig, g as RobotRockWebhookConfig, S as SendToHumanActionInput, a as SendToHumanInput, h as SendToHumanResult, i as SendToHumanValidUntil, j as SendUpdateInput, k as attachWebhookToActions, l as createClient } from './client-D-XEBOWd.js';
1
+ import { R as RobotRock, b as RobotRockConfig } from './client-CzVmjXpz.js';
2
+ export { C as ChatsApi, c as CloseChatOptions, d as CreateChatInput, e as CreateChatResult, f as CreatedChat, g as RobotRockAdvancedConfig, h as RobotRockPollingClientConfig, i as RobotRockPollingOptions, j as RobotRockWebhookClientConfig, k as RobotRockWebhookConfig, S as SendToHumanActionInput, a as SendToHumanInput, l as SendToHumanResult, m as SendToHumanValidUntil, n as SendUpdateInput, T as TasksApi, o as attachWebhookToActions, p as createChatsApi, q as createClient } from './client-CzVmjXpz.js';
3
+ export { AgentChatSeedMessage, CreateAgentChatBody, CreateAgentChatBodyInput, agentChatSeedMessageSchema, createAgentChatBodySchema } from '@robotrock/core';
3
4
  import { Task, DiscriminatedApprovalResult } from './schemas/index.js';
4
- export { AGENT_OTEL_SPANS_MAX, AgentCost, AgentCostTokens, AgentOtel, AgentOtelSpanStatus, AgentOtelSpanSummary, AgentTelemetry, AgentTelemetryInput, AgentToolCalls, ApprovalResult, AssignToInput, CreateTaskBody, CreateTaskBodyInput, DEFAULT_TASK_PRIORITY, DEFAULT_THREAD_UPDATE_STATUS, Handler, InferActionData, LOWEST_TASK_PRIORITY, TASK_PRIORITY_RANK, TaskAction, TaskContext, TaskContextInput, TaskPriority, TaskResponse, TaskResult, TaskStatus, ThreadUpdate, ThreadUpdateBody, ThreadUpdateBodyInput, ThreadUpdateInput, ThreadUpdateResponse, ThreadUpdateSource, ThreadUpdateStatus, TriggerHandler, TupleElementIndices, WebhookHandler, agentCostSchema, agentCostTokensSchema, agentOtelSchema, agentOtelSpanStatusSchema, agentOtelSpanSummarySchema, agentTelemetrySchema, agentToolCallsSchema, assignToSchema, createTaskBodySchema, taskContextSchema, taskPriorities, taskPrioritySchema, threadUpdateBodySchema, threadUpdateInputSchema, threadUpdateStatusSchema, threadUpdateStatuses } from './schemas/index.js';
5
+ export { AgentTelemetry, AgentTelemetryInput, ApprovalResult, AssignToInput, CreateTaskBody, CreateTaskBodyInput, DEFAULT_TASK_PRIORITY, DEFAULT_THREAD_UPDATE_STATUS, Handler, InferActionData, LOWEST_TASK_PRIORITY, TASK_CONTEXT_FORMAT_VERSION, TASK_PRIORITY_RANK, TaskAction, TaskContext, TaskContextFormatVersion, TaskContextInput, TaskPriority, TaskResponse, TaskResult, TaskStatus, ThreadUpdate, ThreadUpdateBody, ThreadUpdateBodyInput, ThreadUpdateInput, ThreadUpdateResponse, ThreadUpdateSource, ThreadUpdateStatus, TriggerHandler, TupleElementIndices, WebhookHandler, agentTelemetrySchema, assignToSchema, createTaskBodySchema, taskContextSchema, taskPriorities, taskPrioritySchema, threadUpdateBodySchema, threadUpdateInputSchema, threadUpdateStatusSchema, threadUpdateStatuses } from './schemas/index.js';
5
6
  import { z } from 'zod';
6
- export { R as RobotRockHandlerWebhookPayload } from './handler-webhook-BqEi6Bk-.js';
7
- export { AgentTelemetryFromOtelOptions, OtelSpanLike, OtelSpanSummaryInput, agentTelemetryFromOtel, toolCallsFromOtelSpans } from './otel/index.js';
7
+ export { E as EndRobotRockHumanWaitSpanOptions, b as RobotRockCreatedTask, c as RobotRockHandledOtelInput, a as RobotRockHandlerWebhookPayload, d as RobotRockHumanWaitOtelSession, e as RobotRockOtelHandle, f as RobotRockOtelRecordOptions, R as RobotRockPlatformOtelFields, g as beginRobotRockHumanWaitOtel, h as captureRobotRockOtelHandle, i as endRobotRockHumanWaitSpan, j as finishRobotRockHumanWaitOtel, r as recordRobotRockHandledToOtel, s as shouldRecordRobotRockOtel, k as startRobotRockHumanWaitSpan, l as stripPlatformOtelFields, t as toRobotRockHandledOtelInput } from './otel-platform-DzHyHkGk.js';
8
+ import '@opentelemetry/api';
9
+
10
+ declare class RobotRockError extends Error {
11
+ readonly statusCode: number;
12
+ readonly response?: unknown | undefined;
13
+ constructor(message: string, statusCode: number, response?: unknown | undefined);
14
+ }
8
15
 
9
16
  /**
10
17
  * Read RobotRock client config from environment variables.
@@ -98,7 +105,7 @@ declare function assertNotPlatformRejectRequest(actionId: string, data?: unknown
98
105
  */
99
106
  declare function shouldStopAgentForHandledAction(actionId: string | undefined): boolean;
100
107
 
101
- declare const robotRockWebhookPayloadSchema: z.ZodObject<{
108
+ declare const robotRockWebhookPayloadBodySchema: z.ZodObject<{
102
109
  taskId: z.ZodString;
103
110
  action: z.ZodObject<{
104
111
  id: z.ZodString;
@@ -108,15 +115,16 @@ declare const robotRockWebhookPayloadSchema: z.ZodObject<{
108
115
  handledBy: z.ZodOptional<z.ZodString>;
109
116
  handledAt: z.ZodString;
110
117
  handlerType: z.ZodString;
111
- headers: z.ZodRecord<z.ZodString, z.ZodString>;
112
118
  }, z.core.$strip>;
119
+ type RobotRockWebhookPayload = z.infer<typeof robotRockWebhookPayloadBodySchema> & {
120
+ headers: Record<string, string>;
121
+ };
113
122
  type RobotRockWebhookErrorCode = "MISSING_WEBHOOK_SECRET" | "MISSING_SIGNATURE" | "INVALID_SIGNATURE" | "INVALID_JSON" | "INVALID_PAYLOAD";
114
123
  declare class RobotRockWebhookError extends Error {
115
124
  readonly code: RobotRockWebhookErrorCode;
116
125
  readonly details?: unknown | undefined;
117
126
  constructor(message: string, code: RobotRockWebhookErrorCode, details?: unknown | undefined);
118
127
  }
119
- type RobotRockWebhookPayload = z.infer<typeof robotRockWebhookPayloadSchema>;
120
128
  interface VerifyRobotRockWebhookOptions {
121
129
  /**
122
130
  * Override shared secret (defaults to ROBOTROCK_WEBHOOK_SECRET).
@@ -137,4 +145,4 @@ interface VerifyRobotRockWebhookOptions {
137
145
  */
138
146
  declare function verifyRobotRockWebhook(request: Request, options?: VerifyRobotRockWebhookOptions): Promise<RobotRockWebhookPayload>;
139
147
 
140
- export { DiscriminatedApprovalResult, type HandledActionInput, type HandledOutcome, PLATFORM_MARK_DONE_ACTION_ID, PLATFORM_MARK_DONE_ACTION_TITLE, PLATFORM_REJECT_REQUEST_ACTION_ID, PLATFORM_REJECT_REQUEST_ACTION_TITLE, PLATFORM_TERMINAL_ACTION_IDS, type PlatformMarkDoneOutcome, type PlatformRejectRequestData, PlatformRejectRequestError, type PlatformRejectRequestOutcome, type PlatformTerminalActionId, RobotRock, RobotRockConfig, RobotRockWebhookError, type RobotRockWebhookErrorCode, type RobotRockWebhookPayload, Task, type TaskActionOutcome, TaskExpiredError, TaskTimeoutError, type VerifyRobotRockWebhookOptions, assertNotPlatformRejectRequest, isPlatformMarkDoneAction, isPlatformRejectRequestAction, isPlatformTerminalAction, parseHandledOutcome, parsePlatformRejectRequestData, resolveRobotRockClient, resolveRobotRockConfig, shouldStopAgentForHandledAction, toDiscriminatedApprovalResult, verifyRobotRockWebhook };
148
+ export { DiscriminatedApprovalResult, type HandledActionInput, type HandledOutcome, PLATFORM_MARK_DONE_ACTION_ID, PLATFORM_MARK_DONE_ACTION_TITLE, PLATFORM_REJECT_REQUEST_ACTION_ID, PLATFORM_REJECT_REQUEST_ACTION_TITLE, PLATFORM_TERMINAL_ACTION_IDS, type PlatformMarkDoneOutcome, type PlatformRejectRequestData, PlatformRejectRequestError, type PlatformRejectRequestOutcome, type PlatformTerminalActionId, RobotRock, RobotRockConfig, RobotRockError, RobotRockWebhookError, type RobotRockWebhookErrorCode, type RobotRockWebhookPayload, Task, type TaskActionOutcome, TaskExpiredError, TaskTimeoutError, type VerifyRobotRockWebhookOptions, assertNotPlatformRejectRequest, isPlatformMarkDoneAction, isPlatformRejectRequestAction, isPlatformTerminalAction, parseHandledOutcome, parsePlatformRejectRequestData, resolveRobotRockClient, resolveRobotRockConfig, shouldStopAgentForHandledAction, toDiscriminatedApprovalResult, verifyRobotRockWebhook };