@sayknow-cli/bridge-client 0.4.1 → 0.4.3
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,44 @@
|
|
|
1
|
+
export type SdkErrorCode = "invalid_input" | "unknown_operation" | "not_found" | "unavailable" | "timeout" | "connection_closed" | "endpoint_credential_forbidden" | (string & {});
|
|
2
|
+
export declare class SdkClientError extends Error {
|
|
3
|
+
readonly code: SdkErrorCode;
|
|
4
|
+
readonly details: unknown;
|
|
5
|
+
constructor(code: SdkErrorCode, message: string, details?: unknown);
|
|
6
|
+
}
|
|
7
|
+
export interface SdkClientOptions {
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
/** Absolute wall-clock deadline shared by connect, hello, retry, and request work. */
|
|
10
|
+
deadline?: number;
|
|
11
|
+
reconnectAttempts?: number;
|
|
12
|
+
reconnectBackoffMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SdkRequestOptions {
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
idempotencyKey?: string;
|
|
17
|
+
confirm?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export type SdkFrame = Record<string, unknown>;
|
|
20
|
+
export type SdkFrameHandler = (frame: SdkFrame) => void;
|
|
21
|
+
export type SdkReconnectHandler = () => void;
|
|
22
|
+
export type SdkReconnectFailedHandler = (error: SdkClientError) => void;
|
|
23
|
+
/** A transport-only v3 SDK WebSocket client with no host or session authority. */
|
|
24
|
+
export declare class SdkClient {
|
|
25
|
+
#private;
|
|
26
|
+
connectionId?: string;
|
|
27
|
+
constructor(url: string, token: string, options?: SdkClientOptions);
|
|
28
|
+
static connect(url: string, token: string, options?: SdkClientOptions): Promise<SdkClient>;
|
|
29
|
+
connect(): Promise<void>;
|
|
30
|
+
/** Resolves once the current WebSocket has received its server hello frame. */
|
|
31
|
+
awaitHello(): Promise<void>;
|
|
32
|
+
onFrame(handler: SdkFrameHandler): () => void;
|
|
33
|
+
onReconnect(handler: SdkReconnectHandler): () => void;
|
|
34
|
+
onReconnectFailed(handler: SdkReconnectFailedHandler): () => void;
|
|
35
|
+
send(frame: SdkFrame): void;
|
|
36
|
+
request(frame: SdkFrame, timeout?: number | {
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
idempotencyKey?: string;
|
|
39
|
+
}): Promise<SdkFrame>;
|
|
40
|
+
close(): Promise<void>;
|
|
41
|
+
control(operation: string, input?: Record<string, unknown>, options?: SdkRequestOptions): Promise<unknown>;
|
|
42
|
+
query(query: string, input?: Record<string, unknown>, cursor?: string, options?: SdkRequestOptions): Promise<unknown>;
|
|
43
|
+
global(operation: string, input?: Record<string, unknown>, options?: SdkRequestOptions): Promise<unknown>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare const BRIDGE_CLIENT_COMMAND_TYPES: readonly ["prompt", "steer", "follow_up", "abort", "abort_and_prompt", "new_session", "get_state", "set_todos", "set_host_tools", "set_host_uri_schemes", "get_pending_workflow_gates", "set_capabilities", "workflow_gate_response", "set_model", "set_default_model_selection", "cycle_model", "get_available_models", "set_thinking_level", "cycle_thinking_level", "set_steering_mode", "set_follow_up_mode", "set_interrupt_mode", "compact", "set_auto_compaction", "set_auto_retry", "abort_retry", "bash", "abort_bash", "get_session_stats", "export_html", "switch_session", "branch", "get_branch_messages", "get_last_assistant_text", "set_session_name", "handoff", "get_messages", "get_login_providers", "login", "negotiate_unattended"];
|
|
2
|
+
export type BridgeClientCommandType = (typeof BRIDGE_CLIENT_COMMAND_TYPES)[number];
|
|
3
|
+
export type BridgeClientCommand<TType extends BridgeClientCommandType = BridgeClientCommandType> = {
|
|
4
|
+
id?: string;
|
|
5
|
+
type: TType;
|
|
6
|
+
} & Record<string, unknown>;
|
|
7
|
+
export interface BridgeCommandOptions {
|
|
8
|
+
id?: string;
|
|
9
|
+
idempotencyKey?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface BridgeImageCommandOptions extends BridgeCommandOptions {
|
|
12
|
+
images?: unknown[];
|
|
13
|
+
}
|
|
14
|
+
export interface BridgeCommandHelpers {
|
|
15
|
+
prompt(sessionId: string, message: string, options?: BridgeImageCommandOptions & {
|
|
16
|
+
streamingBehavior?: "steer" | "followUp";
|
|
17
|
+
}): Promise<unknown>;
|
|
18
|
+
steer(sessionId: string, message: string, options?: BridgeImageCommandOptions): Promise<unknown>;
|
|
19
|
+
followUp(sessionId: string, message: string, options?: BridgeImageCommandOptions): Promise<unknown>;
|
|
20
|
+
abort(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
21
|
+
abortAndPrompt(sessionId: string, message: string, options?: BridgeImageCommandOptions): Promise<unknown>;
|
|
22
|
+
newSession(sessionId: string, options?: BridgeCommandOptions & {
|
|
23
|
+
parentSession?: string;
|
|
24
|
+
}): Promise<unknown>;
|
|
25
|
+
getState(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
26
|
+
setTodos(sessionId: string, phases: unknown[], options?: BridgeCommandOptions): Promise<unknown>;
|
|
27
|
+
setHostTools(sessionId: string, tools: unknown[], options?: BridgeCommandOptions): Promise<unknown>;
|
|
28
|
+
setHostUriSchemes(sessionId: string, schemes: unknown[], options?: BridgeCommandOptions): Promise<unknown>;
|
|
29
|
+
getPendingWorkflowGates(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
30
|
+
setModel(sessionId: string, provider: string, modelId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
31
|
+
cycleModel(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
32
|
+
getAvailableModels(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
33
|
+
setThinkingLevel(sessionId: string, level: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
34
|
+
cycleThinkingLevel(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
35
|
+
setSteeringMode(sessionId: string, mode: "all" | "one-at-a-time", options?: BridgeCommandOptions): Promise<unknown>;
|
|
36
|
+
setFollowUpMode(sessionId: string, mode: "all" | "one-at-a-time", options?: BridgeCommandOptions): Promise<unknown>;
|
|
37
|
+
setInterruptMode(sessionId: string, mode: "immediate" | "wait", options?: BridgeCommandOptions): Promise<unknown>;
|
|
38
|
+
compact(sessionId: string, options?: BridgeCommandOptions & {
|
|
39
|
+
customInstructions?: string;
|
|
40
|
+
}): Promise<unknown>;
|
|
41
|
+
setAutoCompaction(sessionId: string, enabled: boolean, options?: BridgeCommandOptions): Promise<unknown>;
|
|
42
|
+
setAutoRetry(sessionId: string, enabled: boolean, options?: BridgeCommandOptions): Promise<unknown>;
|
|
43
|
+
abortRetry(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
44
|
+
bash(sessionId: string, command: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
45
|
+
abortBash(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
46
|
+
getSessionStats(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
47
|
+
exportHtml(sessionId: string, options?: BridgeCommandOptions & {
|
|
48
|
+
outputPath?: string;
|
|
49
|
+
}): Promise<unknown>;
|
|
50
|
+
switchSession(sessionId: string, sessionPath: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
51
|
+
branch(sessionId: string, entryId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
52
|
+
getBranchMessages(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
53
|
+
getLastAssistantText(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
54
|
+
setSessionName(sessionId: string, name: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
55
|
+
handoff(sessionId: string, options?: BridgeCommandOptions & {
|
|
56
|
+
customInstructions?: string;
|
|
57
|
+
}): Promise<unknown>;
|
|
58
|
+
getMessages(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
59
|
+
getLoginProviders(sessionId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
60
|
+
login(sessionId: string, providerId: string, options?: BridgeCommandOptions): Promise<unknown>;
|
|
61
|
+
respondGate(sessionId: string, gateId: string, ownerToken: string, answer: unknown, options?: BridgeCommandOptions): Promise<unknown>;
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./client";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface BridgeFrame<TPayload = unknown> {
|
|
2
|
+
protocol_version: number;
|
|
3
|
+
session_id: string;
|
|
4
|
+
seq: number;
|
|
5
|
+
frame_id: string;
|
|
6
|
+
correlation_id?: string;
|
|
7
|
+
type: string;
|
|
8
|
+
payload: TPayload;
|
|
9
|
+
}
|
|
10
|
+
export interface RenderedBridgeFrame {
|
|
11
|
+
seq: number;
|
|
12
|
+
type: string;
|
|
13
|
+
html: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function renderBridgeFrame(frame: BridgeFrame): RenderedBridgeFrame;
|
|
16
|
+
export declare class ReferenceBridgeConsumer {
|
|
17
|
+
#private;
|
|
18
|
+
consume(frame: BridgeFrame): RenderedBridgeFrame;
|
|
19
|
+
renderDocument(): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed `workflow_gate` client helpers (#322).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the server-side workflow-gate contract for bridge consumers: a typed
|
|
5
|
+
* gate frame, the response shape, a frame type-guard, and a headless policy that
|
|
6
|
+
* routes received gates to an agent callback and posts answers back through the
|
|
7
|
+
* existing owner-token ui-response flow.
|
|
8
|
+
*/
|
|
9
|
+
import type { BridgeFrame } from "./reference-consumer";
|
|
10
|
+
export type WorkflowGateStage = "deep-interview" | "ralplan" | "ultragoal";
|
|
11
|
+
export type WorkflowGateKind = "question" | "approval" | "execution";
|
|
12
|
+
export interface WorkflowGateOption {
|
|
13
|
+
value: unknown;
|
|
14
|
+
label: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface WorkflowGate {
|
|
18
|
+
type: "workflow_gate";
|
|
19
|
+
gate_id: string;
|
|
20
|
+
stage: WorkflowGateStage;
|
|
21
|
+
kind: WorkflowGateKind;
|
|
22
|
+
schema: unknown;
|
|
23
|
+
schema_hash: string;
|
|
24
|
+
options?: WorkflowGateOption[];
|
|
25
|
+
context: Record<string, unknown>;
|
|
26
|
+
created_at: string;
|
|
27
|
+
required: true;
|
|
28
|
+
}
|
|
29
|
+
export interface WorkflowGateResponse {
|
|
30
|
+
gate_id: string;
|
|
31
|
+
answer: unknown;
|
|
32
|
+
idempotency_key?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Unattended declaration carried on the bridge handshake (#318/#319). */
|
|
35
|
+
export interface UnattendedDeclaration {
|
|
36
|
+
actor: string;
|
|
37
|
+
budget: {
|
|
38
|
+
max_tokens: number;
|
|
39
|
+
max_tool_calls: number;
|
|
40
|
+
max_wall_time_ms: number;
|
|
41
|
+
max_cost_usd: number;
|
|
42
|
+
};
|
|
43
|
+
scopes: string[];
|
|
44
|
+
action_allowlist: string[];
|
|
45
|
+
}
|
|
46
|
+
/** Type guard: is this bridge frame a fully-formed workflow_gate frame? */
|
|
47
|
+
export declare function isWorkflowGateFrame(frame: BridgeFrame): frame is BridgeFrame<WorkflowGate>;
|
|
48
|
+
/** A callback that produces an answer for a received gate (the agent's "memory"). */
|
|
49
|
+
export type WorkflowGateResolver = (gate: WorkflowGate) => unknown | Promise<unknown>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sayknow-cli/bridge-client",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.3",
|
|
5
5
|
"description": "Transport-only v3 SDK WebSocket client",
|
|
6
6
|
"homepage": "https://sayknow-cli.com",
|
|
7
7
|
"author": "jaybeyond and Sayknow-CLI Contributors",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"client"
|
|
22
22
|
],
|
|
23
23
|
"main": "./src/index.ts",
|
|
24
|
-
"types": "./
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
25
|
"scripts": {
|
|
26
26
|
"check": "biome check . && bun run check:types",
|
|
27
27
|
"check:types": "tsc -p tsconfig.json --noEmit",
|
|
@@ -37,11 +37,12 @@
|
|
|
37
37
|
"bun": ">=1.3.14"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
|
-
"src"
|
|
40
|
+
"src",
|
|
41
|
+
"dist/types"
|
|
41
42
|
],
|
|
42
43
|
"exports": {
|
|
43
44
|
".": {
|
|
44
|
-
"types": "./
|
|
45
|
+
"types": "./dist/types/index.d.ts",
|
|
45
46
|
"import": "./src/index.ts"
|
|
46
47
|
}
|
|
47
48
|
}
|