@superdurable/connector-sensetime 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +6 -2
- package/dex-connector.json +52 -0
- package/dist/chunk-3XCIZXL4.js +114 -0
- package/dist/connection-C_0XqNl1.d.ts +68 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +198 -0
- package/dist/mock.d.ts +35 -0
- package/dist/mock.js +72 -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
|
+
# SenseTime TypeScript connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@superdurable/connector-sensetime` implements the read-only `listModels` Step. It calls the fixed `GET /v1/llm/models` endpoint and returns the provider model count and at most fifty IDs. Inference and account data are excluded.
|
|
4
|
+
|
|
5
|
+
Use the [authorization guide](../README.md#authorization) to configure the static `sensetime` connection in Dex Web. The [runnable Flow and Worker](examples/model-list/) use that connection. Credentials stay outside Flow state and are resolved for each call.
|
|
6
|
+
|
|
7
|
+
Go-recorded conformance tests check provider outcomes and exact requests. The integration test runs a real Dex Worker and Client with a local provider that returns 503 once before success. Authorization against a real provider account remains unverified.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "sensetime",
|
|
3
|
+
"releaseTag": "connectors/sensetime/go/v0.1.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "npm",
|
|
6
|
+
"name": "@superdurable/connector-sensetime",
|
|
7
|
+
"version": "0.1.0"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "newListModelsStep",
|
|
12
|
+
"kind": "query",
|
|
13
|
+
"operationId": "listModels",
|
|
14
|
+
"inputType": "ListModelsInput",
|
|
15
|
+
"description": "List up to 50 model IDs enabled for the API Key.",
|
|
16
|
+
"fields": {
|
|
17
|
+
"stepType": "stepType",
|
|
18
|
+
"annotations": "annotations",
|
|
19
|
+
"connectionName": "connectionName",
|
|
20
|
+
"resultAttribute": "resultAttribute"
|
|
21
|
+
},
|
|
22
|
+
"branches": [
|
|
23
|
+
{
|
|
24
|
+
"id": "found",
|
|
25
|
+
"field": "found",
|
|
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": "ListModelsInput requests models visible to a SenseNova API Key.",
|
|
47
|
+
"properties": {},
|
|
48
|
+
"type": "object"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// src/generated/models.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
4
|
+
var ConfigSchema = z.object({
|
|
5
|
+
"timeoutMs": z.number().int().optional(),
|
|
6
|
+
"maxResponseBytes": z.number().int().optional()
|
|
7
|
+
});
|
|
8
|
+
var CredentialMaterialError = class extends TypeError {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "CredentialMaterialError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
|
|
15
|
+
"project credential decoding failed",
|
|
16
|
+
"shared project credential decoding failed",
|
|
17
|
+
"project credential decoding failed: this connector version does not support shared credentials"
|
|
18
|
+
]);
|
|
19
|
+
function isCredentialMaterialError(error) {
|
|
20
|
+
return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
|
|
21
|
+
}
|
|
22
|
+
function decodeCredentials(value) {
|
|
23
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
|
|
24
|
+
const fields = value;
|
|
25
|
+
const allowed = /* @__PURE__ */ new Set(["apiKey"]);
|
|
26
|
+
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
|
|
27
|
+
if (fields["apiKey"] != null && !(typeof fields["apiKey"] === "string")) throw new CredentialMaterialError("credential apiKey has an invalid type");
|
|
28
|
+
const credentials = {};
|
|
29
|
+
if (!fields["apiKey"]) throw new CredentialMaterialError("credential apiKey is required");
|
|
30
|
+
credentials.apiKey = new SecretString(fields["apiKey"] ?? "");
|
|
31
|
+
return credentials;
|
|
32
|
+
}
|
|
33
|
+
var ListModelsInputSchema = z.strictObject({});
|
|
34
|
+
var ListModelsOutputSchema = z.strictObject({
|
|
35
|
+
"total": z.number().int(),
|
|
36
|
+
"modelIDs": z.array(z.string()).nullable()
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// src/generated/definitions.ts
|
|
40
|
+
var ConnectorID = "sensetime";
|
|
41
|
+
var ProviderID = "sensetime";
|
|
42
|
+
var ListModelsBranch = {
|
|
43
|
+
Found: "found",
|
|
44
|
+
ProviderRejected: "providerRejected",
|
|
45
|
+
InvalidResponse: "invalidResponse",
|
|
46
|
+
Defect: "defect"
|
|
47
|
+
};
|
|
48
|
+
var ListModelsBranchFound = ListModelsBranch.Found;
|
|
49
|
+
var ListModelsBranchProviderRejected = ListModelsBranch.ProviderRejected;
|
|
50
|
+
var ListModelsBranchInvalidResponse = ListModelsBranch.InvalidResponse;
|
|
51
|
+
var ListModelsBranchDefect = ListModelsBranch.Defect;
|
|
52
|
+
var ListModelsDefinition = {
|
|
53
|
+
operation: { connectorId: ConnectorID, operationId: "listModels" },
|
|
54
|
+
branches: [
|
|
55
|
+
{ id: "found", description: "SenseTime returned the available model list." },
|
|
56
|
+
{ id: "providerRejected", description: "SenseTime rejected the Key or request.", optional: true },
|
|
57
|
+
{ id: "invalidResponse", description: "SenseTime returned malformed or oversized model data.", optional: true },
|
|
58
|
+
{ id: "defect", description: "The local API Key is invalid.", optional: true }
|
|
59
|
+
],
|
|
60
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
61
|
+
};
|
|
62
|
+
var ListModelsMetadata = { kind: "query", idempotency: "none", authorization: "required" };
|
|
63
|
+
|
|
64
|
+
// src/generated/connection.ts
|
|
65
|
+
import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
|
|
66
|
+
var Connection = class {
|
|
67
|
+
/** Stable provider and connection name. */
|
|
68
|
+
reference;
|
|
69
|
+
/** Bound provider operations. */
|
|
70
|
+
operations;
|
|
71
|
+
/** Validate a reference and bind operations. */
|
|
72
|
+
constructor(reference, operations) {
|
|
73
|
+
this.reference = ConnectionRefSchema.parse(reference);
|
|
74
|
+
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
75
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
76
|
+
this.operations = operations;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
function newConnection(client, reference) {
|
|
80
|
+
if (!client) throw new TypeError("connector client is required");
|
|
81
|
+
return new Connection(reference, client);
|
|
82
|
+
}
|
|
83
|
+
function newConnectionWithOperations(operations, reference) {
|
|
84
|
+
return new Connection(reference, operations);
|
|
85
|
+
}
|
|
86
|
+
function newProjectConnection(project, connectionName, createClient) {
|
|
87
|
+
if (!project) throw new TypeError("loaded project is required");
|
|
88
|
+
const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
89
|
+
const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
|
|
90
|
+
if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
|
|
91
|
+
return newConnection(createClient(project, connectionName), reference);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export {
|
|
95
|
+
ConfigSchema,
|
|
96
|
+
CredentialMaterialError,
|
|
97
|
+
isCredentialMaterialError,
|
|
98
|
+
decodeCredentials,
|
|
99
|
+
ListModelsInputSchema,
|
|
100
|
+
ListModelsOutputSchema,
|
|
101
|
+
ConnectorID,
|
|
102
|
+
ProviderID,
|
|
103
|
+
ListModelsBranch,
|
|
104
|
+
ListModelsBranchFound,
|
|
105
|
+
ListModelsBranchProviderRejected,
|
|
106
|
+
ListModelsBranchInvalidResponse,
|
|
107
|
+
ListModelsBranchDefect,
|
|
108
|
+
ListModelsDefinition,
|
|
109
|
+
ListModelsMetadata,
|
|
110
|
+
Connection,
|
|
111
|
+
newConnection,
|
|
112
|
+
newConnectionWithOperations,
|
|
113
|
+
newProjectConnection
|
|
114
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CredentialProvider, SecretString, Query, ConnectionRef } from '@superdurable/connectors-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** Connector configuration; omitted fields use manifest defaults. */
|
|
5
|
+
interface Config {
|
|
6
|
+
/** Maximum duration of one API model-list HTTP request as a positive Go duration such as 5s or 1m. Blank uses the displayed default; increase only for a slow approved network. Runtime value in milliseconds. */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
/** Maximum model-list response size in bytes as a positive integer. Blank uses the displayed default; increase only if the provider adds more model metadata. */
|
|
9
|
+
maxResponseBytes?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Runtime schema for manifest configuration. */
|
|
12
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
13
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
maxResponseBytes: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
/** Private connector credentials resolved by the host. */
|
|
17
|
+
interface Credentials {
|
|
18
|
+
/** Secret SenseNova API Key from https://console.sensecore.cn > ModelStudio Management Center > API Key Management. Create and copy a Key; blank prevents requests. */
|
|
19
|
+
apiKey: SecretString;
|
|
20
|
+
}
|
|
21
|
+
/** Stored credential material that fails the connector credential checks, so no retry can succeed. */
|
|
22
|
+
declare class CredentialMaterialError extends TypeError {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
/** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
|
|
26
|
+
declare function isCredentialMaterialError(error: unknown): boolean;
|
|
27
|
+
/** Decode private credential fields for the connector. */
|
|
28
|
+
declare function decodeCredentials(value: unknown): Credentials;
|
|
29
|
+
/** Host-owned source of private connector credentials. */
|
|
30
|
+
type CredentialSource = CredentialProvider<Credentials>;
|
|
31
|
+
/** ListModelsInput requests models visible to a SenseNova API Key. */
|
|
32
|
+
interface ListModelsInput {
|
|
33
|
+
}
|
|
34
|
+
/** ListModelsOutput contains the provider count and at most fifty model IDs. */
|
|
35
|
+
interface ListModelsOutput {
|
|
36
|
+
/** Total is the number of models returned by the provider. */
|
|
37
|
+
"total": number;
|
|
38
|
+
/** ModelIDs are the first fifty nonsecret model identifiers. */
|
|
39
|
+
"modelIDs": Array<string> | null;
|
|
40
|
+
}
|
|
41
|
+
/** Runtime validator for ListModelsInput. */
|
|
42
|
+
declare const ListModelsInputSchema: z.ZodObject<{}, z.core.$strict>;
|
|
43
|
+
/** Runtime validator for ListModelsOutput. */
|
|
44
|
+
declare const ListModelsOutputSchema: z.ZodObject<{
|
|
45
|
+
total: z.ZodNumber;
|
|
46
|
+
modelIDs: z.ZodNullable<z.ZodArray<z.ZodString>>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
|
|
49
|
+
/** Typed operations supplied by a client or mock. */
|
|
50
|
+
interface Operations {
|
|
51
|
+
/** Invoke listModels through this connection. */
|
|
52
|
+
listModels(): Query<ListModelsInput, ListModelsOutput>;
|
|
53
|
+
}
|
|
54
|
+
/** Named connector connection kept outside Flow state. */
|
|
55
|
+
declare class Connection<BoundOperations = Operations> {
|
|
56
|
+
/** Stable provider and connection name. */
|
|
57
|
+
readonly reference: ConnectionRef;
|
|
58
|
+
/** Bound provider operations. */
|
|
59
|
+
readonly operations: BoundOperations;
|
|
60
|
+
/** Validate a reference and bind operations. */
|
|
61
|
+
constructor(reference: ConnectionRef, operations: BoundOperations);
|
|
62
|
+
}
|
|
63
|
+
/** Bind a client to a named connection. */
|
|
64
|
+
declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
|
|
65
|
+
/** Bind scripted operations to a named connection. */
|
|
66
|
+
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
67
|
+
|
|
68
|
+
export { Connection as C, type ListModelsInput as L, type Operations as O, type ListModelsOutput as a, type Credentials as b, type Config as c, ConfigSchema as d, CredentialMaterialError as e, type CredentialSource as f, ListModelsInputSchema as g, ListModelsOutputSchema as h, decodeCredentials as i, isCredentialMaterialError as j, newConnectionWithOperations as k, newConnection as n };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { L as ListModelsInput, a as ListModelsOutput, C as Connection, O as Operations, b as Credentials, c as Config } from './connection-C_0XqNl1.js';
|
|
2
|
+
export { d as ConfigSchema, e as CredentialMaterialError, f as CredentialSource, g as ListModelsInputSchema, h as ListModelsOutputSchema, i as decodeCredentials, j as isCredentialMaterialError, n as newConnection, k as newConnectionWithOperations } from './connection-C_0XqNl1.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 = "sensetime";
|
|
11
|
+
/** Provider identity for named connections. */
|
|
12
|
+
declare const ProviderID = "sensetime";
|
|
13
|
+
/** Branch IDs for listModels. */
|
|
14
|
+
declare const ListModelsBranch: {
|
|
15
|
+
readonly Found: "found";
|
|
16
|
+
readonly ProviderRejected: "providerRejected";
|
|
17
|
+
readonly InvalidResponse: "invalidResponse";
|
|
18
|
+
readonly Defect: "defect";
|
|
19
|
+
};
|
|
20
|
+
/** SenseTime returned the available model list. */
|
|
21
|
+
declare const ListModelsBranchFound: "found";
|
|
22
|
+
/** SenseTime rejected the Key or request. */
|
|
23
|
+
declare const ListModelsBranchProviderRejected: "providerRejected";
|
|
24
|
+
/** SenseTime returned malformed or oversized model data. */
|
|
25
|
+
declare const ListModelsBranchInvalidResponse: "invalidResponse";
|
|
26
|
+
/** The local API Key is invalid. */
|
|
27
|
+
declare const ListModelsBranchDefect: "defect";
|
|
28
|
+
/** Manifest definition for listModels. */
|
|
29
|
+
declare const ListModelsDefinition: QueryDefinition;
|
|
30
|
+
/** Manifest metadata for listModels. */
|
|
31
|
+
declare const ListModelsMetadata: {
|
|
32
|
+
readonly kind: "query";
|
|
33
|
+
readonly idempotency: "none";
|
|
34
|
+
readonly authorization: "required";
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Configuration for the listModels connector Step. */
|
|
38
|
+
interface ListModelsStepConfig<StepInput, OperationInput = ListModelsInput, OperationOutput = ListModelsOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
39
|
+
/** Named connection supplying this operation. */
|
|
40
|
+
connection: Connection<{
|
|
41
|
+
listModels(): Query<OperationInput, OperationOutput>;
|
|
42
|
+
}>;
|
|
43
|
+
/** Name matching the bound connection. */
|
|
44
|
+
connectionName: string;
|
|
45
|
+
/** SenseTime returned the available model list. */
|
|
46
|
+
found: StepTarget<QueryResult<OperationOutput>>;
|
|
47
|
+
/** SenseTime rejected the Key or request. */
|
|
48
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
49
|
+
/** SenseTime returned malformed or oversized model data. */
|
|
50
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
51
|
+
/** The local API Key is invalid. */
|
|
52
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
53
|
+
}
|
|
54
|
+
/** Build the listModels Step from a named connection. */
|
|
55
|
+
declare function newListModelsStep<StepInput, OperationInput = ListModelsInput, OperationOutput = ListModelsOutput>(configuration: ListModelsStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
56
|
+
|
|
57
|
+
/** Open one named SenseTime connection from Dex project configuration. */
|
|
58
|
+
declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
|
|
59
|
+
|
|
60
|
+
/** Send one model-list request through a caller-owned transport. */
|
|
61
|
+
type ModelRequestSender = (request: ProviderRequest) => Promise<ProviderResponse>;
|
|
62
|
+
/** Optional transport dependency for provider tests. */
|
|
63
|
+
interface SenseTimeClientOptions {
|
|
64
|
+
/** Request sender; production uses the Connector SDK transport. */
|
|
65
|
+
send?: ModelRequestSender;
|
|
66
|
+
}
|
|
67
|
+
/** Resolve the SenseTime Key for each model-list attempt. */
|
|
68
|
+
declare class SenseTimeClient {
|
|
69
|
+
readonly timeoutMs: number;
|
|
70
|
+
readonly maxResponseBytes: number;
|
|
71
|
+
readonly credentials: CredentialProvider<Credentials>;
|
|
72
|
+
readonly send: ModelRequestSender;
|
|
73
|
+
/** Validate settings without making a provider request. */
|
|
74
|
+
constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: SenseTimeClientOptions);
|
|
75
|
+
/** Bind the model-list Query. */
|
|
76
|
+
listModels(): ListModelsOperation;
|
|
77
|
+
}
|
|
78
|
+
/** List at most fifty model IDs visible to the API Key. */
|
|
79
|
+
declare class ListModelsOperation implements Query<ListModelsInput, ListModelsOutput> {
|
|
80
|
+
private readonly client;
|
|
81
|
+
/** Bind an authenticated SenseTime client. */
|
|
82
|
+
constructor(client: SenseTimeClient);
|
|
83
|
+
/** Return the stable generated Query contract. */
|
|
84
|
+
definition(): QueryDefinition;
|
|
85
|
+
/** Send and classify one model-list request. */
|
|
86
|
+
invoke(call: Call, input: ListModelsInput): Promise<QueryAttempt<ListModelsOutput>>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { Config, Connection, ConnectorID, Credentials, ListModelsBranch, ListModelsBranchDefect, ListModelsBranchFound, ListModelsBranchInvalidResponse, ListModelsBranchProviderRejected, ListModelsDefinition, ListModelsInput, ListModelsMetadata, ListModelsOperation, ListModelsOutput, type ListModelsStepConfig, type ModelRequestSender, ProviderID, SenseTimeClient, type SenseTimeClientOptions, newListModelsStep, newProjectConnection };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigSchema,
|
|
3
|
+
Connection,
|
|
4
|
+
ConnectorID,
|
|
5
|
+
CredentialMaterialError,
|
|
6
|
+
ListModelsBranch,
|
|
7
|
+
ListModelsBranchDefect,
|
|
8
|
+
ListModelsBranchFound,
|
|
9
|
+
ListModelsBranchInvalidResponse,
|
|
10
|
+
ListModelsBranchProviderRejected,
|
|
11
|
+
ListModelsDefinition,
|
|
12
|
+
ListModelsInputSchema,
|
|
13
|
+
ListModelsMetadata,
|
|
14
|
+
ListModelsOutputSchema,
|
|
15
|
+
ProviderID,
|
|
16
|
+
decodeCredentials,
|
|
17
|
+
isCredentialMaterialError,
|
|
18
|
+
newConnection,
|
|
19
|
+
newConnectionWithOperations,
|
|
20
|
+
newProjectConnection
|
|
21
|
+
} from "./chunk-3XCIZXL4.js";
|
|
22
|
+
|
|
23
|
+
// src/generated/steps.ts
|
|
24
|
+
import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
|
|
25
|
+
function newListModelsStep(configuration) {
|
|
26
|
+
const { connection, connectionName, found, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
27
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
28
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listModels(), connection: connection.reference, branches: [
|
|
29
|
+
goToBranch("found", found),
|
|
30
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
31
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
32
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
33
|
+
] });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/project.ts
|
|
37
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
38
|
+
import { z } from "zod";
|
|
39
|
+
|
|
40
|
+
// src/client.ts
|
|
41
|
+
import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
42
|
+
import { BodyTooLargeError, parseRetryAfter, sendProviderRequest } from "@superdurable/connectors-sdk/providerhttp";
|
|
43
|
+
var modelListEndpoint = "https://api.sensenova.cn/v1/llm/models";
|
|
44
|
+
var emptyOutput = { total: 0, modelIDs: [] };
|
|
45
|
+
var SenseTimeClient = class {
|
|
46
|
+
timeoutMs;
|
|
47
|
+
maxResponseBytes;
|
|
48
|
+
credentials;
|
|
49
|
+
send;
|
|
50
|
+
/** Validate settings without making a provider request. */
|
|
51
|
+
constructor(config, credentials, options = {}) {
|
|
52
|
+
if (!config || !credentials) throw new TypeError("SenseTime configuration and credential source are required");
|
|
53
|
+
this.timeoutMs = config.timeoutMs ?? 15e3;
|
|
54
|
+
this.maxResponseBytes = config.maxResponseBytes ?? 1048576;
|
|
55
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0 || this.maxResponseBytes > 16 << 20) throw new TypeError("SenseTime configuration is invalid");
|
|
56
|
+
this.credentials = credentials;
|
|
57
|
+
this.send = options.send ?? sendProviderRequest;
|
|
58
|
+
}
|
|
59
|
+
/** Bind the model-list Query. */
|
|
60
|
+
listModels() {
|
|
61
|
+
return new ListModelsOperation(this);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var ListModelsOperation = class {
|
|
65
|
+
/** Bind an authenticated SenseTime client. */
|
|
66
|
+
constructor(client) {
|
|
67
|
+
this.client = client;
|
|
68
|
+
}
|
|
69
|
+
client;
|
|
70
|
+
/** Return the stable generated Query contract. */
|
|
71
|
+
definition() {
|
|
72
|
+
return ListModelsDefinition;
|
|
73
|
+
}
|
|
74
|
+
/** Send and classify one model-list request. */
|
|
75
|
+
async invoke(call, input) {
|
|
76
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) return branch("defect", "VALIDATION", "SenseTime model request is invalid");
|
|
77
|
+
let credentials;
|
|
78
|
+
try {
|
|
79
|
+
credentials = await this.client.credentials.resolve(call, call.context.cancellationSignal);
|
|
80
|
+
} catch {
|
|
81
|
+
return branch("defect", "AUTHENTICATION", "SenseTime API Key is unavailable or invalid");
|
|
82
|
+
}
|
|
83
|
+
const apiKey = credentials.apiKey instanceof SecretString ? credentials.apiKey.reveal() : "";
|
|
84
|
+
if (!isValidAPIKey(apiKey)) return branch("defect", "AUTHENTICATION", "SenseTime API Key is unavailable or invalid");
|
|
85
|
+
let response;
|
|
86
|
+
try {
|
|
87
|
+
response = await this.client.send({
|
|
88
|
+
url: modelListEndpoint,
|
|
89
|
+
method: "GET",
|
|
90
|
+
headers: { Authorization: `Bearer ${apiKey}`, Accept: "application/json" },
|
|
91
|
+
timeoutMs: this.client.timeoutMs,
|
|
92
|
+
maxResponseBytes: this.client.maxResponseBytes,
|
|
93
|
+
addressPolicy: "publicHTTPS",
|
|
94
|
+
signal: call.context.cancellationSignal
|
|
95
|
+
});
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof BodyTooLargeError && error.status === 200) return branch("invalidResponse", "RESPONSE_TOO_LARGE", "SenseTime response exceeded the configured limit");
|
|
98
|
+
if (error instanceof BodyTooLargeError && error.status !== void 0) return classifyStatus(error.status, error.headers ?? {});
|
|
99
|
+
return retry("AVAILABILITY", "SenseTime model request failed");
|
|
100
|
+
}
|
|
101
|
+
if (response.status !== 200) return classifyStatus(response.status, response.headers);
|
|
102
|
+
let document;
|
|
103
|
+
try {
|
|
104
|
+
document = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(response.body));
|
|
105
|
+
} catch {
|
|
106
|
+
return branch("invalidResponse", "PROTOCOL", "SenseTime returned invalid model data");
|
|
107
|
+
}
|
|
108
|
+
if (!isRecord(document) || document.object !== "LIST" || !Array.isArray(document.data)) return branch("invalidResponse", "PROTOCOL", "SenseTime returned invalid model data");
|
|
109
|
+
const modelIDs = [];
|
|
110
|
+
for (const model of document.data) {
|
|
111
|
+
if (!isRecord(model) || model.object !== "MODEL" || typeof model.id !== "string" || !model.id || Buffer.byteLength(model.id, "utf8") > 256 || model.id.includes("\r") || model.id.includes("\n") || model.id.includes("\0")) return branch("invalidResponse", "PROTOCOL", "SenseTime returned invalid model ID");
|
|
112
|
+
if (modelIDs.length < 50) modelIDs.push(model.id);
|
|
113
|
+
}
|
|
114
|
+
return newQueryBranch("found", { total: document.data.length, modelIDs });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function classifyStatus(status, headers) {
|
|
118
|
+
const retryAfterHeader = headers["retry-after"];
|
|
119
|
+
const retryAfterMs = parseRetryAfter(Array.isArray(retryAfterHeader) ? retryAfterHeader[0] ?? "" : retryAfterHeader ?? "");
|
|
120
|
+
if (status === 429) return retry("RATE_LIMIT", "SenseTime rate limited the model request", retryAfterMs);
|
|
121
|
+
if (status === 408 || status >= 500) return retry("AVAILABILITY", "SenseTime API is temporarily unavailable", retryAfterMs);
|
|
122
|
+
const kind = status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : "PROVIDER_REJECTION";
|
|
123
|
+
return branch("providerRejected", kind, `SenseTime rejected model request with HTTP ${status}`);
|
|
124
|
+
}
|
|
125
|
+
function isRecord(value) {
|
|
126
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
127
|
+
}
|
|
128
|
+
function isValidAPIKey(value) {
|
|
129
|
+
return value.length > 0 && value.length <= 1024 && /^[!-~]+$/.test(value);
|
|
130
|
+
}
|
|
131
|
+
function failure(kind, message) {
|
|
132
|
+
return { provider: "sensetime", operation: "listModels", kind, message };
|
|
133
|
+
}
|
|
134
|
+
function branch(id, kind, message) {
|
|
135
|
+
return newQueryBranch(id, emptyOutput, {}, failure(kind, message));
|
|
136
|
+
}
|
|
137
|
+
function retry(kind, message, delayMs = 0) {
|
|
138
|
+
return newQueryRetry(failure(kind, message), delayMs);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/project.ts
|
|
142
|
+
function newProjectConnection2(project, connectionName) {
|
|
143
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
144
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "sensetime" && entry.connectionName === name);
|
|
145
|
+
if (!selected) throw new TypeError("SenseTime project connection is not configured");
|
|
146
|
+
const fields = z.strictObject({ timeout: z.union([z.string(), z.number().int()]).optional(), maxResponseBytes: z.number().int().optional() }).parse(selected.configuration);
|
|
147
|
+
const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
|
|
148
|
+
const config = {
|
|
149
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
150
|
+
...fields.maxResponseBytes !== void 0 ? { maxResponseBytes: fields.maxResponseBytes } : {}
|
|
151
|
+
};
|
|
152
|
+
const credentials = {
|
|
153
|
+
async resolve(_call, signal) {
|
|
154
|
+
const privateFields = await loadedProject.resolveCredential("sensetime", name, signal);
|
|
155
|
+
if (typeof privateFields.apiKey !== "string") throw new TypeError("SenseTime Key is unavailable");
|
|
156
|
+
return { apiKey: new SecretString2(privateFields.apiKey) };
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return new SenseTimeClient(config, credentials);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function parseDurationMilliseconds(value) {
|
|
163
|
+
let remaining = value;
|
|
164
|
+
let milliseconds = 0;
|
|
165
|
+
const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
|
|
166
|
+
while (remaining) {
|
|
167
|
+
const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
|
|
168
|
+
if (!part) throw new TypeError("SenseTime timeout must be a positive Go duration");
|
|
169
|
+
milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
|
|
170
|
+
remaining = remaining.slice(part[0].length);
|
|
171
|
+
}
|
|
172
|
+
if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("SenseTime timeout must resolve to positive whole milliseconds");
|
|
173
|
+
return milliseconds;
|
|
174
|
+
}
|
|
175
|
+
export {
|
|
176
|
+
ConfigSchema,
|
|
177
|
+
Connection,
|
|
178
|
+
ConnectorID,
|
|
179
|
+
CredentialMaterialError,
|
|
180
|
+
ListModelsBranch,
|
|
181
|
+
ListModelsBranchDefect,
|
|
182
|
+
ListModelsBranchFound,
|
|
183
|
+
ListModelsBranchInvalidResponse,
|
|
184
|
+
ListModelsBranchProviderRejected,
|
|
185
|
+
ListModelsDefinition,
|
|
186
|
+
ListModelsInputSchema,
|
|
187
|
+
ListModelsMetadata,
|
|
188
|
+
ListModelsOperation,
|
|
189
|
+
ListModelsOutputSchema,
|
|
190
|
+
ProviderID,
|
|
191
|
+
SenseTimeClient,
|
|
192
|
+
decodeCredentials,
|
|
193
|
+
isCredentialMaterialError,
|
|
194
|
+
newConnection,
|
|
195
|
+
newConnectionWithOperations,
|
|
196
|
+
newListModelsStep,
|
|
197
|
+
newProjectConnection2 as newProjectConnection
|
|
198
|
+
};
|
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 ListModelsInput, a as ListModelsOutput } from './connection-C_0XqNl1.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/** Go zero value for ListModelsInput in scripted cases. */
|
|
7
|
+
declare const emptyListModelsInput: ListModelsInput;
|
|
8
|
+
/** Go zero value for ListModelsOutput in scripted cases. */
|
|
9
|
+
declare const emptyListModelsOutput: ListModelsOutput;
|
|
10
|
+
/** Script the found branch. */
|
|
11
|
+
declare function listModelsFound(value: ListModelsOutput, failure?: Failure): Case<ListModelsOutput>;
|
|
12
|
+
/** Script the providerRejected branch. */
|
|
13
|
+
declare function listModelsProviderRejected(value: ListModelsOutput, failure?: Failure): Case<ListModelsOutput>;
|
|
14
|
+
/** Script the invalidResponse branch. */
|
|
15
|
+
declare function listModelsInvalidResponse(value: ListModelsOutput, failure?: Failure): Case<ListModelsOutput>;
|
|
16
|
+
/** Script the defect branch. */
|
|
17
|
+
declare function listModelsDefect(value: ListModelsOutput, failure?: Failure): Case<ListModelsOutput>;
|
|
18
|
+
/** Script a safe retry of listModels. */
|
|
19
|
+
declare function listModelsRetry(failure: Failure, retryAfterMs?: number): Case<ListModelsOutput>;
|
|
20
|
+
/** Manifest scenario oneModel for listModels. */
|
|
21
|
+
declare function listModelsOneModel(): Case<ListModelsOutput>;
|
|
22
|
+
/** Default listModels scenario. */
|
|
23
|
+
declare function listModelsDefault(): Case<ListModelsOutput>;
|
|
24
|
+
/** Manifest scenario noModels for listModels. */
|
|
25
|
+
declare function listModelsNoModels(): Case<ListModelsOutput>;
|
|
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
|
+
listModels(): MockQuery<ListModelsInput, ListModelsOutput>;
|
|
32
|
+
assertNoFailures(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { GeneratedMock, GeneratedMock as Mock, emptyListModelsInput, emptyListModelsOutput, listModelsDefault, listModelsDefect, listModelsFound, listModelsInvalidResponse, listModelsNoModels, listModelsOneModel, listModelsProviderRejected, listModelsRetry };
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ListModelsDefinition,
|
|
3
|
+
ListModelsInputSchema,
|
|
4
|
+
ListModelsOutputSchema,
|
|
5
|
+
ProviderID,
|
|
6
|
+
newConnectionWithOperations
|
|
7
|
+
} from "./chunk-3XCIZXL4.js";
|
|
8
|
+
|
|
9
|
+
// src/generated/mock.ts
|
|
10
|
+
import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
|
11
|
+
var emptyListModelsInput = ListModelsInputSchema.parse({});
|
|
12
|
+
var emptyListModelsOutput = ListModelsOutputSchema.parse({
|
|
13
|
+
"total": 0,
|
|
14
|
+
"modelIDs": []
|
|
15
|
+
});
|
|
16
|
+
function listModelsFound(value, failure) {
|
|
17
|
+
return branchCase("found", value, failure);
|
|
18
|
+
}
|
|
19
|
+
function listModelsProviderRejected(value, failure) {
|
|
20
|
+
return branchCase("providerRejected", value, failure);
|
|
21
|
+
}
|
|
22
|
+
function listModelsInvalidResponse(value, failure) {
|
|
23
|
+
return branchCase("invalidResponse", value, failure);
|
|
24
|
+
}
|
|
25
|
+
function listModelsDefect(value, failure) {
|
|
26
|
+
return branchCase("defect", value, failure);
|
|
27
|
+
}
|
|
28
|
+
function listModelsRetry(failure, retryAfterMs = 0) {
|
|
29
|
+
return retryCase(failure, retryAfterMs);
|
|
30
|
+
}
|
|
31
|
+
function listModelsOneModel() {
|
|
32
|
+
const value = ListModelsOutputSchema.parse({ "modelIDs": ["SenseNova-V6-Pro"], "total": 1 });
|
|
33
|
+
return branchCase("found", value);
|
|
34
|
+
}
|
|
35
|
+
function listModelsDefault() {
|
|
36
|
+
return listModelsOneModel();
|
|
37
|
+
}
|
|
38
|
+
function listModelsNoModels() {
|
|
39
|
+
const value = ListModelsOutputSchema.parse({ "modelIDs": [], "total": 0 });
|
|
40
|
+
return branchCase("found", value);
|
|
41
|
+
}
|
|
42
|
+
var GeneratedMock = class {
|
|
43
|
+
#listModels;
|
|
44
|
+
#connection;
|
|
45
|
+
constructor(connectionName) {
|
|
46
|
+
this.#listModels = newQuery(ListModelsDefinition).default(listModelsDefault());
|
|
47
|
+
this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
|
|
48
|
+
}
|
|
49
|
+
connection() {
|
|
50
|
+
return this.#connection;
|
|
51
|
+
}
|
|
52
|
+
listModels() {
|
|
53
|
+
return this.#listModels;
|
|
54
|
+
}
|
|
55
|
+
assertNoFailures() {
|
|
56
|
+
this.#listModels.assertNoFailures();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
export {
|
|
60
|
+
GeneratedMock,
|
|
61
|
+
GeneratedMock as Mock,
|
|
62
|
+
emptyListModelsInput,
|
|
63
|
+
emptyListModelsOutput,
|
|
64
|
+
listModelsDefault,
|
|
65
|
+
listModelsDefect,
|
|
66
|
+
listModelsFound,
|
|
67
|
+
listModelsInvalidResponse,
|
|
68
|
+
listModelsNoModels,
|
|
69
|
+
listModelsOneModel,
|
|
70
|
+
listModelsProviderRejected,
|
|
71
|
+
listModelsRetry
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-sensetime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "SenseTime model catalog connector for Dex TypeScript applications",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/superdurable/dex-connectors-library.git",
|
|
9
|
+
"directory": "connectors/sensetime/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/model-list/worker.ts",
|
|
43
|
+
"example:start": "tsx examples/model-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
|
+
}
|