@uncensoredcode/openbridge 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.
- package/README.md +117 -0
- package/bin/openbridge.js +10 -0
- package/package.json +85 -0
- package/packages/cli/dist/args.d.ts +30 -0
- package/packages/cli/dist/args.js +160 -0
- package/packages/cli/dist/cli.d.ts +2 -0
- package/packages/cli/dist/cli.js +9 -0
- package/packages/cli/dist/index.d.ts +26 -0
- package/packages/cli/dist/index.js +76 -0
- package/packages/runtime/dist/assistant-protocol.d.ts +34 -0
- package/packages/runtime/dist/assistant-protocol.js +121 -0
- package/packages/runtime/dist/execution/in-process.d.ts +14 -0
- package/packages/runtime/dist/execution/in-process.js +45 -0
- package/packages/runtime/dist/execution/types.d.ts +49 -0
- package/packages/runtime/dist/execution/types.js +20 -0
- package/packages/runtime/dist/index.d.ts +86 -0
- package/packages/runtime/dist/index.js +60 -0
- package/packages/runtime/dist/normalizers/index.d.ts +6 -0
- package/packages/runtime/dist/normalizers/index.js +12 -0
- package/packages/runtime/dist/normalizers/legacy-packet.d.ts +6 -0
- package/packages/runtime/dist/normalizers/legacy-packet.js +131 -0
- package/packages/runtime/dist/output-sanitizer.d.ts +23 -0
- package/packages/runtime/dist/output-sanitizer.js +78 -0
- package/packages/runtime/dist/packet-extractor.d.ts +17 -0
- package/packages/runtime/dist/packet-extractor.js +43 -0
- package/packages/runtime/dist/packet-normalizer.d.ts +21 -0
- package/packages/runtime/dist/packet-normalizer.js +47 -0
- package/packages/runtime/dist/prompt-compiler.d.ts +28 -0
- package/packages/runtime/dist/prompt-compiler.js +301 -0
- package/packages/runtime/dist/protocol.d.ts +44 -0
- package/packages/runtime/dist/protocol.js +165 -0
- package/packages/runtime/dist/provider-failure.d.ts +52 -0
- package/packages/runtime/dist/provider-failure.js +236 -0
- package/packages/runtime/dist/provider.d.ts +40 -0
- package/packages/runtime/dist/provider.js +1 -0
- package/packages/runtime/dist/runtime.d.ts +86 -0
- package/packages/runtime/dist/runtime.js +462 -0
- package/packages/runtime/dist/session-bound-provider.d.ts +52 -0
- package/packages/runtime/dist/session-bound-provider.js +366 -0
- package/packages/runtime/dist/tool-name-aliases.d.ts +5 -0
- package/packages/runtime/dist/tool-name-aliases.js +13 -0
- package/packages/runtime/dist/tools/bash.d.ts +9 -0
- package/packages/runtime/dist/tools/bash.js +157 -0
- package/packages/runtime/dist/tools/edit.d.ts +9 -0
- package/packages/runtime/dist/tools/edit.js +94 -0
- package/packages/runtime/dist/tools/index.d.ts +39 -0
- package/packages/runtime/dist/tools/index.js +27 -0
- package/packages/runtime/dist/tools/list-dir.d.ts +9 -0
- package/packages/runtime/dist/tools/list-dir.js +127 -0
- package/packages/runtime/dist/tools/read.d.ts +9 -0
- package/packages/runtime/dist/tools/read.js +56 -0
- package/packages/runtime/dist/tools/registry.d.ts +15 -0
- package/packages/runtime/dist/tools/registry.js +38 -0
- package/packages/runtime/dist/tools/runtime-path.d.ts +7 -0
- package/packages/runtime/dist/tools/runtime-path.js +22 -0
- package/packages/runtime/dist/tools/search-files.d.ts +9 -0
- package/packages/runtime/dist/tools/search-files.js +149 -0
- package/packages/runtime/dist/tools/text-file.d.ts +32 -0
- package/packages/runtime/dist/tools/text-file.js +101 -0
- package/packages/runtime/dist/tools/workspace-path.d.ts +17 -0
- package/packages/runtime/dist/tools/workspace-path.js +70 -0
- package/packages/runtime/dist/tools/write.d.ts +9 -0
- package/packages/runtime/dist/tools/write.js +59 -0
- package/packages/server/dist/bridge/bridge-model-catalog.d.ts +56 -0
- package/packages/server/dist/bridge/bridge-model-catalog.js +100 -0
- package/packages/server/dist/bridge/bridge-runtime-service.d.ts +61 -0
- package/packages/server/dist/bridge/bridge-runtime-service.js +1386 -0
- package/packages/server/dist/bridge/chat-completions/chat-completion-service.d.ts +127 -0
- package/packages/server/dist/bridge/chat-completions/chat-completion-service.js +1026 -0
- package/packages/server/dist/bridge/index.d.ts +335 -0
- package/packages/server/dist/bridge/index.js +45 -0
- package/packages/server/dist/bridge/live-provider-extraction-canary.d.ts +69 -0
- package/packages/server/dist/bridge/live-provider-extraction-canary.js +186 -0
- package/packages/server/dist/bridge/providers/generic-provider-transport.d.ts +53 -0
- package/packages/server/dist/bridge/providers/generic-provider-transport.js +973 -0
- package/packages/server/dist/bridge/providers/provider-session-resolver.d.ts +17 -0
- package/packages/server/dist/bridge/providers/provider-session-resolver.js +95 -0
- package/packages/server/dist/bridge/providers/provider-streams.d.ts +80 -0
- package/packages/server/dist/bridge/providers/provider-streams.js +844 -0
- package/packages/server/dist/bridge/providers/provider-transport-profile.d.ts +194 -0
- package/packages/server/dist/bridge/providers/provider-transport-profile.js +198 -0
- package/packages/server/dist/bridge/providers/web-provider-transport.d.ts +30 -0
- package/packages/server/dist/bridge/providers/web-provider-transport.js +151 -0
- package/packages/server/dist/bridge/state/file-bridge-state-store.d.ts +36 -0
- package/packages/server/dist/bridge/state/file-bridge-state-store.js +164 -0
- package/packages/server/dist/bridge/stores/local-session-package-store.d.ts +23 -0
- package/packages/server/dist/bridge/stores/local-session-package-store.js +548 -0
- package/packages/server/dist/bridge/stores/provider-store.d.ts +94 -0
- package/packages/server/dist/bridge/stores/provider-store.js +143 -0
- package/packages/server/dist/bridge/stores/session-backed-provider-store.d.ts +7 -0
- package/packages/server/dist/bridge/stores/session-backed-provider-store.js +26 -0
- package/packages/server/dist/bridge/stores/session-package-store.d.ts +286 -0
- package/packages/server/dist/bridge/stores/session-package-store.js +1527 -0
- package/packages/server/dist/bridge/stores/session-store.d.ts +120 -0
- package/packages/server/dist/bridge/stores/session-store.js +139 -0
- package/packages/server/dist/cli/index.d.ts +9 -0
- package/packages/server/dist/cli/index.js +6 -0
- package/packages/server/dist/cli/main.d.ts +2 -0
- package/packages/server/dist/cli/main.js +9 -0
- package/packages/server/dist/cli/run-bridge-server-cli.d.ts +54 -0
- package/packages/server/dist/cli/run-bridge-server-cli.js +371 -0
- package/packages/server/dist/client/bridge-api-client.d.ts +61 -0
- package/packages/server/dist/client/bridge-api-client.js +267 -0
- package/packages/server/dist/client/index.d.ts +11 -0
- package/packages/server/dist/client/index.js +11 -0
- package/packages/server/dist/config/bridge-server-config.d.ts +52 -0
- package/packages/server/dist/config/bridge-server-config.js +118 -0
- package/packages/server/dist/config/index.d.ts +20 -0
- package/packages/server/dist/config/index.js +8 -0
- package/packages/server/dist/http/bridge-api-route-context.d.ts +14 -0
- package/packages/server/dist/http/bridge-api-route-context.js +1 -0
- package/packages/server/dist/http/create-bridge-api-server.d.ts +72 -0
- package/packages/server/dist/http/create-bridge-api-server.js +225 -0
- package/packages/server/dist/http/index.d.ts +5 -0
- package/packages/server/dist/http/index.js +5 -0
- package/packages/server/dist/http/parse-request.d.ts +6 -0
- package/packages/server/dist/http/parse-request.js +27 -0
- package/packages/server/dist/http/register-bridge-api-routes.d.ts +7 -0
- package/packages/server/dist/http/register-bridge-api-routes.js +17 -0
- package/packages/server/dist/http/routes/admin-routes.d.ts +7 -0
- package/packages/server/dist/http/routes/admin-routes.js +135 -0
- package/packages/server/dist/http/routes/chat-completions-route.d.ts +7 -0
- package/packages/server/dist/http/routes/chat-completions-route.js +49 -0
- package/packages/server/dist/http/routes/health-routes.d.ts +6 -0
- package/packages/server/dist/http/routes/health-routes.js +7 -0
- package/packages/server/dist/http/routes/message-routes.d.ts +7 -0
- package/packages/server/dist/http/routes/message-routes.js +7 -0
- package/packages/server/dist/index.d.ts +85 -0
- package/packages/server/dist/index.js +28 -0
- package/packages/server/dist/security/bridge-auth.d.ts +9 -0
- package/packages/server/dist/security/bridge-auth.js +41 -0
- package/packages/server/dist/security/cors-policy.d.ts +5 -0
- package/packages/server/dist/security/cors-policy.js +34 -0
- package/packages/server/dist/security/index.d.ts +16 -0
- package/packages/server/dist/security/index.js +12 -0
- package/packages/server/dist/security/redact-sensitive-values.d.ts +19 -0
- package/packages/server/dist/security/redact-sensitive-values.js +67 -0
- package/packages/server/dist/shared/api-schema.d.ts +133 -0
- package/packages/server/dist/shared/api-schema.js +1 -0
- package/packages/server/dist/shared/bridge-api-error.d.ts +17 -0
- package/packages/server/dist/shared/bridge-api-error.js +19 -0
- package/packages/server/dist/shared/index.d.ts +7 -0
- package/packages/server/dist/shared/index.js +7 -0
- package/packages/server/dist/shared/output.d.ts +5 -0
- package/packages/server/dist/shared/output.js +14 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import type { CompiledProviderMessage } from "@uncensoredcode/openbridge/runtime";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { ProviderRecord } from "../stores/provider-store.ts";
|
|
4
|
+
declare const requestTemplateSchema: z.ZodObject<{
|
|
5
|
+
method: z.ZodDefault<z.ZodString>;
|
|
6
|
+
url: z.ZodString;
|
|
7
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
8
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
9
|
+
signing: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
kind: z.ZodLiteral<"z-ai-v1">;
|
|
11
|
+
}, z.core.$strict>>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
declare const sessionPolicySchema: z.ZodObject<{
|
|
14
|
+
requireCookie: z.ZodDefault<z.ZodBoolean>;
|
|
15
|
+
requireBearerToken: z.ZodDefault<z.ZodBoolean>;
|
|
16
|
+
requireUserAgent: z.ZodDefault<z.ZodBoolean>;
|
|
17
|
+
includeExtraHeaders: z.ZodDefault<z.ZodBoolean>;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
declare const promptPolicySchema: z.ZodObject<{
|
|
20
|
+
mode: z.ZodDefault<z.ZodEnum<{
|
|
21
|
+
auto_join: "auto_join";
|
|
22
|
+
flatten: "flatten";
|
|
23
|
+
latest_user: "latest_user";
|
|
24
|
+
}>>;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
declare const responseMappingSchema: z.ZodObject<{
|
|
27
|
+
contentPaths: z.ZodArray<z.ZodString>;
|
|
28
|
+
responseIdPaths: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
29
|
+
conversationIdPaths: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
30
|
+
eventFilters: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
31
|
+
path: z.ZodString;
|
|
32
|
+
equals: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
33
|
+
}, z.core.$strip>>>;
|
|
34
|
+
fallbackResponseId: z.ZodOptional<z.ZodEnum<{
|
|
35
|
+
assistantMessageId: "assistantMessageId";
|
|
36
|
+
userMessageId: "userMessageId";
|
|
37
|
+
}>>;
|
|
38
|
+
trimLeadingAssistantBlock: z.ZodDefault<z.ZodBoolean>;
|
|
39
|
+
allowVisibleTextFinal: z.ZodDefault<z.ZodBoolean>;
|
|
40
|
+
}, z.core.$strict>;
|
|
41
|
+
declare const bindingPolicySchema: z.ZodObject<{
|
|
42
|
+
firstTurn: z.ZodDefault<z.ZodEnum<{
|
|
43
|
+
seed: "seed";
|
|
44
|
+
empty: "empty";
|
|
45
|
+
}>>;
|
|
46
|
+
}, z.core.$strict>;
|
|
47
|
+
declare const bootstrapConfigSchema: z.ZodObject<{
|
|
48
|
+
request: z.ZodObject<{
|
|
49
|
+
method: z.ZodDefault<z.ZodString>;
|
|
50
|
+
url: z.ZodString;
|
|
51
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
52
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
53
|
+
signing: z.ZodOptional<z.ZodObject<{
|
|
54
|
+
kind: z.ZodLiteral<"z-ai-v1">;
|
|
55
|
+
}, z.core.$strict>>;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
conversationIdPath: z.ZodString;
|
|
58
|
+
parentIdPath: z.ZodOptional<z.ZodString>;
|
|
59
|
+
}, z.core.$strict>;
|
|
60
|
+
declare const preflightConfigSchema: z.ZodObject<{
|
|
61
|
+
request: z.ZodObject<{
|
|
62
|
+
method: z.ZodDefault<z.ZodString>;
|
|
63
|
+
url: z.ZodString;
|
|
64
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
65
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
66
|
+
signing: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
kind: z.ZodLiteral<"z-ai-v1">;
|
|
68
|
+
}, z.core.$strict>>;
|
|
69
|
+
}, z.core.$strict>;
|
|
70
|
+
headerBindings: z.ZodDefault<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
71
|
+
proofOfWork: z.ZodOptional<z.ZodObject<{
|
|
72
|
+
kind: z.ZodLiteral<"sha3-wasm-salt-expiry">;
|
|
73
|
+
headerName: z.ZodString;
|
|
74
|
+
wasmUrl: z.ZodString;
|
|
75
|
+
algorithmPath: z.ZodString;
|
|
76
|
+
challengePath: z.ZodString;
|
|
77
|
+
saltPath: z.ZodString;
|
|
78
|
+
signaturePath: z.ZodString;
|
|
79
|
+
difficultyPath: z.ZodString;
|
|
80
|
+
expireAtPath: z.ZodString;
|
|
81
|
+
targetPathPath: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, z.core.$strict>>;
|
|
83
|
+
}, z.core.$strict>;
|
|
84
|
+
declare const seedBindingSchema: z.ZodObject<{
|
|
85
|
+
conversationId: z.ZodString;
|
|
86
|
+
parentId: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.core.$strict>;
|
|
88
|
+
declare const transportFamilySchema: z.ZodEnum<{
|
|
89
|
+
"http-sse": "http-sse";
|
|
90
|
+
"http-json": "http-json";
|
|
91
|
+
"http-connect": "http-connect";
|
|
92
|
+
}>;
|
|
93
|
+
type ProviderTransportFamily = z.infer<typeof transportFamilySchema>;
|
|
94
|
+
type ProviderPromptMode = z.infer<typeof promptPolicySchema>["mode"];
|
|
95
|
+
type ProviderTransportProfile = {
|
|
96
|
+
family: ProviderTransportFamily;
|
|
97
|
+
models: string[];
|
|
98
|
+
prompt: z.infer<typeof promptPolicySchema>;
|
|
99
|
+
binding: z.infer<typeof bindingPolicySchema>;
|
|
100
|
+
session: z.infer<typeof sessionPolicySchema>;
|
|
101
|
+
request: z.infer<typeof requestTemplateSchema>;
|
|
102
|
+
response: z.infer<typeof responseMappingSchema>;
|
|
103
|
+
seedBinding?: z.infer<typeof seedBindingSchema>;
|
|
104
|
+
bootstrap?: z.infer<typeof bootstrapConfigSchema>;
|
|
105
|
+
preflight?: z.infer<typeof preflightConfigSchema>;
|
|
106
|
+
};
|
|
107
|
+
declare function resolveProviderTransportProfile(provider: ProviderRecord | null): {
|
|
108
|
+
prompt: {
|
|
109
|
+
mode: "auto_join" | "flatten" | "latest_user";
|
|
110
|
+
};
|
|
111
|
+
binding: {
|
|
112
|
+
firstTurn: "seed" | "empty";
|
|
113
|
+
};
|
|
114
|
+
session: {
|
|
115
|
+
requireCookie: boolean;
|
|
116
|
+
requireBearerToken: boolean;
|
|
117
|
+
requireUserAgent: boolean;
|
|
118
|
+
includeExtraHeaders: boolean;
|
|
119
|
+
};
|
|
120
|
+
request: {
|
|
121
|
+
method: string;
|
|
122
|
+
url: string;
|
|
123
|
+
headers: Record<string, string>;
|
|
124
|
+
body?: unknown;
|
|
125
|
+
signing?: {
|
|
126
|
+
kind: "z-ai-v1";
|
|
127
|
+
} | undefined;
|
|
128
|
+
};
|
|
129
|
+
response: {
|
|
130
|
+
contentPaths: string[];
|
|
131
|
+
responseIdPaths: string[];
|
|
132
|
+
conversationIdPaths: string[];
|
|
133
|
+
eventFilters: {
|
|
134
|
+
path: string;
|
|
135
|
+
equals: string | number | boolean;
|
|
136
|
+
}[];
|
|
137
|
+
trimLeadingAssistantBlock: boolean;
|
|
138
|
+
allowVisibleTextFinal: boolean;
|
|
139
|
+
fallbackResponseId?: "assistantMessageId" | "userMessageId" | undefined;
|
|
140
|
+
};
|
|
141
|
+
seedBinding?: {
|
|
142
|
+
conversationId: string;
|
|
143
|
+
parentId?: string | undefined;
|
|
144
|
+
} | undefined;
|
|
145
|
+
bootstrap?: {
|
|
146
|
+
request: {
|
|
147
|
+
method: string;
|
|
148
|
+
url: string;
|
|
149
|
+
headers: Record<string, string>;
|
|
150
|
+
body?: unknown;
|
|
151
|
+
signing?: {
|
|
152
|
+
kind: "z-ai-v1";
|
|
153
|
+
} | undefined;
|
|
154
|
+
};
|
|
155
|
+
conversationIdPath: string;
|
|
156
|
+
parentIdPath?: string | undefined;
|
|
157
|
+
} | undefined;
|
|
158
|
+
preflight?: {
|
|
159
|
+
request: {
|
|
160
|
+
method: string;
|
|
161
|
+
url: string;
|
|
162
|
+
headers: Record<string, string>;
|
|
163
|
+
body?: unknown;
|
|
164
|
+
signing?: {
|
|
165
|
+
kind: "z-ai-v1";
|
|
166
|
+
} | undefined;
|
|
167
|
+
};
|
|
168
|
+
headerBindings: Record<string, string>;
|
|
169
|
+
proofOfWork?: {
|
|
170
|
+
kind: "sha3-wasm-salt-expiry";
|
|
171
|
+
headerName: string;
|
|
172
|
+
wasmUrl: string;
|
|
173
|
+
algorithmPath: string;
|
|
174
|
+
challengePath: string;
|
|
175
|
+
saltPath: string;
|
|
176
|
+
signaturePath: string;
|
|
177
|
+
difficultyPath: string;
|
|
178
|
+
expireAtPath: string;
|
|
179
|
+
targetPathPath?: string | undefined;
|
|
180
|
+
} | undefined;
|
|
181
|
+
} | undefined;
|
|
182
|
+
family: "http-sse" | "http-json" | "http-connect";
|
|
183
|
+
models: string[];
|
|
184
|
+
} | null;
|
|
185
|
+
declare function readConfiguredModelIds(config: Record<string, unknown>): string[];
|
|
186
|
+
declare function defaultModelForProviderRecord(provider: ProviderRecord | null): string;
|
|
187
|
+
declare function selectProviderPrompt(messages: CompiledProviderMessage[], mode: ProviderPromptMode): string;
|
|
188
|
+
export declare const providerTransportProfileModule: {
|
|
189
|
+
resolveProviderTransportProfile: typeof resolveProviderTransportProfile;
|
|
190
|
+
readConfiguredModelIds: typeof readConfiguredModelIds;
|
|
191
|
+
defaultModelForProviderRecord: typeof defaultModelForProviderRecord;
|
|
192
|
+
selectProviderPrompt: typeof selectProviderPrompt;
|
|
193
|
+
};
|
|
194
|
+
export type { ProviderPromptMode, ProviderTransportFamily, ProviderTransportProfile };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const nonEmptyString = (field) => z.string().trim().min(1, `${field} is required.`);
|
|
3
|
+
const stringMapSchema = z.record(z.string(), z.string()).default({});
|
|
4
|
+
const requestSigningSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
kind: z.literal("z-ai-v1")
|
|
7
|
+
})
|
|
8
|
+
.strict();
|
|
9
|
+
const requestTemplateSchema = z
|
|
10
|
+
.object({
|
|
11
|
+
method: nonEmptyString("method").default("POST"),
|
|
12
|
+
url: nonEmptyString("url"),
|
|
13
|
+
headers: stringMapSchema,
|
|
14
|
+
body: z.unknown().optional(),
|
|
15
|
+
signing: requestSigningSchema.optional()
|
|
16
|
+
})
|
|
17
|
+
.strict();
|
|
18
|
+
const sessionPolicySchema = z
|
|
19
|
+
.object({
|
|
20
|
+
requireCookie: z.boolean().default(false),
|
|
21
|
+
requireBearerToken: z.boolean().default(false),
|
|
22
|
+
requireUserAgent: z.boolean().default(false),
|
|
23
|
+
includeExtraHeaders: z.boolean().default(true)
|
|
24
|
+
})
|
|
25
|
+
.strict();
|
|
26
|
+
const promptPolicySchema = z
|
|
27
|
+
.object({
|
|
28
|
+
mode: z.enum(["auto_join", "flatten", "latest_user"]).default("auto_join")
|
|
29
|
+
})
|
|
30
|
+
.strict();
|
|
31
|
+
const responseMappingSchema = z
|
|
32
|
+
.object({
|
|
33
|
+
contentPaths: z
|
|
34
|
+
.array(nonEmptyString("content path"))
|
|
35
|
+
.min(1, "At least one content path is required."),
|
|
36
|
+
responseIdPaths: z.array(nonEmptyString("response id path")).default([]),
|
|
37
|
+
conversationIdPaths: z.array(nonEmptyString("conversation id path")).default([]),
|
|
38
|
+
eventFilters: z
|
|
39
|
+
.array(z.object({
|
|
40
|
+
path: nonEmptyString("event filter path"),
|
|
41
|
+
equals: z.union([z.string(), z.number(), z.boolean()])
|
|
42
|
+
}))
|
|
43
|
+
.default([]),
|
|
44
|
+
fallbackResponseId: z.enum(["assistantMessageId", "userMessageId"]).optional(),
|
|
45
|
+
trimLeadingAssistantBlock: z.boolean().default(false),
|
|
46
|
+
allowVisibleTextFinal: z.boolean().default(false)
|
|
47
|
+
})
|
|
48
|
+
.strict();
|
|
49
|
+
const bindingPolicySchema = z
|
|
50
|
+
.object({
|
|
51
|
+
firstTurn: z.enum(["seed", "empty"]).default("seed")
|
|
52
|
+
})
|
|
53
|
+
.strict();
|
|
54
|
+
const bootstrapConfigSchema = z
|
|
55
|
+
.object({
|
|
56
|
+
request: requestTemplateSchema,
|
|
57
|
+
conversationIdPath: nonEmptyString("conversationIdPath"),
|
|
58
|
+
parentIdPath: nonEmptyString("parentIdPath").optional()
|
|
59
|
+
})
|
|
60
|
+
.strict();
|
|
61
|
+
const proofOfWorkConfigSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
kind: z.literal("sha3-wasm-salt-expiry"),
|
|
64
|
+
headerName: nonEmptyString("headerName"),
|
|
65
|
+
wasmUrl: z.string().url(),
|
|
66
|
+
algorithmPath: nonEmptyString("algorithmPath"),
|
|
67
|
+
challengePath: nonEmptyString("challengePath"),
|
|
68
|
+
saltPath: nonEmptyString("saltPath"),
|
|
69
|
+
signaturePath: nonEmptyString("signaturePath"),
|
|
70
|
+
difficultyPath: nonEmptyString("difficultyPath"),
|
|
71
|
+
expireAtPath: nonEmptyString("expireAtPath"),
|
|
72
|
+
targetPathPath: nonEmptyString("targetPathPath").optional()
|
|
73
|
+
})
|
|
74
|
+
.strict();
|
|
75
|
+
const preflightConfigSchema = z
|
|
76
|
+
.object({
|
|
77
|
+
request: requestTemplateSchema,
|
|
78
|
+
headerBindings: stringMapSchema.default({}),
|
|
79
|
+
proofOfWork: proofOfWorkConfigSchema.optional()
|
|
80
|
+
})
|
|
81
|
+
.strict();
|
|
82
|
+
const seedBindingSchema = z
|
|
83
|
+
.object({
|
|
84
|
+
conversationId: nonEmptyString("conversationId"),
|
|
85
|
+
parentId: nonEmptyString("parentId").optional()
|
|
86
|
+
})
|
|
87
|
+
.strict();
|
|
88
|
+
const transportConfigSchema = z
|
|
89
|
+
.object({
|
|
90
|
+
prompt: promptPolicySchema.default({
|
|
91
|
+
mode: "auto_join"
|
|
92
|
+
}),
|
|
93
|
+
binding: bindingPolicySchema.default({
|
|
94
|
+
firstTurn: "seed"
|
|
95
|
+
}),
|
|
96
|
+
session: sessionPolicySchema.default({
|
|
97
|
+
requireCookie: false,
|
|
98
|
+
requireBearerToken: false,
|
|
99
|
+
requireUserAgent: false,
|
|
100
|
+
includeExtraHeaders: true
|
|
101
|
+
}),
|
|
102
|
+
request: requestTemplateSchema,
|
|
103
|
+
response: responseMappingSchema,
|
|
104
|
+
seedBinding: seedBindingSchema.optional(),
|
|
105
|
+
bootstrap: bootstrapConfigSchema.optional(),
|
|
106
|
+
preflight: preflightConfigSchema.optional()
|
|
107
|
+
})
|
|
108
|
+
.strict();
|
|
109
|
+
const transportFamilySchema = z.enum(["http-sse", "http-json", "http-connect"]);
|
|
110
|
+
function resolveProviderTransportProfile(provider) {
|
|
111
|
+
if (!provider) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const family = transportFamilySchema.safeParse(provider.kind);
|
|
115
|
+
if (!family.success) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const transportConfig = transportConfigSchema.safeParse(provider.config.transport ?? {});
|
|
119
|
+
if (!transportConfig.success) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
family: family.data,
|
|
124
|
+
models: readConfiguredModelIds(provider.config),
|
|
125
|
+
...transportConfig.data
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function readConfiguredModelIds(config) {
|
|
129
|
+
const configuredModels = config.models;
|
|
130
|
+
if (!Array.isArray(configuredModels)) {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
return [
|
|
134
|
+
...new Set(configuredModels
|
|
135
|
+
.filter((value) => typeof value === "string")
|
|
136
|
+
.map((value) => value.trim()))
|
|
137
|
+
]
|
|
138
|
+
.filter(Boolean)
|
|
139
|
+
.sort((left, right) => left.localeCompare(right));
|
|
140
|
+
}
|
|
141
|
+
function defaultModelForProviderRecord(provider) {
|
|
142
|
+
const models = provider ? readConfiguredModelIds(provider.config) : [];
|
|
143
|
+
return models[0] ?? null;
|
|
144
|
+
}
|
|
145
|
+
function selectProviderPrompt(messages, mode) {
|
|
146
|
+
if (messages.length === 0) {
|
|
147
|
+
return "";
|
|
148
|
+
}
|
|
149
|
+
if (isBridgeToolAwarePrompt(messages)) {
|
|
150
|
+
return messages
|
|
151
|
+
.map((message) => message.content.trim())
|
|
152
|
+
.filter(Boolean)
|
|
153
|
+
.join("\n\n");
|
|
154
|
+
}
|
|
155
|
+
if (mode === "latest_user") {
|
|
156
|
+
return selectLatestUserPrompt(messages);
|
|
157
|
+
}
|
|
158
|
+
if (messages.length === 1) {
|
|
159
|
+
return messages[0].content.trim();
|
|
160
|
+
}
|
|
161
|
+
if (mode === "flatten") {
|
|
162
|
+
return flattenMessages(messages);
|
|
163
|
+
}
|
|
164
|
+
return flattenMessages(messages);
|
|
165
|
+
}
|
|
166
|
+
function selectLatestUserPrompt(messages) {
|
|
167
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
168
|
+
const message = messages[index];
|
|
169
|
+
if (message?.role === "user") {
|
|
170
|
+
return message.content.trim();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return messages[messages.length - 1].content.trim();
|
|
174
|
+
}
|
|
175
|
+
function isBridgeToolAwarePrompt(messages) {
|
|
176
|
+
const systemContent = messages
|
|
177
|
+
.filter((message) => message.role === "system")
|
|
178
|
+
.map((message) => message.content)
|
|
179
|
+
.join("\n\n");
|
|
180
|
+
const userContent = messages
|
|
181
|
+
.filter((message) => message.role === "user")
|
|
182
|
+
.map((message) => message.content)
|
|
183
|
+
.join("\n\n");
|
|
184
|
+
return (/OpenAI-compatible tool-calling adapter/i.test(systemContent) &&
|
|
185
|
+
/(Conversation transcript:|Current turn:|Prior turns are already present upstream\.)/i.test(userContent));
|
|
186
|
+
}
|
|
187
|
+
function flattenMessages(messages) {
|
|
188
|
+
return messages
|
|
189
|
+
.map((message) => `${message.role.toUpperCase()}:\n${message.content.trim()}`)
|
|
190
|
+
.join("\n\n")
|
|
191
|
+
.trim();
|
|
192
|
+
}
|
|
193
|
+
export const providerTransportProfileModule = {
|
|
194
|
+
resolveProviderTransportProfile,
|
|
195
|
+
readConfiguredModelIds,
|
|
196
|
+
defaultModelForProviderRecord,
|
|
197
|
+
selectProviderPrompt
|
|
198
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ProviderTransport, ProviderTransportRequest, ProviderTransportResponse } from "@uncensoredcode/openbridge/runtime";
|
|
2
|
+
import type { FileBridgeStateStore } from "../state/file-bridge-state-store.ts";
|
|
3
|
+
import type { ProviderRecord } from "../stores/provider-store.ts";
|
|
4
|
+
import type { CollectedProviderTransportCompletion } from "./generic-provider-transport.ts";
|
|
5
|
+
import type { BridgeProviderSessionResolver } from "./provider-session-resolver.ts";
|
|
6
|
+
import type { ProviderStreamFragment } from "./provider-streams.ts";
|
|
7
|
+
type StreamingProviderTransport = {
|
|
8
|
+
streamChat(request: ProviderTransportRequest): Promise<{
|
|
9
|
+
content: AsyncIterable<ProviderStreamFragment>;
|
|
10
|
+
upstreamBinding: Promise<Pick<NonNullable<ProviderTransportRequest["upstreamBinding"]>, "conversationId" | "parentId"> | null>;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
declare class WebProviderTransport implements ProviderTransport {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(input: {
|
|
16
|
+
providerSessionResolver: BridgeProviderSessionResolver;
|
|
17
|
+
loadProvider?: (providerId: string) => ProviderRecord | null;
|
|
18
|
+
});
|
|
19
|
+
completeChat(request: ProviderTransportRequest): Promise<ProviderTransportResponse>;
|
|
20
|
+
streamChat(request: ProviderTransportRequest): Promise<{
|
|
21
|
+
content: AsyncIterable<ProviderStreamFragment>;
|
|
22
|
+
upstreamBinding: Promise<Pick<NonNullable<ProviderTransportRequest["upstreamBinding"]>, "conversationId" | "parentId"> | null>;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
declare function collectProviderTransportCompletion(stateStore: FileBridgeStateStore, request: ProviderTransportRequest): Promise<CollectedProviderTransportCompletion>;
|
|
26
|
+
export declare const webProviderTransportModule: {
|
|
27
|
+
WebProviderTransport: typeof WebProviderTransport;
|
|
28
|
+
collectProviderTransportCompletion: typeof collectProviderTransportCompletion;
|
|
29
|
+
};
|
|
30
|
+
export type { StreamingProviderTransport, WebProviderTransport };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { bridgeRuntime } from "@uncensoredcode/openbridge/runtime";
|
|
2
|
+
import { genericProviderTransportModule } from "./generic-provider-transport.js";
|
|
3
|
+
import { providerTransportProfileModule } from "./provider-transport-profile.js";
|
|
4
|
+
const { ProviderFailure } = bridgeRuntime;
|
|
5
|
+
const { collectGenericProviderCompletion, openGenericProviderStream } = genericProviderTransportModule;
|
|
6
|
+
const { resolveProviderTransportProfile } = providerTransportProfileModule;
|
|
7
|
+
class WebProviderTransport {
|
|
8
|
+
#providerSessionResolver;
|
|
9
|
+
#loadProvider;
|
|
10
|
+
constructor(input) {
|
|
11
|
+
this.#providerSessionResolver = input.providerSessionResolver;
|
|
12
|
+
this.#loadProvider = input.loadProvider ?? (() => null);
|
|
13
|
+
}
|
|
14
|
+
async completeChat(request) {
|
|
15
|
+
const result = await collectProviderTransportCompletionWithResolver(this.#providerSessionResolver, request, this.#loadProvider);
|
|
16
|
+
logCollectedCompletionSummary(request.requestId, result);
|
|
17
|
+
if (!result.completion.content) {
|
|
18
|
+
throw createEmptyCompletionFailure(result.providerId, result.completion, Boolean(request.upstreamBinding));
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
content: result.completion.content,
|
|
22
|
+
upstreamBinding: result.upstreamBinding ?? request.upstreamBinding
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async streamChat(request) {
|
|
26
|
+
return await openProviderTransportStreamWithResolver(this.#providerSessionResolver, request, this.#loadProvider);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function logCollectedCompletionSummary(requestId, result) {
|
|
30
|
+
console.log(`[BridgeTransport][${requestId}] provider_completion_collected ${JSON.stringify({
|
|
31
|
+
providerId: result.providerId,
|
|
32
|
+
modelId: result.modelId,
|
|
33
|
+
responseId: result.completion.responseId || null,
|
|
34
|
+
eventCount: result.completion.eventCount,
|
|
35
|
+
fragmentCount: result.completion.fragmentCount,
|
|
36
|
+
contentLength: result.completion.content.length,
|
|
37
|
+
contentPreview: summarizeProviderContent(result.completion.content)
|
|
38
|
+
})}`);
|
|
39
|
+
}
|
|
40
|
+
async function collectProviderTransportCompletion(stateStore, request) {
|
|
41
|
+
return collectProviderTransportCompletionWithResolver({
|
|
42
|
+
rootDir: stateStore.rootDir,
|
|
43
|
+
loadProviderSession: ({ providerId }) => stateStore.loadProviderSession(providerId)
|
|
44
|
+
}, request, () => null);
|
|
45
|
+
}
|
|
46
|
+
async function collectProviderTransportCompletionWithResolver(providerSessionResolver, request, loadProvider) {
|
|
47
|
+
const provider = loadProvider(request.providerId);
|
|
48
|
+
const profile = resolveProviderTransportProfile(provider);
|
|
49
|
+
if (!profile) {
|
|
50
|
+
throw unsupportedProviderFailure(provider);
|
|
51
|
+
}
|
|
52
|
+
const session = await providerSessionResolver.loadProviderSession({
|
|
53
|
+
providerId: request.providerId
|
|
54
|
+
});
|
|
55
|
+
if (!session) {
|
|
56
|
+
throw missingSessionFailure(request.providerId, providerSessionResolver.rootDir);
|
|
57
|
+
}
|
|
58
|
+
logProviderSessionSummary(request.requestId, request.providerId, profile.family, session);
|
|
59
|
+
return collectGenericProviderCompletion({
|
|
60
|
+
stateRoot: providerSessionResolver.rootDir,
|
|
61
|
+
session,
|
|
62
|
+
request,
|
|
63
|
+
profile
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async function openProviderTransportStreamWithResolver(providerSessionResolver, request, loadProvider) {
|
|
67
|
+
const provider = loadProvider(request.providerId);
|
|
68
|
+
const profile = resolveProviderTransportProfile(provider);
|
|
69
|
+
if (!profile) {
|
|
70
|
+
throw unsupportedProviderFailure(provider);
|
|
71
|
+
}
|
|
72
|
+
const session = await providerSessionResolver.loadProviderSession({
|
|
73
|
+
providerId: request.providerId
|
|
74
|
+
});
|
|
75
|
+
if (!session) {
|
|
76
|
+
throw missingSessionFailure(request.providerId, providerSessionResolver.rootDir);
|
|
77
|
+
}
|
|
78
|
+
logProviderSessionSummary(request.requestId, request.providerId, profile.family, session);
|
|
79
|
+
return openGenericProviderStream({
|
|
80
|
+
stateRoot: providerSessionResolver.rootDir,
|
|
81
|
+
session,
|
|
82
|
+
request,
|
|
83
|
+
profile
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function logProviderSessionSummary(requestId, providerId, providerKind, session) {
|
|
87
|
+
const cookieCount = typeof session.cookie === "string" && session.cookie
|
|
88
|
+
? session.cookie.split(/;\s*/).filter(Boolean).length
|
|
89
|
+
: 0;
|
|
90
|
+
const extraHeaderNames = session.extraHeaders ? Object.keys(session.extraHeaders).sort() : [];
|
|
91
|
+
console.log(`[BridgeTransport][${requestId}] provider_session_resolved ${JSON.stringify({
|
|
92
|
+
providerId,
|
|
93
|
+
providerKind,
|
|
94
|
+
hasCookie: Boolean(session.cookie),
|
|
95
|
+
cookieCount,
|
|
96
|
+
hasBearerToken: Boolean(session.bearerToken),
|
|
97
|
+
hasUserAgent: Boolean(session.userAgent),
|
|
98
|
+
extraHeaderNames,
|
|
99
|
+
updatedAt: session.updatedAt ?? null
|
|
100
|
+
})}`);
|
|
101
|
+
}
|
|
102
|
+
function unsupportedProviderFailure(provider) {
|
|
103
|
+
const providerId = provider?.id ?? "";
|
|
104
|
+
const providerKind = provider?.kind ?? "";
|
|
105
|
+
return new ProviderFailure({
|
|
106
|
+
kind: "permanent",
|
|
107
|
+
code: "request_invalid",
|
|
108
|
+
message: `Provider "${providerId}" does not define a supported transport family${providerKind ? ` ("${providerKind}")` : ""}.`,
|
|
109
|
+
displayMessage: "Provider transport configuration is invalid for this request.",
|
|
110
|
+
retryable: false,
|
|
111
|
+
sessionResetEligible: false,
|
|
112
|
+
details: {
|
|
113
|
+
providerId: providerId || null,
|
|
114
|
+
providerKind: providerKind || null,
|
|
115
|
+
hasTransportConfig: Boolean(provider?.config.transport)
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function missingSessionFailure(providerId, rootDir) {
|
|
120
|
+
return new ProviderFailure({
|
|
121
|
+
kind: "permanent",
|
|
122
|
+
code: "authentication_failed",
|
|
123
|
+
message: `No uploaded or legacy provider session exists for provider "${providerId}" under ${rootDir}.`,
|
|
124
|
+
displayMessage: "Provider authentication/session state is missing or expired.",
|
|
125
|
+
retryable: false,
|
|
126
|
+
sessionResetEligible: false
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function createEmptyCompletionFailure(providerId, completion, hasBinding) {
|
|
130
|
+
const noExtractableContent = completion.eventCount > 0 && completion.fragmentCount === 0;
|
|
131
|
+
return new ProviderFailure({
|
|
132
|
+
kind: "transient",
|
|
133
|
+
code: noExtractableContent ? "empty_extracted_response" : "empty_response",
|
|
134
|
+
message: `${providerId} returned ${noExtractableContent ? "no extractable assistant content" : "an empty response"}.`,
|
|
135
|
+
retryable: true,
|
|
136
|
+
sessionResetEligible: hasBinding,
|
|
137
|
+
emptyOutput: true,
|
|
138
|
+
details: {
|
|
139
|
+
streamEventCount: completion.eventCount,
|
|
140
|
+
fragmentCount: completion.fragmentCount
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function summarizeProviderContent(value, maxLength = 320) {
|
|
145
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
146
|
+
return normalized.length <= maxLength ? normalized : `${normalized.slice(0, maxLength)}...`;
|
|
147
|
+
}
|
|
148
|
+
export const webProviderTransportModule = {
|
|
149
|
+
WebProviderTransport,
|
|
150
|
+
collectProviderTransportCompletion
|
|
151
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BridgeSessionTurn, SessionBindingStore, UpstreamConversationBinding } from "@uncensoredcode/openbridge/runtime";
|
|
2
|
+
type BridgeProviderSession = {
|
|
3
|
+
providerId: string;
|
|
4
|
+
cookie: string;
|
|
5
|
+
userAgent: string;
|
|
6
|
+
bearerToken: string;
|
|
7
|
+
extraHeaders?: Record<string, string>;
|
|
8
|
+
updatedAt: string;
|
|
9
|
+
};
|
|
10
|
+
declare class FileBridgeStateStore implements SessionBindingStore {
|
|
11
|
+
readonly rootDir: string;
|
|
12
|
+
constructor(rootDir: string);
|
|
13
|
+
loadProviderSession(providerId: string): Promise<BridgeProviderSession | null>;
|
|
14
|
+
loadBinding(providerId: string, sessionId: string): Promise<UpstreamConversationBinding | null>;
|
|
15
|
+
saveBinding(providerId: string, sessionId: string, binding: UpstreamConversationBinding): Promise<void>;
|
|
16
|
+
clearBinding(providerId: string, sessionId: string): Promise<void>;
|
|
17
|
+
loadSessionHistory(sessionId: string): Promise<BridgeSessionTurn[]>;
|
|
18
|
+
appendSessionTurn(sessionId: string, turn: BridgeSessionTurn): Promise<void>;
|
|
19
|
+
loadChatCompletionSession(providerId: string, modelKey: string, lookupKey: string): Promise<string | null>;
|
|
20
|
+
loadSharedChatCompletionSession(lookupKey: string): Promise<string | null>;
|
|
21
|
+
saveChatCompletionSession(providerId: string, modelKey: string, lookupKey: string, sessionId: string): Promise<void>;
|
|
22
|
+
saveSharedChatCompletionSession(lookupKey: string, sessionId: string, metadata?: {
|
|
23
|
+
providerId?: string;
|
|
24
|
+
modelKey?: string;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
private readStoredSessionHistory;
|
|
27
|
+
private getProviderSessionPath;
|
|
28
|
+
private getConversationPath;
|
|
29
|
+
private getSessionHistoryPath;
|
|
30
|
+
private getChatCompletionContinuationPath;
|
|
31
|
+
private getSharedChatCompletionContinuationPath;
|
|
32
|
+
}
|
|
33
|
+
export declare const fileBridgeStateStoreModule: {
|
|
34
|
+
FileBridgeStateStore: typeof FileBridgeStateStore;
|
|
35
|
+
};
|
|
36
|
+
export type { BridgeProviderSession, FileBridgeStateStore };
|