@superdurable/connector-baichuan 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +6 -2
- package/dex-connector.json +52 -0
- package/dist/chunk-N32HRSVO.js +124 -0
- package/dist/connection-Cg1bLEnj.d.ts +103 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +231 -0
- package/dist/mock.d.ts +35 -0
- package/dist/mock.js +77 -0
- package/package.json +59 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Baichuan TypeScript connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@superdurable/connector-baichuan` provides the read-only `listKnowledgeBases` Dex Step. It reads the knowledge-base list through Baichuan AI's [documented API](https://platform.baichuan-ai.com/docs/knowledgeBase).
|
|
4
|
+
|
|
5
|
+
Use the [runnable Flow and Worker](examples/knowledge-base-list/) with a static `baichuan` connection. In Dex Web Connections, sign in at [Baichuan AI Platform](https://platform.baichuan-ai.com/), request access if required, then open API Key > 创建 API Key and save the secret key in the connection form. The key is resolved for each call and never enters Flow state. The endpoint, timeout, and response limit have manifest defaults.
|
|
6
|
+
|
|
7
|
+
The checked-in conformance scenarios replay Go-recorded requests and outcomes. The integration test exercises a real Dex Worker and Client with a local provider that returns 503 before succeeding. Real Baichuan authorization and knowledge-base discovery remain unverified without a user-controlled approved account.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "baichuan",
|
|
3
|
+
"releaseTag": "connectors/baichuan/go/v0.1.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "npm",
|
|
6
|
+
"name": "@superdurable/connector-baichuan",
|
|
7
|
+
"version": "0.1.1"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "newListKnowledgeBasesStep",
|
|
12
|
+
"kind": "query",
|
|
13
|
+
"operationId": "listKnowledgeBases",
|
|
14
|
+
"inputType": "ListKnowledgeBasesInput",
|
|
15
|
+
"description": "Read all knowledge bases returned for the configured Baichuan API key.",
|
|
16
|
+
"fields": {
|
|
17
|
+
"stepType": "stepType",
|
|
18
|
+
"annotations": "annotations",
|
|
19
|
+
"connectionName": "connectionName",
|
|
20
|
+
"resultAttribute": "resultAttribute"
|
|
21
|
+
},
|
|
22
|
+
"branches": [
|
|
23
|
+
{
|
|
24
|
+
"id": "listed",
|
|
25
|
+
"field": "listed",
|
|
26
|
+
"optional": false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "providerRejected",
|
|
30
|
+
"field": "providerRejected",
|
|
31
|
+
"optional": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "invalidResponse",
|
|
35
|
+
"field": "invalidResponse",
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "defect",
|
|
40
|
+
"field": "defect",
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"inputSchema": {
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"description": "ListKnowledgeBasesInput requests all knowledge bases visible to the connection's API key.",
|
|
47
|
+
"properties": {},
|
|
48
|
+
"type": "object"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// src/generated/models.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
4
|
+
var ConfigSchema = z.object({
|
|
5
|
+
"baseUrl": z.string().optional(),
|
|
6
|
+
"timeoutMs": z.number().int().optional(),
|
|
7
|
+
"maxResponseBytes": z.number().int().optional()
|
|
8
|
+
});
|
|
9
|
+
var CredentialMaterialError = class extends TypeError {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "CredentialMaterialError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
|
|
16
|
+
"project credential decoding failed",
|
|
17
|
+
"shared project credential decoding failed",
|
|
18
|
+
"project credential decoding failed: this connector version does not support shared credentials"
|
|
19
|
+
]);
|
|
20
|
+
function isCredentialMaterialError(error) {
|
|
21
|
+
return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
|
|
22
|
+
}
|
|
23
|
+
function decodeCredentials(value) {
|
|
24
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
|
|
25
|
+
const fields = value;
|
|
26
|
+
const allowed = /* @__PURE__ */ new Set(["api_key"]);
|
|
27
|
+
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
|
|
28
|
+
if (fields["api_key"] != null && !(typeof fields["api_key"] === "string")) throw new CredentialMaterialError("credential api_key has an invalid type");
|
|
29
|
+
const credentials = {};
|
|
30
|
+
if (!fields["api_key"]) throw new CredentialMaterialError("credential api_key is required");
|
|
31
|
+
credentials.apiKey = new SecretString(fields["api_key"] ?? "");
|
|
32
|
+
return credentials;
|
|
33
|
+
}
|
|
34
|
+
var ListKnowledgeBasesInputSchema = z.strictObject({});
|
|
35
|
+
var KnowledgeBaseSchema = z.strictObject({
|
|
36
|
+
"id": z.string(),
|
|
37
|
+
"name": z.string(),
|
|
38
|
+
"description": z.string(),
|
|
39
|
+
"status": z.string(),
|
|
40
|
+
"fileIds": z.array(z.string()).nullable(),
|
|
41
|
+
"createdAt": z.number().int(),
|
|
42
|
+
"updatedAt": z.number().int()
|
|
43
|
+
});
|
|
44
|
+
var ListKnowledgeBasesOutputSchema = z.strictObject({
|
|
45
|
+
"knowledgeBases": z.array(KnowledgeBaseSchema).nullable()
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/generated/definitions.ts
|
|
49
|
+
var ConnectorID = "baichuan";
|
|
50
|
+
var ProviderID = "baichuan";
|
|
51
|
+
var ListKnowledgeBasesBranch = {
|
|
52
|
+
Listed: "listed",
|
|
53
|
+
ProviderRejected: "providerRejected",
|
|
54
|
+
InvalidResponse: "invalidResponse",
|
|
55
|
+
Defect: "defect"
|
|
56
|
+
};
|
|
57
|
+
var ListKnowledgeBasesBranchListed = ListKnowledgeBasesBranch.Listed;
|
|
58
|
+
var ListKnowledgeBasesBranchProviderRejected = ListKnowledgeBasesBranch.ProviderRejected;
|
|
59
|
+
var ListKnowledgeBasesBranchInvalidResponse = ListKnowledgeBasesBranch.InvalidResponse;
|
|
60
|
+
var ListKnowledgeBasesBranchDefect = ListKnowledgeBasesBranch.Defect;
|
|
61
|
+
var ListKnowledgeBasesDefinition = {
|
|
62
|
+
operation: { connectorId: ConnectorID, operationId: "listKnowledgeBases" },
|
|
63
|
+
branches: [
|
|
64
|
+
{ id: "listed", description: "Baichuan returned zero or more knowledge bases." },
|
|
65
|
+
{ id: "providerRejected", description: "Baichuan rejected the key or account permissions.", optional: true },
|
|
66
|
+
{ id: "invalidResponse", description: "Baichuan returned malformed or oversized data.", optional: true },
|
|
67
|
+
{ id: "defect", description: "Connection configuration or credentials are invalid.", optional: true }
|
|
68
|
+
],
|
|
69
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
70
|
+
};
|
|
71
|
+
var ListKnowledgeBasesMetadata = { kind: "query", idempotency: "none", authorization: "required" };
|
|
72
|
+
|
|
73
|
+
// src/generated/connection.ts
|
|
74
|
+
import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
|
|
75
|
+
var Connection = class {
|
|
76
|
+
/** Stable provider and connection name. */
|
|
77
|
+
reference;
|
|
78
|
+
/** Bound provider operations. */
|
|
79
|
+
operations;
|
|
80
|
+
/** Validate a reference and bind operations. */
|
|
81
|
+
constructor(reference, operations) {
|
|
82
|
+
this.reference = ConnectionRefSchema.parse(reference);
|
|
83
|
+
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
84
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
85
|
+
this.operations = operations;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
function newConnection(client, reference) {
|
|
89
|
+
if (!client) throw new TypeError("connector client is required");
|
|
90
|
+
return new Connection(reference, client);
|
|
91
|
+
}
|
|
92
|
+
function newConnectionWithOperations(operations, reference) {
|
|
93
|
+
return new Connection(reference, operations);
|
|
94
|
+
}
|
|
95
|
+
function newProjectConnection(project, connectionName, createClient) {
|
|
96
|
+
if (!project) throw new TypeError("loaded project is required");
|
|
97
|
+
const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
98
|
+
const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
|
|
99
|
+
if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
|
|
100
|
+
return newConnection(createClient(project, connectionName), reference);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
ConfigSchema,
|
|
105
|
+
CredentialMaterialError,
|
|
106
|
+
isCredentialMaterialError,
|
|
107
|
+
decodeCredentials,
|
|
108
|
+
ListKnowledgeBasesInputSchema,
|
|
109
|
+
KnowledgeBaseSchema,
|
|
110
|
+
ListKnowledgeBasesOutputSchema,
|
|
111
|
+
ConnectorID,
|
|
112
|
+
ProviderID,
|
|
113
|
+
ListKnowledgeBasesBranch,
|
|
114
|
+
ListKnowledgeBasesBranchListed,
|
|
115
|
+
ListKnowledgeBasesBranchProviderRejected,
|
|
116
|
+
ListKnowledgeBasesBranchInvalidResponse,
|
|
117
|
+
ListKnowledgeBasesBranchDefect,
|
|
118
|
+
ListKnowledgeBasesDefinition,
|
|
119
|
+
ListKnowledgeBasesMetadata,
|
|
120
|
+
Connection,
|
|
121
|
+
newConnection,
|
|
122
|
+
newConnectionWithOperations,
|
|
123
|
+
newProjectConnection
|
|
124
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { SecretString, CredentialProvider, Query, ConnectionRef } from '@superdurable/connectors-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** Connector configuration; omitted fields use manifest defaults. */
|
|
5
|
+
interface Config {
|
|
6
|
+
/** HTTPS origin of the Baichuan AI API, without /v1. Leave blank for the displayed public endpoint; override only for a trusted test server or approved proxy. */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** Maximum time for one knowledge-base listing request as a positive Go duration such as 5s or 1m. Leave blank for the displayed default; raise only for a slow approved proxy. Runtime value in milliseconds. */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
/** Maximum knowledge-base list response size in bytes as a positive integer. Leave blank for the displayed default; raise only if a legitimate full list exceeds it. */
|
|
11
|
+
maxResponseBytes?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Runtime schema for manifest configuration. */
|
|
14
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
15
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
16
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
maxResponseBytes: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/** Private connector credentials resolved by the host. */
|
|
20
|
+
interface Credentials {
|
|
21
|
+
/** Secret Baichuan API key from https://platform.baichuan-ai.com/console/apikey > API Key > 创建 API Key for an existing approved account. Copy the complete key without spaces; Dex stores it only as a credential and sends it in a Bearer header. Blank prevents requests. New applicants may need to request access from the platform home page first. */
|
|
22
|
+
apiKey: SecretString;
|
|
23
|
+
}
|
|
24
|
+
/** Stored credential material that fails the connector credential checks, so no retry can succeed. */
|
|
25
|
+
declare class CredentialMaterialError extends TypeError {
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
28
|
+
/** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
|
|
29
|
+
declare function isCredentialMaterialError(error: unknown): boolean;
|
|
30
|
+
/** Decode private credential fields for the connector. */
|
|
31
|
+
declare function decodeCredentials(value: unknown): Credentials;
|
|
32
|
+
/** Host-owned source of private connector credentials. */
|
|
33
|
+
type CredentialSource = CredentialProvider<Credentials>;
|
|
34
|
+
/** ListKnowledgeBasesInput requests all knowledge bases visible to the connection's API key. */
|
|
35
|
+
interface ListKnowledgeBasesInput {
|
|
36
|
+
}
|
|
37
|
+
/** KnowledgeBase is the list metadata for one Baichuan knowledge base. */
|
|
38
|
+
interface KnowledgeBase {
|
|
39
|
+
/** ID is the stable provider ID used by knowledge-base APIs. */
|
|
40
|
+
"id": string;
|
|
41
|
+
/** Name is the provider's knowledge-base name. */
|
|
42
|
+
"name": string;
|
|
43
|
+
/** Description is the provider's knowledge-base description. */
|
|
44
|
+
"description": string;
|
|
45
|
+
/** Status is the provider's processing state such as init, parsing, online, or fail. */
|
|
46
|
+
"status": string;
|
|
47
|
+
/** FileIDs lists the provider file IDs attached to the knowledge base. */
|
|
48
|
+
"fileIds": Array<string> | null;
|
|
49
|
+
/** CreatedAt is the provider creation time in Unix seconds. */
|
|
50
|
+
"createdAt": number;
|
|
51
|
+
/** UpdatedAt is the provider update time in Unix seconds. */
|
|
52
|
+
"updatedAt": number;
|
|
53
|
+
}
|
|
54
|
+
/** ListKnowledgeBasesOutput contains all knowledge bases returned by Baichuan's unpaginated list API. */
|
|
55
|
+
interface ListKnowledgeBasesOutput {
|
|
56
|
+
/** KnowledgeBases is empty when the provider returned no knowledge bases. */
|
|
57
|
+
"knowledgeBases": Array<KnowledgeBase> | null;
|
|
58
|
+
}
|
|
59
|
+
/** Runtime validator for ListKnowledgeBasesInput. */
|
|
60
|
+
declare const ListKnowledgeBasesInputSchema: z.ZodObject<{}, z.core.$strict>;
|
|
61
|
+
/** Runtime validator for KnowledgeBase. */
|
|
62
|
+
declare const KnowledgeBaseSchema: z.ZodObject<{
|
|
63
|
+
id: z.ZodString;
|
|
64
|
+
name: z.ZodString;
|
|
65
|
+
description: z.ZodString;
|
|
66
|
+
status: z.ZodString;
|
|
67
|
+
fileIds: z.ZodNullable<z.ZodArray<z.ZodString>>;
|
|
68
|
+
createdAt: z.ZodNumber;
|
|
69
|
+
updatedAt: z.ZodNumber;
|
|
70
|
+
}, z.core.$strict>;
|
|
71
|
+
/** Runtime validator for ListKnowledgeBasesOutput. */
|
|
72
|
+
declare const ListKnowledgeBasesOutputSchema: z.ZodObject<{
|
|
73
|
+
knowledgeBases: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
74
|
+
id: z.ZodString;
|
|
75
|
+
name: z.ZodString;
|
|
76
|
+
description: z.ZodString;
|
|
77
|
+
status: z.ZodString;
|
|
78
|
+
fileIds: z.ZodNullable<z.ZodArray<z.ZodString>>;
|
|
79
|
+
createdAt: z.ZodNumber;
|
|
80
|
+
updatedAt: z.ZodNumber;
|
|
81
|
+
}, z.core.$strict>>>;
|
|
82
|
+
}, z.core.$strict>;
|
|
83
|
+
|
|
84
|
+
/** Typed operations supplied by a client or mock. */
|
|
85
|
+
interface Operations {
|
|
86
|
+
/** Invoke listKnowledgeBases through this connection. */
|
|
87
|
+
listKnowledgeBases(): Query<ListKnowledgeBasesInput, ListKnowledgeBasesOutput>;
|
|
88
|
+
}
|
|
89
|
+
/** Named connector connection kept outside Flow state. */
|
|
90
|
+
declare class Connection<BoundOperations = Operations> {
|
|
91
|
+
/** Stable provider and connection name. */
|
|
92
|
+
readonly reference: ConnectionRef;
|
|
93
|
+
/** Bound provider operations. */
|
|
94
|
+
readonly operations: BoundOperations;
|
|
95
|
+
/** Validate a reference and bind operations. */
|
|
96
|
+
constructor(reference: ConnectionRef, operations: BoundOperations);
|
|
97
|
+
}
|
|
98
|
+
/** Bind a client to a named connection. */
|
|
99
|
+
declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
|
|
100
|
+
/** Bind scripted operations to a named connection. */
|
|
101
|
+
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
102
|
+
|
|
103
|
+
export { Connection as C, type KnowledgeBase as K, type ListKnowledgeBasesInput as L, type Operations as O, type ListKnowledgeBasesOutput as a, type Credentials as b, type Config as c, ConfigSchema as d, CredentialMaterialError as e, type CredentialSource as f, KnowledgeBaseSchema as g, ListKnowledgeBasesInputSchema as h, ListKnowledgeBasesOutputSchema as i, decodeCredentials as j, isCredentialMaterialError as k, newConnectionWithOperations as l, newConnection as n };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { L as ListKnowledgeBasesInput, a as ListKnowledgeBasesOutput, C as Connection, O as Operations, b as Credentials, c as Config } from './connection-Cg1bLEnj.js';
|
|
2
|
+
export { d as ConfigSchema, e as CredentialMaterialError, f as CredentialSource, K as KnowledgeBase, g as KnowledgeBaseSchema, h as ListKnowledgeBasesInputSchema, i as ListKnowledgeBasesOutputSchema, j as decodeCredentials, k as isCredentialMaterialError, n as newConnection, l as newConnectionWithOperations } from './connection-Cg1bLEnj.js';
|
|
3
|
+
import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, CredentialProvider, Call, QueryAttempt } from '@superdurable/connectors-sdk';
|
|
4
|
+
import { StepTarget } from '@superdurable/dex';
|
|
5
|
+
import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
|
|
6
|
+
import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
|
|
7
|
+
import 'zod';
|
|
8
|
+
|
|
9
|
+
/** Stable connector identity. */
|
|
10
|
+
declare const ConnectorID = "baichuan";
|
|
11
|
+
/** Provider identity for named connections. */
|
|
12
|
+
declare const ProviderID = "baichuan";
|
|
13
|
+
/** Branch IDs for listKnowledgeBases. */
|
|
14
|
+
declare const ListKnowledgeBasesBranch: {
|
|
15
|
+
readonly Listed: "listed";
|
|
16
|
+
readonly ProviderRejected: "providerRejected";
|
|
17
|
+
readonly InvalidResponse: "invalidResponse";
|
|
18
|
+
readonly Defect: "defect";
|
|
19
|
+
};
|
|
20
|
+
/** Baichuan returned zero or more knowledge bases. */
|
|
21
|
+
declare const ListKnowledgeBasesBranchListed: "listed";
|
|
22
|
+
/** Baichuan rejected the key or account permissions. */
|
|
23
|
+
declare const ListKnowledgeBasesBranchProviderRejected: "providerRejected";
|
|
24
|
+
/** Baichuan returned malformed or oversized data. */
|
|
25
|
+
declare const ListKnowledgeBasesBranchInvalidResponse: "invalidResponse";
|
|
26
|
+
/** Connection configuration or credentials are invalid. */
|
|
27
|
+
declare const ListKnowledgeBasesBranchDefect: "defect";
|
|
28
|
+
/** Manifest definition for listKnowledgeBases. */
|
|
29
|
+
declare const ListKnowledgeBasesDefinition: QueryDefinition;
|
|
30
|
+
/** Manifest metadata for listKnowledgeBases. */
|
|
31
|
+
declare const ListKnowledgeBasesMetadata: {
|
|
32
|
+
readonly kind: "query";
|
|
33
|
+
readonly idempotency: "none";
|
|
34
|
+
readonly authorization: "required";
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Configuration for the listKnowledgeBases connector Step. */
|
|
38
|
+
interface ListKnowledgeBasesStepConfig<StepInput, OperationInput = ListKnowledgeBasesInput, OperationOutput = ListKnowledgeBasesOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
39
|
+
/** Named connection supplying this operation. */
|
|
40
|
+
connection: Connection<{
|
|
41
|
+
listKnowledgeBases(): Query<OperationInput, OperationOutput>;
|
|
42
|
+
}>;
|
|
43
|
+
/** Name matching the bound connection. */
|
|
44
|
+
connectionName: string;
|
|
45
|
+
/** Baichuan returned zero or more knowledge bases. */
|
|
46
|
+
listed: StepTarget<QueryResult<OperationOutput>>;
|
|
47
|
+
/** Baichuan rejected the key or account permissions. */
|
|
48
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
49
|
+
/** Baichuan returned malformed or oversized data. */
|
|
50
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
51
|
+
/** Connection configuration or credentials are invalid. */
|
|
52
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
53
|
+
}
|
|
54
|
+
/** Build the listKnowledgeBases Step from a named connection. */
|
|
55
|
+
declare function newListKnowledgeBasesStep<StepInput, OperationInput = ListKnowledgeBasesInput, OperationOutput = ListKnowledgeBasesOutput>(configuration: ListKnowledgeBasesStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
56
|
+
|
|
57
|
+
/** Open one named Baichuan connection from Dex project configuration. */
|
|
58
|
+
declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
|
|
59
|
+
|
|
60
|
+
/** Send one knowledge-base request through a caller-owned transport. */
|
|
61
|
+
type KnowledgeBaseRequestSender = (request: ProviderRequest) => Promise<ProviderResponse>;
|
|
62
|
+
/** Optional transport dependency for provider tests. */
|
|
63
|
+
interface BaichuanClientOptions {
|
|
64
|
+
/** Request sender; production uses the Connector SDK transport. */
|
|
65
|
+
send?: KnowledgeBaseRequestSender;
|
|
66
|
+
}
|
|
67
|
+
/** Resolve Baichuan credentials for each knowledge-base query. */
|
|
68
|
+
declare class BaichuanClient {
|
|
69
|
+
readonly baseUrl: string;
|
|
70
|
+
readonly timeoutMs: number;
|
|
71
|
+
readonly maxResponseBytes: number;
|
|
72
|
+
readonly credentials: CredentialProvider<Credentials>;
|
|
73
|
+
readonly send: KnowledgeBaseRequestSender;
|
|
74
|
+
/** Validate configuration without contacting Baichuan. */
|
|
75
|
+
constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: BaichuanClientOptions);
|
|
76
|
+
/** Bind the knowledge-base-list Query. */
|
|
77
|
+
listKnowledgeBases(): ListKnowledgeBasesOperation;
|
|
78
|
+
}
|
|
79
|
+
/** Read knowledge bases visible to one Baichuan API key. */
|
|
80
|
+
declare class ListKnowledgeBasesOperation implements Query<ListKnowledgeBasesInput, ListKnowledgeBasesOutput> {
|
|
81
|
+
private readonly client;
|
|
82
|
+
/** Bind an authenticated Baichuan client. */
|
|
83
|
+
constructor(client: BaichuanClient);
|
|
84
|
+
/** Return the stable generated Query contract. */
|
|
85
|
+
definition(): QueryDefinition;
|
|
86
|
+
/** Send and classify one knowledge-base-list request. */
|
|
87
|
+
invoke(call: Call, input: ListKnowledgeBasesInput): Promise<QueryAttempt<ListKnowledgeBasesOutput>>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { BaichuanClient, type BaichuanClientOptions, Config, Connection, ConnectorID, Credentials, type KnowledgeBaseRequestSender, ListKnowledgeBasesBranch, ListKnowledgeBasesBranchDefect, ListKnowledgeBasesBranchInvalidResponse, ListKnowledgeBasesBranchListed, ListKnowledgeBasesBranchProviderRejected, ListKnowledgeBasesDefinition, ListKnowledgeBasesInput, ListKnowledgeBasesMetadata, ListKnowledgeBasesOperation, ListKnowledgeBasesOutput, type ListKnowledgeBasesStepConfig, ProviderID, newListKnowledgeBasesStep, newProjectConnection };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigSchema,
|
|
3
|
+
Connection,
|
|
4
|
+
ConnectorID,
|
|
5
|
+
CredentialMaterialError,
|
|
6
|
+
KnowledgeBaseSchema,
|
|
7
|
+
ListKnowledgeBasesBranch,
|
|
8
|
+
ListKnowledgeBasesBranchDefect,
|
|
9
|
+
ListKnowledgeBasesBranchInvalidResponse,
|
|
10
|
+
ListKnowledgeBasesBranchListed,
|
|
11
|
+
ListKnowledgeBasesBranchProviderRejected,
|
|
12
|
+
ListKnowledgeBasesDefinition,
|
|
13
|
+
ListKnowledgeBasesInputSchema,
|
|
14
|
+
ListKnowledgeBasesMetadata,
|
|
15
|
+
ListKnowledgeBasesOutputSchema,
|
|
16
|
+
ProviderID,
|
|
17
|
+
decodeCredentials,
|
|
18
|
+
isCredentialMaterialError,
|
|
19
|
+
newConnection,
|
|
20
|
+
newConnectionWithOperations,
|
|
21
|
+
newProjectConnection
|
|
22
|
+
} from "./chunk-N32HRSVO.js";
|
|
23
|
+
|
|
24
|
+
// src/generated/steps.ts
|
|
25
|
+
import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
|
|
26
|
+
function newListKnowledgeBasesStep(configuration) {
|
|
27
|
+
const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
28
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
29
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listKnowledgeBases(), connection: connection.reference, branches: [
|
|
30
|
+
goToBranch("listed", listed),
|
|
31
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
32
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
33
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
34
|
+
] });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/project.ts
|
|
38
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
39
|
+
import { z } from "zod";
|
|
40
|
+
|
|
41
|
+
// src/client.ts
|
|
42
|
+
import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
43
|
+
import { BodyTooLargeError, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
44
|
+
var emptyOutput = { knowledgeBases: [] };
|
|
45
|
+
var BaichuanClient = class {
|
|
46
|
+
baseUrl;
|
|
47
|
+
timeoutMs;
|
|
48
|
+
maxResponseBytes;
|
|
49
|
+
credentials;
|
|
50
|
+
send;
|
|
51
|
+
/** Validate configuration without contacting Baichuan. */
|
|
52
|
+
constructor(config, credentials, options = {}) {
|
|
53
|
+
if (!config || !credentials) throw new TypeError("Baichuan configuration and credential source are required");
|
|
54
|
+
this.baseUrl = validateBaseURL(config.baseUrl || "https://api.baichuan-ai.com").replace(/\/$/, "");
|
|
55
|
+
this.timeoutMs = config.timeoutMs ?? 1e4;
|
|
56
|
+
this.maxResponseBytes = config.maxResponseBytes ?? 1048576;
|
|
57
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0) throw new TypeError("Baichuan timeout and maxResponseBytes must be positive");
|
|
58
|
+
this.credentials = credentials;
|
|
59
|
+
this.send = options.send ?? sendProviderRequest;
|
|
60
|
+
}
|
|
61
|
+
/** Bind the knowledge-base-list Query. */
|
|
62
|
+
listKnowledgeBases() {
|
|
63
|
+
return new ListKnowledgeBasesOperation(this);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var ListKnowledgeBasesOperation = class {
|
|
67
|
+
/** Bind an authenticated Baichuan client. */
|
|
68
|
+
constructor(client) {
|
|
69
|
+
this.client = client;
|
|
70
|
+
}
|
|
71
|
+
client;
|
|
72
|
+
/** Return the stable generated Query contract. */
|
|
73
|
+
definition() {
|
|
74
|
+
return ListKnowledgeBasesDefinition;
|
|
75
|
+
}
|
|
76
|
+
/** Send and classify one knowledge-base-list request. */
|
|
77
|
+
async invoke(call, input) {
|
|
78
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) return branch("defect", "VALIDATION", "knowledge-base request is invalid");
|
|
79
|
+
let credentials;
|
|
80
|
+
try {
|
|
81
|
+
credentials = await this.client.credentials.resolve(call, call.context.cancellationSignal);
|
|
82
|
+
} catch {
|
|
83
|
+
return branch("defect", "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
84
|
+
}
|
|
85
|
+
const apiKey = credentials.apiKey instanceof SecretString ? credentials.apiKey.reveal() : "";
|
|
86
|
+
if (!isValidAPIKey(apiKey)) return branch("defect", "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
87
|
+
let response;
|
|
88
|
+
try {
|
|
89
|
+
response = await this.client.send({
|
|
90
|
+
url: `${this.client.baseUrl}/v1/kbs`,
|
|
91
|
+
method: "GET",
|
|
92
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${apiKey}` },
|
|
93
|
+
timeoutMs: this.client.timeoutMs,
|
|
94
|
+
maxResponseBytes: this.client.maxResponseBytes,
|
|
95
|
+
addressPolicy: this.client.baseUrl === "https://api.baichuan-ai.com" ? "publicHTTPS" : "privateNetworkHTTP",
|
|
96
|
+
signal: call.context.cancellationSignal
|
|
97
|
+
});
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof BodyTooLargeError && error.status !== void 0) {
|
|
100
|
+
const status2 = classifyStatus(error.status, error.headers ?? {});
|
|
101
|
+
if (status2) return status2;
|
|
102
|
+
return branch("invalidResponse", "RESPONSE_TOO_LARGE", "Baichuan response exceeded the configured limit");
|
|
103
|
+
}
|
|
104
|
+
return retry("AVAILABILITY", "Baichuan request failed");
|
|
105
|
+
}
|
|
106
|
+
const status = classifyStatus(response.status, response.headers);
|
|
107
|
+
if (status) return status;
|
|
108
|
+
let wire;
|
|
109
|
+
try {
|
|
110
|
+
wire = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(response.body));
|
|
111
|
+
} catch {
|
|
112
|
+
return branch("invalidResponse", "PROTOCOL", "Baichuan returned an invalid knowledge-base list");
|
|
113
|
+
}
|
|
114
|
+
const document = isRecord(wire) ? providerFields(wire) : {};
|
|
115
|
+
if (document.object !== "list" || !Array.isArray(document.data) || document.data.length > 1e4) return branch("invalidResponse", "PROTOCOL", "Baichuan returned an invalid knowledge-base list");
|
|
116
|
+
const knowledgeBases = [];
|
|
117
|
+
const seen = /* @__PURE__ */ new Set();
|
|
118
|
+
for (const row of document.data) {
|
|
119
|
+
const item = isRecord(row) ? providerFields(row) : {};
|
|
120
|
+
if (typeof item.id !== "string" || !item.id || byteLength(item.id) > 256 || item.object !== "knowledge-base" || !isOptionalString(item.name) || byteLength(optionalString(item.name)) > 256 || !isOptionalString(item.description) || byteLength(optionalString(item.description)) > 4096 || !isOptionalString(item.status) || !isOptionalInteger(item.created_at) || !isOptionalInteger(item.updated_at) || optionalInteger(item.created_at) < 0 || optionalInteger(item.updated_at) < 0 || !(item.file_ids === void 0 || item.file_ids === null || Array.isArray(item.file_ids))) return branch("invalidResponse", "PROTOCOL", "Baichuan returned an invalid knowledge-base list");
|
|
121
|
+
if (seen.has(item.id)) return branch("invalidResponse", "PROTOCOL", "Baichuan returned an invalid knowledge-base list");
|
|
122
|
+
seen.add(item.id);
|
|
123
|
+
const fileIds = item.file_ids === void 0 || item.file_ids === null ? [] : item.file_ids;
|
|
124
|
+
if (fileIds.length > 1e4 || fileIds.some((fileId) => typeof fileId !== "string" || !fileId || byteLength(fileId) > 256)) return branch("invalidResponse", "PROTOCOL", "Baichuan returned an invalid knowledge-base list");
|
|
125
|
+
knowledgeBases.push({ id: item.id, name: optionalString(item.name), description: optionalString(item.description), status: optionalString(item.status), fileIds, createdAt: optionalInteger(item.created_at), updatedAt: optionalInteger(item.updated_at) });
|
|
126
|
+
}
|
|
127
|
+
return newQueryBranch("listed", { knowledgeBases });
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
function classifyStatus(status, headers) {
|
|
131
|
+
const value = headers["retry-after"];
|
|
132
|
+
const delayMs = parseRetryAfter(Array.isArray(value) ? value[0] ?? "" : value ?? "");
|
|
133
|
+
if (status === 429) return retry("RATE_LIMIT", "Baichuan rate limited the request", delayMs);
|
|
134
|
+
if (status === 408 || status >= 500) return retry("AVAILABILITY", "Baichuan is temporarily unavailable", delayMs);
|
|
135
|
+
if (status !== 200) return branch("providerRejected", status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : "PROVIDER_REJECTION", `Baichuan rejected the request with HTTP ${status}`);
|
|
136
|
+
return void 0;
|
|
137
|
+
}
|
|
138
|
+
function byteLength(value) {
|
|
139
|
+
return Buffer.byteLength(value, "utf8");
|
|
140
|
+
}
|
|
141
|
+
function optionalString(value) {
|
|
142
|
+
return typeof value === "string" ? value : "";
|
|
143
|
+
}
|
|
144
|
+
function optionalInteger(value) {
|
|
145
|
+
return Number.isSafeInteger(value) ? value : 0;
|
|
146
|
+
}
|
|
147
|
+
function isOptionalString(value) {
|
|
148
|
+
return value === void 0 || value === null || typeof value === "string";
|
|
149
|
+
}
|
|
150
|
+
function isOptionalInteger(value) {
|
|
151
|
+
return value === void 0 || value === null || Number.isSafeInteger(value);
|
|
152
|
+
}
|
|
153
|
+
function isRecord(value) {
|
|
154
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
155
|
+
}
|
|
156
|
+
function isValidAPIKey(value) {
|
|
157
|
+
return value.length > 0 && value.length <= 512 && /^[!-~]+$/.test(value);
|
|
158
|
+
}
|
|
159
|
+
function failure(kind, message) {
|
|
160
|
+
return { provider: "baichuan", operation: "listKnowledgeBases", kind, message };
|
|
161
|
+
}
|
|
162
|
+
function branch(id, kind, message) {
|
|
163
|
+
return newQueryBranch(id, emptyOutput, {}, failure(kind, message));
|
|
164
|
+
}
|
|
165
|
+
function retry(kind, message, delayMs = 0) {
|
|
166
|
+
return newQueryRetry(failure(kind, message), delayMs);
|
|
167
|
+
}
|
|
168
|
+
function providerFields(record) {
|
|
169
|
+
return Object.fromEntries(Object.entries(record).map(([name, value]) => [name.toLowerCase(), value]));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/project.ts
|
|
173
|
+
function newProjectConnection2(project, connectionName) {
|
|
174
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
175
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "baichuan" && entry.connectionName === name);
|
|
176
|
+
if (!selected) throw new TypeError("Baichuan project connection is not configured");
|
|
177
|
+
const fields = z.strictObject({ baseUrl: z.string().optional(), timeout: z.union([z.string(), z.number().int()]).optional(), maxResponseBytes: z.number().int().optional() }).parse(selected.configuration);
|
|
178
|
+
const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
|
|
179
|
+
const config = {
|
|
180
|
+
...fields.baseUrl !== void 0 ? { baseUrl: fields.baseUrl } : {},
|
|
181
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
182
|
+
...fields.maxResponseBytes !== void 0 ? { maxResponseBytes: fields.maxResponseBytes } : {}
|
|
183
|
+
};
|
|
184
|
+
const credentials = {
|
|
185
|
+
async resolve(_call, signal) {
|
|
186
|
+
const privateFields = await loadedProject.resolveCredential("baichuan", name, signal);
|
|
187
|
+
if (typeof privateFields.api_key !== "string") throw new TypeError("Baichuan API key is unavailable");
|
|
188
|
+
return { apiKey: new SecretString2(privateFields.api_key) };
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
return new BaichuanClient(config, credentials);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function parseDurationMilliseconds(value) {
|
|
195
|
+
let remaining = value;
|
|
196
|
+
let milliseconds = 0;
|
|
197
|
+
const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
|
|
198
|
+
while (remaining) {
|
|
199
|
+
const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
|
|
200
|
+
if (!part) throw new TypeError("Baichuan timeout must be a positive Go duration");
|
|
201
|
+
milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
|
|
202
|
+
remaining = remaining.slice(part[0].length);
|
|
203
|
+
}
|
|
204
|
+
if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("Baichuan timeout must resolve to positive whole milliseconds");
|
|
205
|
+
return milliseconds;
|
|
206
|
+
}
|
|
207
|
+
export {
|
|
208
|
+
BaichuanClient,
|
|
209
|
+
ConfigSchema,
|
|
210
|
+
Connection,
|
|
211
|
+
ConnectorID,
|
|
212
|
+
CredentialMaterialError,
|
|
213
|
+
KnowledgeBaseSchema,
|
|
214
|
+
ListKnowledgeBasesBranch,
|
|
215
|
+
ListKnowledgeBasesBranchDefect,
|
|
216
|
+
ListKnowledgeBasesBranchInvalidResponse,
|
|
217
|
+
ListKnowledgeBasesBranchListed,
|
|
218
|
+
ListKnowledgeBasesBranchProviderRejected,
|
|
219
|
+
ListKnowledgeBasesDefinition,
|
|
220
|
+
ListKnowledgeBasesInputSchema,
|
|
221
|
+
ListKnowledgeBasesMetadata,
|
|
222
|
+
ListKnowledgeBasesOperation,
|
|
223
|
+
ListKnowledgeBasesOutputSchema,
|
|
224
|
+
ProviderID,
|
|
225
|
+
decodeCredentials,
|
|
226
|
+
isCredentialMaterialError,
|
|
227
|
+
newConnection,
|
|
228
|
+
newConnectionWithOperations,
|
|
229
|
+
newListKnowledgeBasesStep,
|
|
230
|
+
newProjectConnection2 as newProjectConnection
|
|
231
|
+
};
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
|
+
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
+
import { O as Operations, C as Connection, L as ListKnowledgeBasesInput, a as ListKnowledgeBasesOutput, K as KnowledgeBase } from './connection-Cg1bLEnj.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/** Go zero value for ListKnowledgeBasesInput in scripted cases. */
|
|
7
|
+
declare const emptyListKnowledgeBasesInput: ListKnowledgeBasesInput;
|
|
8
|
+
/** Go zero value for KnowledgeBase in scripted cases. */
|
|
9
|
+
declare const emptyKnowledgeBase: KnowledgeBase;
|
|
10
|
+
/** Go zero value for ListKnowledgeBasesOutput in scripted cases. */
|
|
11
|
+
declare const emptyListKnowledgeBasesOutput: ListKnowledgeBasesOutput;
|
|
12
|
+
/** Script the listed branch. */
|
|
13
|
+
declare function listKnowledgeBasesListed(value: ListKnowledgeBasesOutput, failure?: Failure): Case<ListKnowledgeBasesOutput>;
|
|
14
|
+
/** Script the providerRejected branch. */
|
|
15
|
+
declare function listKnowledgeBasesProviderRejected(value: ListKnowledgeBasesOutput, failure?: Failure): Case<ListKnowledgeBasesOutput>;
|
|
16
|
+
/** Script the invalidResponse branch. */
|
|
17
|
+
declare function listKnowledgeBasesInvalidResponse(value: ListKnowledgeBasesOutput, failure?: Failure): Case<ListKnowledgeBasesOutput>;
|
|
18
|
+
/** Script the defect branch. */
|
|
19
|
+
declare function listKnowledgeBasesDefect(value: ListKnowledgeBasesOutput, failure?: Failure): Case<ListKnowledgeBasesOutput>;
|
|
20
|
+
/** Script a safe retry of listKnowledgeBases. */
|
|
21
|
+
declare function listKnowledgeBasesRetry(failure: Failure, retryAfterMs?: number): Case<ListKnowledgeBasesOutput>;
|
|
22
|
+
/** Manifest scenario sampleKnowledgeBase for listKnowledgeBases. */
|
|
23
|
+
declare function listKnowledgeBasesSampleKnowledgeBase(): Case<ListKnowledgeBasesOutput>;
|
|
24
|
+
/** Default listKnowledgeBases scenario. */
|
|
25
|
+
declare function listKnowledgeBasesDefault(): Case<ListKnowledgeBasesOutput>;
|
|
26
|
+
/** Scripted operations and manifest defaults for this connector. */
|
|
27
|
+
declare class GeneratedMock implements Operations {
|
|
28
|
+
#private;
|
|
29
|
+
constructor(connectionName: string);
|
|
30
|
+
connection(): Connection;
|
|
31
|
+
listKnowledgeBases(): MockQuery<ListKnowledgeBasesInput, ListKnowledgeBasesOutput>;
|
|
32
|
+
assertNoFailures(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { GeneratedMock, GeneratedMock as Mock, emptyKnowledgeBase, emptyListKnowledgeBasesInput, emptyListKnowledgeBasesOutput, listKnowledgeBasesDefault, listKnowledgeBasesDefect, listKnowledgeBasesInvalidResponse, listKnowledgeBasesListed, listKnowledgeBasesProviderRejected, listKnowledgeBasesRetry, listKnowledgeBasesSampleKnowledgeBase };
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KnowledgeBaseSchema,
|
|
3
|
+
ListKnowledgeBasesDefinition,
|
|
4
|
+
ListKnowledgeBasesInputSchema,
|
|
5
|
+
ListKnowledgeBasesOutputSchema,
|
|
6
|
+
ProviderID,
|
|
7
|
+
newConnectionWithOperations
|
|
8
|
+
} from "./chunk-N32HRSVO.js";
|
|
9
|
+
|
|
10
|
+
// src/generated/mock.ts
|
|
11
|
+
import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
|
12
|
+
var emptyListKnowledgeBasesInput = ListKnowledgeBasesInputSchema.parse({});
|
|
13
|
+
var emptyKnowledgeBase = KnowledgeBaseSchema.parse({
|
|
14
|
+
"id": "",
|
|
15
|
+
"name": "",
|
|
16
|
+
"description": "",
|
|
17
|
+
"status": "",
|
|
18
|
+
"fileIds": [],
|
|
19
|
+
"createdAt": 0,
|
|
20
|
+
"updatedAt": 0
|
|
21
|
+
});
|
|
22
|
+
var emptyListKnowledgeBasesOutput = ListKnowledgeBasesOutputSchema.parse({
|
|
23
|
+
"knowledgeBases": []
|
|
24
|
+
});
|
|
25
|
+
function listKnowledgeBasesListed(value, failure) {
|
|
26
|
+
return branchCase("listed", value, failure);
|
|
27
|
+
}
|
|
28
|
+
function listKnowledgeBasesProviderRejected(value, failure) {
|
|
29
|
+
return branchCase("providerRejected", value, failure);
|
|
30
|
+
}
|
|
31
|
+
function listKnowledgeBasesInvalidResponse(value, failure) {
|
|
32
|
+
return branchCase("invalidResponse", value, failure);
|
|
33
|
+
}
|
|
34
|
+
function listKnowledgeBasesDefect(value, failure) {
|
|
35
|
+
return branchCase("defect", value, failure);
|
|
36
|
+
}
|
|
37
|
+
function listKnowledgeBasesRetry(failure, retryAfterMs = 0) {
|
|
38
|
+
return retryCase(failure, retryAfterMs);
|
|
39
|
+
}
|
|
40
|
+
function listKnowledgeBasesSampleKnowledgeBase() {
|
|
41
|
+
const value = ListKnowledgeBasesOutputSchema.parse({ "knowledgeBases": [{ "createdAt": 1701828706, "description": "Example knowledge base", "fileIds": ["file-123"], "id": "kb-abc123", "name": "sample", "status": "online", "updatedAt": 1701828706 }] });
|
|
42
|
+
return branchCase("listed", value);
|
|
43
|
+
}
|
|
44
|
+
function listKnowledgeBasesDefault() {
|
|
45
|
+
return listKnowledgeBasesSampleKnowledgeBase();
|
|
46
|
+
}
|
|
47
|
+
var GeneratedMock = class {
|
|
48
|
+
#listKnowledgeBases;
|
|
49
|
+
#connection;
|
|
50
|
+
constructor(connectionName) {
|
|
51
|
+
this.#listKnowledgeBases = newQuery(ListKnowledgeBasesDefinition).default(listKnowledgeBasesDefault());
|
|
52
|
+
this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
|
|
53
|
+
}
|
|
54
|
+
connection() {
|
|
55
|
+
return this.#connection;
|
|
56
|
+
}
|
|
57
|
+
listKnowledgeBases() {
|
|
58
|
+
return this.#listKnowledgeBases;
|
|
59
|
+
}
|
|
60
|
+
assertNoFailures() {
|
|
61
|
+
this.#listKnowledgeBases.assertNoFailures();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
GeneratedMock,
|
|
66
|
+
GeneratedMock as Mock,
|
|
67
|
+
emptyKnowledgeBase,
|
|
68
|
+
emptyListKnowledgeBasesInput,
|
|
69
|
+
emptyListKnowledgeBasesOutput,
|
|
70
|
+
listKnowledgeBasesDefault,
|
|
71
|
+
listKnowledgeBasesDefect,
|
|
72
|
+
listKnowledgeBasesInvalidResponse,
|
|
73
|
+
listKnowledgeBasesListed,
|
|
74
|
+
listKnowledgeBasesProviderRejected,
|
|
75
|
+
listKnowledgeBasesRetry,
|
|
76
|
+
listKnowledgeBasesSampleKnowledgeBase
|
|
77
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-baichuan",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Baichuan knowledge base list connector for Dex TypeScript applications",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/superdurable/dex-connectors-library.git",
|
|
9
|
+
"directory": "connectors/baichuan/typescript"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": "^22.0.0 || ^24.0.0"
|
|
14
|
+
},
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./mock": {
|
|
23
|
+
"types": "./dist/mock.d.ts",
|
|
24
|
+
"import": "./dist/mock.js"
|
|
25
|
+
},
|
|
26
|
+
"./dex-connector.json": "./dex-connector.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"dex-connector.json"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"prepack": "npm run build",
|
|
36
|
+
"build": "tsup src/index.ts src/mock.ts --format esm --dts --clean",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"lint": "eslint src test examples",
|
|
39
|
+
"test": "vitest run --exclude test/integration/**",
|
|
40
|
+
"test:integration": "vitest run test/integration/*.integration.test.ts",
|
|
41
|
+
"check": "npm run typecheck && npm run lint && npm test && npm run build",
|
|
42
|
+
"example:worker": "tsx examples/knowledge-base-list/worker.ts",
|
|
43
|
+
"example:start": "tsx examples/knowledge-base-list/start.ts"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@superdurable/connectors-sdk": "0.11.0",
|
|
47
|
+
"@superdurable/dex": ">=1.28.0",
|
|
48
|
+
"zod": "^4.1.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@eslint/js": "^9.0.0",
|
|
52
|
+
"@types/node": "^22.0.0",
|
|
53
|
+
"eslint": "^9.0.0",
|
|
54
|
+
"tsup": "^8.0.0",
|
|
55
|
+
"tsx": "^4.23.15",
|
|
56
|
+
"typescript": "^5.9.0",
|
|
57
|
+
"typescript-eslint": "^8.0.0",
|
|
58
|
+
"vitest": "^3.0.0",
|
|
59
|
+
"yaml": "^2.9.1"
|
|
60
|
+
}
|
|
61
|
+
}
|