@hachej/boring-ask-user 0.1.13
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.
- package/README.md +266 -0
- package/dist/front/index.d.ts +17 -0
- package/dist/front/index.js +546 -0
- package/dist/server/index.d.ts +205 -0
- package/dist/server/index.js +1011 -0
- package/dist/shared/index.d.ts +3443 -0
- package/dist/shared/index.js +305 -0
- package/dist/types-CF72YmK-.d.ts +193 -0
- package/package.json +72 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { UiBridge, WorkspaceServerPlugin } from '@hachej/boring-workspace/server';
|
|
2
|
+
import { A as AskUserQuestion, a as AskUserAnswer, b as AskUserTranscriptEvent, c as AskUserToolResult, d as AskUserCancelReason, e as AskUserRequest, Q as QuestionsCommand, f as AskUserField, g as AskUserAnswerValue } from '../types-CF72YmK-.js';
|
|
3
|
+
export { h as ASK_USER_PLUGIN_ID } from '../types-CF72YmK-.js';
|
|
4
|
+
import { FastifyRequest, FastifyInstance } from 'fastify';
|
|
5
|
+
|
|
6
|
+
declare class AskUserStoreError extends Error {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
constructor(code: string, message: string);
|
|
9
|
+
}
|
|
10
|
+
type AskUserStoreChange = {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
questionId?: string;
|
|
13
|
+
reason: "create" | "answer" | "cancel" | "abandon" | "clear" | "transcript";
|
|
14
|
+
};
|
|
15
|
+
type AskUserStoreListener = (change: AskUserStoreChange) => void;
|
|
16
|
+
interface AskUserStore {
|
|
17
|
+
getPending(sessionId: string): Promise<AskUserQuestion | null>;
|
|
18
|
+
getByQuestionId(questionId: string): Promise<AskUserQuestion | null>;
|
|
19
|
+
createPending(question: AskUserQuestion): Promise<void>;
|
|
20
|
+
answer(questionId: string, answer: AskUserAnswer): Promise<void>;
|
|
21
|
+
cancel(questionId: string): Promise<void>;
|
|
22
|
+
markAbandoned(questionId: string): Promise<void>;
|
|
23
|
+
clearPending(sessionId: string): Promise<void>;
|
|
24
|
+
appendTranscriptEvent(event: AskUserTranscriptEvent): Promise<void>;
|
|
25
|
+
listTranscriptEvents(sessionId: string): Promise<AskUserTranscriptEvent[]>;
|
|
26
|
+
getTranscriptEventsForQuestion(questionId: string): Promise<AskUserTranscriptEvent[]>;
|
|
27
|
+
subscribe(listener: AskUserStoreListener): () => void;
|
|
28
|
+
}
|
|
29
|
+
declare class FileAskUserStore implements AskUserStore {
|
|
30
|
+
private readonly filePath;
|
|
31
|
+
private state;
|
|
32
|
+
private writeChain;
|
|
33
|
+
private readonly listeners;
|
|
34
|
+
constructor(filePath: string);
|
|
35
|
+
getPending(sessionId: string): Promise<AskUserQuestion | null>;
|
|
36
|
+
getByQuestionId(questionId: string): Promise<AskUserQuestion | null>;
|
|
37
|
+
createPending(question: AskUserQuestion): Promise<void>;
|
|
38
|
+
answer(questionId: string, answer: AskUserAnswer): Promise<void>;
|
|
39
|
+
cancel(questionId: string): Promise<void>;
|
|
40
|
+
markAbandoned(questionId: string): Promise<void>;
|
|
41
|
+
clearPending(sessionId: string): Promise<void>;
|
|
42
|
+
appendTranscriptEvent(event: AskUserTranscriptEvent): Promise<void>;
|
|
43
|
+
listTranscriptEvents(sessionId: string): Promise<AskUserTranscriptEvent[]>;
|
|
44
|
+
getTranscriptEventsForQuestion(questionId: string): Promise<AskUserTranscriptEvent[]>;
|
|
45
|
+
subscribe(listener: AskUserStoreListener): () => void;
|
|
46
|
+
private mutate;
|
|
47
|
+
private load;
|
|
48
|
+
private save;
|
|
49
|
+
private emit;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class AskUserRuntimeError extends Error {
|
|
53
|
+
readonly code: string;
|
|
54
|
+
constructor(code: string, message: string);
|
|
55
|
+
}
|
|
56
|
+
interface AskUserCoordinator {
|
|
57
|
+
registerWaiter(questionId: string, sessionId: string, signal?: AbortSignal): Promise<AskUserToolResult>;
|
|
58
|
+
hasWaiter(questionId: string): boolean;
|
|
59
|
+
resolveAnswered(questionId: string, answer: AskUserAnswer): boolean;
|
|
60
|
+
resolveCancelled(questionId: string, reason: AskUserCancelReason): boolean;
|
|
61
|
+
}
|
|
62
|
+
declare class InProcessAskUserCoordinator implements AskUserCoordinator {
|
|
63
|
+
private readonly waiters;
|
|
64
|
+
registerWaiter(questionId: string, sessionId: string, signal?: AbortSignal): Promise<AskUserToolResult>;
|
|
65
|
+
hasWaiter(questionId: string): boolean;
|
|
66
|
+
resolveAnswered(questionId: string, answer: AskUserAnswer): boolean;
|
|
67
|
+
resolveCancelled(questionId: string, reason: AskUserCancelReason): boolean;
|
|
68
|
+
private resolve;
|
|
69
|
+
}
|
|
70
|
+
type AskUserRuntimeOptions = {
|
|
71
|
+
store: AskUserStore;
|
|
72
|
+
coordinator?: AskUserCoordinator;
|
|
73
|
+
ownerPrincipalId?: string;
|
|
74
|
+
now?: () => Date;
|
|
75
|
+
limits?: {
|
|
76
|
+
perSessionPerMinute?: number;
|
|
77
|
+
perPrincipalPerHour?: number;
|
|
78
|
+
};
|
|
79
|
+
uiBridge?: UiBridge;
|
|
80
|
+
};
|
|
81
|
+
declare class AskUserRuntime {
|
|
82
|
+
readonly coordinator: AskUserCoordinator;
|
|
83
|
+
private readonly store;
|
|
84
|
+
private readonly ownerPrincipalId;
|
|
85
|
+
private readonly now;
|
|
86
|
+
private readonly perSessionPerMinute;
|
|
87
|
+
private readonly perPrincipalPerHour;
|
|
88
|
+
private readonly uiBridge?;
|
|
89
|
+
private readonly sessionBuckets;
|
|
90
|
+
private readonly principalBuckets;
|
|
91
|
+
constructor(options: AskUserRuntimeOptions);
|
|
92
|
+
abandonOrphanedPending(sessionIds: string[]): Promise<void>;
|
|
93
|
+
ask(request: AskUserRequest, signal?: AbortSignal): Promise<AskUserToolResult>;
|
|
94
|
+
submitAnswer(questionId: string, sessionId: string, values: AskUserAnswer["values"]): Promise<"answered" | "abandoned">;
|
|
95
|
+
cancelQuestion(questionId: string, sessionId: string, reason?: AskUserCancelReason): Promise<void>;
|
|
96
|
+
private waitForAnswerWithOpen;
|
|
97
|
+
private openQuestionSurface;
|
|
98
|
+
private waitForAnswer;
|
|
99
|
+
private abandon;
|
|
100
|
+
private createQuestion;
|
|
101
|
+
private assertAllowed;
|
|
102
|
+
private consume;
|
|
103
|
+
private isoNow;
|
|
104
|
+
}
|
|
105
|
+
declare function requireAskUserRuntime(runtime: AskUserRuntime | null | undefined): AskUserRuntime;
|
|
106
|
+
|
|
107
|
+
declare class QuestionsBridgeError extends Error {
|
|
108
|
+
readonly code: string;
|
|
109
|
+
readonly statusCode: number;
|
|
110
|
+
constructor(code: string, message: string, statusCode?: number);
|
|
111
|
+
}
|
|
112
|
+
type QuestionsAuthContext = {
|
|
113
|
+
sessionId: string;
|
|
114
|
+
principalId: string;
|
|
115
|
+
};
|
|
116
|
+
type QuestionsBridgeOptions = {
|
|
117
|
+
store: AskUserStore;
|
|
118
|
+
runtime: AskUserRuntime;
|
|
119
|
+
getAuthContext?: () => QuestionsAuthContext | Promise<QuestionsAuthContext>;
|
|
120
|
+
};
|
|
121
|
+
declare class QuestionsBridge {
|
|
122
|
+
private readonly options;
|
|
123
|
+
constructor(options: QuestionsBridgeOptions);
|
|
124
|
+
handle(command: QuestionsCommand): Promise<{
|
|
125
|
+
ok: true;
|
|
126
|
+
status: string;
|
|
127
|
+
}>;
|
|
128
|
+
private resolveAuth;
|
|
129
|
+
private requireQuestion;
|
|
130
|
+
private assertSession;
|
|
131
|
+
private assertToken;
|
|
132
|
+
}
|
|
133
|
+
declare function constantTimeEqual(expected: string, actual: string): boolean;
|
|
134
|
+
declare function validateAnswerValues(fields: AskUserField[], values: Record<string, AskUserAnswerValue>): void;
|
|
135
|
+
|
|
136
|
+
type QuestionsRoutesOptions = {
|
|
137
|
+
store: AskUserStore;
|
|
138
|
+
runtime: AskUserRuntime;
|
|
139
|
+
getAuthContext?: (request: FastifyRequest) => QuestionsAuthContext | Promise<QuestionsAuthContext>;
|
|
140
|
+
allowedOrigins?: string[];
|
|
141
|
+
csrfHeaderName?: string;
|
|
142
|
+
csrfToken?: string | ((request: FastifyRequest) => string | undefined | Promise<string | undefined>);
|
|
143
|
+
};
|
|
144
|
+
declare function questionsRoutes(app: FastifyInstance, opts: QuestionsRoutesOptions, done: (err?: Error) => void): void;
|
|
145
|
+
|
|
146
|
+
type AskUserServerPluginOptions = {
|
|
147
|
+
workspaceRoot?: string;
|
|
148
|
+
bridge?: UiBridge;
|
|
149
|
+
runtime?: AskUserRuntime;
|
|
150
|
+
store?: AskUserStore;
|
|
151
|
+
sessionId?: string | (() => string);
|
|
152
|
+
routes?: Omit<QuestionsRoutesOptions, "runtime" | "store">;
|
|
153
|
+
onClose?: () => void;
|
|
154
|
+
};
|
|
155
|
+
declare function createAskUserServerPlugin(options: AskUserServerPluginOptions): WorkspaceServerPlugin;
|
|
156
|
+
|
|
157
|
+
type AskUserToolResultPayload = {
|
|
158
|
+
content: Array<{
|
|
159
|
+
type: "text";
|
|
160
|
+
text: string;
|
|
161
|
+
}>;
|
|
162
|
+
details?: unknown;
|
|
163
|
+
isError?: boolean;
|
|
164
|
+
};
|
|
165
|
+
type AskUserToolDefinition = {
|
|
166
|
+
name: "ask_user";
|
|
167
|
+
label: string;
|
|
168
|
+
description: string;
|
|
169
|
+
parameters: Record<string, unknown>;
|
|
170
|
+
promptSnippet?: string;
|
|
171
|
+
execute(toolCallId: string, params: Record<string, unknown>, signal?: AbortSignal, sessionId?: string): Promise<AskUserToolResultPayload>;
|
|
172
|
+
};
|
|
173
|
+
type AskUserToolOptions = {
|
|
174
|
+
runtime: AskUserRuntime;
|
|
175
|
+
sessionId: string | (() => string);
|
|
176
|
+
};
|
|
177
|
+
declare function createAskUserTool(options: AskUserToolOptions): AskUserToolDefinition;
|
|
178
|
+
|
|
179
|
+
type AskUserPendingState = {
|
|
180
|
+
question: AskUserQuestion | null;
|
|
181
|
+
};
|
|
182
|
+
declare class AskUserStatePublisher {
|
|
183
|
+
private readonly store;
|
|
184
|
+
private readonly bridge;
|
|
185
|
+
private unsubscribe?;
|
|
186
|
+
constructor(store: AskUserStore, bridge: UiBridge);
|
|
187
|
+
start(): () => void;
|
|
188
|
+
stop(): void;
|
|
189
|
+
publishSession(sessionId: string): Promise<void>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Default export — adapter for the standard `defaultPluginPackages`
|
|
194
|
+
* load process. The workspace's `pluginEntryResolver` calls a
|
|
195
|
+
* dir-source plugin's default-exported factory with `(options, ctx)`
|
|
196
|
+
* where `ctx = { workspaceRoot, bridge }`. This adapter forwards
|
|
197
|
+
* runtime context into `createAskUserServerPlugin`, which is the
|
|
198
|
+
* existing rich factory consumers use directly when wiring by hand.
|
|
199
|
+
*/
|
|
200
|
+
declare function defaultAskUserServerPlugin(options: Partial<AskUserServerPluginOptions> | undefined, ctx: {
|
|
201
|
+
workspaceRoot: string;
|
|
202
|
+
bridge: AskUserServerPluginOptions["bridge"];
|
|
203
|
+
}): WorkspaceServerPlugin;
|
|
204
|
+
|
|
205
|
+
export { type AskUserCoordinator, type AskUserPendingState, AskUserRuntime, AskUserRuntimeError, type AskUserRuntimeOptions, type AskUserServerPluginOptions, AskUserStatePublisher, type AskUserStore, type AskUserStoreChange, AskUserStoreError, type AskUserStoreListener, type AskUserToolDefinition, type AskUserToolOptions, type AskUserToolResultPayload, FileAskUserStore, InProcessAskUserCoordinator, type QuestionsAuthContext, QuestionsBridge, QuestionsBridgeError, type QuestionsBridgeOptions, type QuestionsRoutesOptions, constantTimeEqual, createAskUserServerPlugin, createAskUserTool, defaultAskUserServerPlugin as default, questionsRoutes, requireAskUserRuntime, validateAnswerValues };
|