@wirecat/cli-core 0.647.0 → 0.649.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/CHANGELOG.md +117 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/account-remove.d.ts +5 -0
- package/dist/cli/account-remove.js +6 -1
- package/dist/cli/app-doctor-command.js +15 -57
- package/dist/cli/app-store.d.ts +12 -0
- package/dist/cli/app-store.js +25 -0
- package/dist/cli/commands-command.js +10 -3
- package/dist/cli/doctor-reports-command.d.ts +22 -0
- package/dist/cli/doctor-reports-command.js +82 -0
- package/dist/cli/help/command-help.d.ts +1 -0
- package/dist/cli/help/command-help.js +7 -8
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/messenger/doctor-command.js +21 -64
- package/dist/cli/messenger/stats-command.js +1 -1
- package/dist/cli/messenger/store-maintenance-command.js +3 -3
- package/dist/cli/messenger/tasks-command.js +1 -3
- package/dist/cli/permission-keys.js +4 -2
- package/dist/cli/program.js +26 -10
- package/dist/cli/settings.d.ts +2 -0
- package/dist/cli/settings.js +3 -2
- package/dist/cli/store-recover.js +2 -2
- package/dist/cli/unknown-profile.d.ts +9 -0
- package/dist/cli/unknown-profile.js +23 -0
- package/dist/crm/cli/search-all.js +4 -4
- package/dist/domain/providers.d.ts +4 -1
- package/dist/domain/providers.js +9 -2
- package/dist/domain/record-types.d.ts +24 -3
- package/dist/domain/record-types.js +23 -2
- package/dist/domain/records-table.js +4 -3
- package/dist/domain/records.d.ts +1 -1
- package/dist/domain/records.js +3 -2
- package/dist/errors/failures.d.ts +2 -0
- package/dist/errors/failures.js +6 -0
- package/dist/errors/reasons.js +17 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/kit/index.d.ts +1 -0
- package/dist/kit/index.js +1 -0
- package/dist/kit/own-catalogue.d.ts +7 -0
- package/dist/kit/own-catalogue.js +21 -0
- package/dist/oauth/index.d.ts +2 -2
- package/dist/oauth/index.js +2 -1
- package/dist/oauth/provider.d.ts +4 -0
- package/dist/oauth/provider.js +16 -1
- package/dist/oauth/storage.d.ts +5 -0
- package/dist/oauth/storage.js +20 -0
- package/dist/runs/error-detail.d.ts +1 -1
- package/dist/runs/error-detail.js +5 -2
- package/dist/runs/events.d.ts +1 -1
- package/dist/runs/secrets.d.ts +5 -4
- package/dist/runs/secrets.js +8 -4
- package/dist/sends/permissions.d.ts +2 -0
- package/dist/sends/permissions.js +4 -1
- package/dist/services/document-source.js +9 -1
- package/dist/services/notes-search.d.ts +10 -5
- package/dist/services/notes-search.js +19 -7
- package/dist/services/search-all.js +19 -11
- package/dist/sftp/index.d.ts +1 -0
- package/dist/sftp/index.js +1 -0
- package/dist/sftp/session.d.ts +61 -0
- package/dist/sftp/session.js +230 -0
- package/dist/sftp/ssh2.d.ts +38 -0
- package/dist/sftp/ssh2.js +306 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +1 -0
- package/dist/store/sqlite/added-sources.d.ts +38 -0
- package/dist/store/sqlite/added-sources.js +80 -50
- package/dist/store/sqlite/crm-activities.d.ts +2 -0
- package/dist/store/sqlite/crm-activities.js +17 -0
- package/dist/store/sqlite/deals.d.ts +4 -3
- package/dist/store/sqlite/deals.js +8 -2
- package/dist/store/sqlite/open-store.js +14 -1
- package/dist/store/sqlite/record-projectors-document.d.ts +12 -0
- package/dist/store/sqlite/record-projectors-document.js +81 -0
- package/dist/store/sqlite/record-projectors.js +2 -0
- package/package.json +14 -4
- package/parity.json +2 -11
- package/schemas/records-envelope.v1.schema.json +57 -2
package/dist/errors/reasons.js
CHANGED
|
@@ -41,6 +41,7 @@ const SIGN_IN = [
|
|
|
41
41
|
["sign-in.secret-without-id", "configuration_error", "an OAuth client secret is set without its client id"],
|
|
42
42
|
validation("account-remove.no-choice", "account remove needs --keep-data or --delete-data, one of them"),
|
|
43
43
|
["account-remove.unknown-profile", "not_found", "no profile by this name on this computer"],
|
|
44
|
+
["profile.unknown", "not_found", "no profile by this name on this computer; details.profiles lists the ones here"],
|
|
44
45
|
["account-remove.busy", "conflict", "a serve or a sync runs for this profile; stop it first"],
|
|
45
46
|
["account-remove.unconfirmed", "confirmation_required", "removing an account asks first; add --yes"],
|
|
46
47
|
["account-remove.path-outside", "configuration_error", "the tool named a path outside its own folders"],
|
|
@@ -60,7 +61,21 @@ const PROVIDER_API = [
|
|
|
60
61
|
validation("file.not-a-file", "the path names a folder or another thing that is not a file"),
|
|
61
62
|
["file.denied", "permission_error", "the file cannot be opened: permission denied"],
|
|
62
63
|
];
|
|
64
|
+
/** The read-only SFTP client (`./sftp`). */
|
|
65
|
+
const SFTP = [
|
|
66
|
+
["sftp.host-key-missing", "configuration_error", "no host key is pinned for the SFTP server"],
|
|
67
|
+
["sftp.host-key-mismatch", "authentication_error", "the SFTP server's host key is not the pinned one"],
|
|
68
|
+
["sftp.auth-missing", "configuration_error", "an SFTP connection needs a password or a private key"],
|
|
69
|
+
["sftp.key-invalid", "configuration_error", "the SFTP private key or its passphrase cannot be read"],
|
|
70
|
+
["sftp.library-missing", "configuration_error", "SFTP needs the ssh2 package in the CLI's dependencies"],
|
|
71
|
+
["sftp.timeout", "timeout", "the SFTP server did not answer in time"],
|
|
72
|
+
validation("sftp.too-large", "the file is larger than the read's byte limit"),
|
|
73
|
+
validation("sftp.closed", "the SFTP connection was closed before the operation"),
|
|
74
|
+
];
|
|
63
75
|
const OTHERS = [
|
|
76
|
+
validation("doctor.report-exists", "the report's file exists; a problem report never overwrites a file"),
|
|
77
|
+
validation("usage.unknown-command", "no command by this name; the CLI's help lists them"),
|
|
78
|
+
validation("usage.unknown-option", "the command takes no option by this name; its help lists them"),
|
|
64
79
|
["query.time-limit", "timeout", "the search took longer than its time limit; the query itself is valid"],
|
|
65
80
|
["enrichment.owner-only", "permission_error", "only the owner turns enrichment on, not an agent"],
|
|
66
81
|
["search-harder.owner-only", "permission_error", "only the owner allows search all --harder, not an agent"],
|
|
@@ -251,6 +266,7 @@ const OTHERS = [
|
|
|
251
266
|
"another program deleted or replaced the store's journal file while it was open; store recover says what to do",
|
|
252
267
|
],
|
|
253
268
|
validation("store.file-damaged", "the named store file is damaged or not a database"),
|
|
269
|
+
["store.unopenable", "configuration_error", "the store file cannot be opened at its path; details.path names it"],
|
|
254
270
|
[
|
|
255
271
|
"store.unreadable",
|
|
256
272
|
"configuration_error",
|
|
@@ -572,7 +588,7 @@ export const INPUT_FIELD_REASONS = defineReasons([
|
|
|
572
588
|
export const REASONS = defineReasons([
|
|
573
589
|
...QUERY_REASONS,
|
|
574
590
|
...INPUT_FIELD_REASONS,
|
|
575
|
-
...[...QUERY, ...SIGN_IN, ...PROVIDER_API, ...OTHERS].map(([reason, code, message]) => ({
|
|
591
|
+
...[...QUERY, ...SIGN_IN, ...PROVIDER_API, ...SFTP, ...OTHERS].map(([reason, code, message]) => ({
|
|
576
592
|
reason,
|
|
577
593
|
code,
|
|
578
594
|
message,
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type { MessageLink, MessagePermalink } from "./domain/message-link.js";
|
|
|
16
16
|
export type * from "./domain/models.js";
|
|
17
17
|
export { CURRENCY_SCALES, currencyOf, formatDecimal, type Money, minorUnits, moneyLabel, moneyOf, signedMinorUnits, } from "./domain/money.js";
|
|
18
18
|
export { ORDER_PURPOSES, ORDER_STATUSES, type OrderPurpose, type OrderStatus, } from "./domain/orders.js";
|
|
19
|
+
export { e164Of, PHONE_COUNTRIES, type PhoneCountry } from "./domain/phones.js";
|
|
19
20
|
export { countedPoll } from "./domain/polls.js";
|
|
20
21
|
export { ADDED_ACCOUNT, ADDED_PROVIDER, CRM_OPENS, FOLDER_PROVIDERS, holdsKind, isFolderProvider, isKind, KINDS, type Kind, kindIn, kindOf, kindsIn, PROVIDERS, type ProviderEntry, providerNamed, providers, UNKNOWN_PROVIDER, useProviders, } from "./domain/providers.js";
|
|
21
22
|
export type { RankingGraphEvidence, RankingGraphLink } from "./domain/rankings-graph.js";
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { parseMarkdown } from "./domain/markdown.js";
|
|
|
13
13
|
export { parseMarkdownSpans } from "./domain/markdown-spans.js";
|
|
14
14
|
export { CURRENCY_SCALES, currencyOf, formatDecimal, minorUnits, moneyLabel, moneyOf, signedMinorUnits, } from "./domain/money.js";
|
|
15
15
|
export { ORDER_PURPOSES, ORDER_STATUSES, } from "./domain/orders.js";
|
|
16
|
+
export { e164Of, PHONE_COUNTRIES } from "./domain/phones.js";
|
|
16
17
|
export { countedPoll } from "./domain/polls.js";
|
|
17
18
|
export { ADDED_ACCOUNT, ADDED_PROVIDER, CRM_OPENS, FOLDER_PROVIDERS, holdsKind, isFolderProvider, isKind, KINDS, kindIn, kindOf, kindsIn, PROVIDERS, providerNamed, providers, UNKNOWN_PROVIDER, useProviders, } from "./domain/providers.js";
|
|
18
19
|
export { rankingOptions } from "./domain/rankings-options.js";
|
package/dist/kit/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { ARGV_LOG, argvLogSetup } from "./argv-log.js";
|
|
|
2
2
|
export { type ContractCase, type ContractOptions, contractCases, OPTIONAL_METHODS } from "./contract.js";
|
|
3
3
|
export { type FakeAdapter, fakeAdapter } from "./fake.js";
|
|
4
4
|
export { type McpStdio, type McpStdioStreams, type McpToolResult, mcpOverStdio } from "./mcp-stdio.js";
|
|
5
|
+
export { ownCatalogue } from "./own-catalogue.js";
|
|
5
6
|
export { neverAnswers, type RunScopeCase, type RunScopeOptions, runScopeCases } from "./run-scope.js";
|
|
6
7
|
export { type SearchRecipes, searchRecipes, seedSearchRecipes } from "./search-recipes.js";
|
|
7
8
|
export { BUSY_PAGE, contractSeed, digitIds, type IdKind, type IdMaker, type Seed, wordIds } from "./seed.js";
|
package/dist/kit/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { ARGV_LOG, argvLogSetup } from "./argv-log.js";
|
|
|
2
2
|
export { contractCases, OPTIONAL_METHODS } from "./contract.js";
|
|
3
3
|
export { fakeAdapter } from "./fake.js";
|
|
4
4
|
export { mcpOverStdio } from "./mcp-stdio.js";
|
|
5
|
+
export { ownCatalogue } from "./own-catalogue.js";
|
|
5
6
|
export { neverAnswers, runScopeCases } from "./run-scope.js";
|
|
6
7
|
export { searchRecipes, seedSearchRecipes } from "./search-recipes.js";
|
|
7
8
|
export { BUSY_PAGE, contractSeed, digitIds, wordIds } from "./seed.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { type CatalogueOptions } from "../mcp/agent.js";
|
|
3
|
+
/**
|
|
4
|
+
* The MCP catalogue of a CLI's own commands, by path, as `read` or `write`: what cli-core mounted is left out, since
|
|
5
|
+
* cli-core pins it. A CLI's contract test pins this and the few shared commands it changes on purpose.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ownCatalogue: (program: Command, options?: CatalogueOptions) => Record<string, "read" | "write">;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describeProgram, hasSharedContract } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { toolsFromCommands } from "../mcp/agent.js";
|
|
3
|
+
const sharedPaths = (command, parents = [], into = new Set()) => {
|
|
4
|
+
for (const child of command.commands) {
|
|
5
|
+
const path = [...parents, child.name()];
|
|
6
|
+
if (hasSharedContract(child))
|
|
7
|
+
into.add(path.join(" "));
|
|
8
|
+
sharedPaths(child, path, into);
|
|
9
|
+
}
|
|
10
|
+
return into;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The MCP catalogue of a CLI's own commands, by path, as `read` or `write`: what cli-core mounted is left out, since
|
|
14
|
+
* cli-core pins it. A CLI's contract test pins this and the few shared commands it changes on purpose.
|
|
15
|
+
*/
|
|
16
|
+
export const ownCatalogue = (program, options = {}) => {
|
|
17
|
+
const shared = sharedPaths(program);
|
|
18
|
+
return Object.fromEntries(toolsFromCommands(describeProgram(program), options)
|
|
19
|
+
.filter((tool) => !shared.has([...(options.root ?? []), tool.command].join(" ")))
|
|
20
|
+
.map((tool) => [tool.command, tool.writes ? "write" : "read"]));
|
|
21
|
+
};
|
package/dist/oauth/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { type Authorization, type AuthorizeOptions, authorize } from "./authorize.js";
|
|
2
2
|
export { type ClientFileOptions, readClientFile } from "./client-file.js";
|
|
3
3
|
export { type SignInOptions, type TokenKeeper, type TokenKeeperOptions, type TokensOptions, tokenKeeper, } from "./keeper.js";
|
|
4
|
-
export type
|
|
4
|
+
export { type AppSource, type ExchangeContext, googleProvider, type OAuthClient, type OAuthProvider, type RequestContext, type TokenSet, } from "./provider.js";
|
|
5
5
|
export { requestTokens, revokeToken, TOKEN_LOG_ALLOW, TOKEN_LOG_EVENT } from "./requests.js";
|
|
6
|
-
export { type CredentialStorageOptions, credentialStorage, driveSessionCodec, type EncodeInput, oauthAccount, type StoredTokens, standardCodec, type TokenCodec, type TokenStorage, zoomTokenCodec, } from "./storage.js";
|
|
6
|
+
export { type CredentialStorageOptions, credentialStorage, driveSessionCodec, type EncodeInput, googleTokenCodec, oauthAccount, type StoredTokens, standardCodec, type TokenCodec, type TokenStorage, zoomTokenCodec, } from "./storage.js";
|
package/dist/oauth/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { authorize } from "./authorize.js";
|
|
2
2
|
export { readClientFile } from "./client-file.js";
|
|
3
3
|
export { tokenKeeper, } from "./keeper.js";
|
|
4
|
+
export { googleProvider, } from "./provider.js";
|
|
4
5
|
export { requestTokens, revokeToken, TOKEN_LOG_ALLOW, TOKEN_LOG_EVENT } from "./requests.js";
|
|
5
|
-
export { credentialStorage, driveSessionCodec, oauthAccount, standardCodec, zoomTokenCodec, } from "./storage.js";
|
|
6
|
+
export { credentialStorage, driveSessionCodec, googleTokenCodec, oauthAccount, standardCodec, zoomTokenCodec, } from "./storage.js";
|
package/dist/oauth/provider.d.ts
CHANGED
|
@@ -59,3 +59,7 @@ export interface OAuthProvider {
|
|
|
59
59
|
exchange?: (params: Record<string, string>, context: ExchangeContext) => Promise<TokenSet>;
|
|
60
60
|
revoke?: (tokens: TokenSet, context: RequestContext) => Promise<void>;
|
|
61
61
|
}
|
|
62
|
+
/** Google's endpoints for a Desktop client; `loginHint` preselects the account the browser offers. */
|
|
63
|
+
export declare const googleProvider: (client: OAuthClient, { loginHint }?: {
|
|
64
|
+
loginHint?: string;
|
|
65
|
+
}) => OAuthProvider;
|
package/dist/oauth/provider.js
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/** Google's endpoints for a Desktop client; `loginHint` preselects the account the browser offers. */
|
|
2
|
+
export const googleProvider = (client, { loginHint } = {}) => ({
|
|
3
|
+
id: "google",
|
|
4
|
+
name: "Google",
|
|
5
|
+
authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
6
|
+
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
7
|
+
revokeUrl: "https://oauth2.googleapis.com/revoke",
|
|
8
|
+
client,
|
|
9
|
+
redirect: { kind: "loopback" },
|
|
10
|
+
// Without offline access Google returns no refresh token; without consent it does not return one again.
|
|
11
|
+
authorizeParams: {
|
|
12
|
+
access_type: "offline",
|
|
13
|
+
prompt: "select_account consent",
|
|
14
|
+
...(loginHint ? { login_hint: loginHint } : {}),
|
|
15
|
+
},
|
|
16
|
+
});
|
package/dist/oauth/storage.d.ts
CHANGED
|
@@ -41,6 +41,11 @@ export declare const standardCodec: (providerId: string) => TokenCodec;
|
|
|
41
41
|
* refresh_token, expiry_date, scope, token_type, …}}`. A write keeps every field it does not own.
|
|
42
42
|
*/
|
|
43
43
|
export declare const driveSessionCodec: TokenCodec;
|
|
44
|
+
/**
|
|
45
|
+
* Google's entry: the standard one plus the client secret, which a Google Desktop client needs to refresh while its
|
|
46
|
+
* client file is read only at sign-in. A client without a secret drops the one the profile signed in with before.
|
|
47
|
+
*/
|
|
48
|
+
export declare const googleTokenCodec: TokenCodec;
|
|
44
49
|
/** zm's entry as zoom-cli writes it today: `{accessToken, refreshToken, expiresAt, scopes}`, all four required. */
|
|
45
50
|
export declare const zoomTokenCodec: TokenCodec;
|
|
46
51
|
export interface CredentialStorageOptions {
|
package/dist/oauth/storage.js
CHANGED
|
@@ -122,6 +122,26 @@ export const driveSessionCodec = {
|
|
|
122
122
|
return JSON.stringify(session);
|
|
123
123
|
},
|
|
124
124
|
};
|
|
125
|
+
const googleStandard = standardCodec("google");
|
|
126
|
+
/**
|
|
127
|
+
* Google's entry: the standard one plus the client secret, which a Google Desktop client needs to refresh while its
|
|
128
|
+
* client file is read only at sign-in. A client without a secret drops the one the profile signed in with before.
|
|
129
|
+
*/
|
|
130
|
+
export const googleTokenCodec = {
|
|
131
|
+
decode: (raw) => {
|
|
132
|
+
const stored = googleStandard.decode(raw);
|
|
133
|
+
const clientSecret = text(parse(raw).clientSecret);
|
|
134
|
+
return clientSecret ? { ...stored, client: { clientId: stored.client?.clientId ?? "", clientSecret } } : stored;
|
|
135
|
+
},
|
|
136
|
+
encode: (input) => {
|
|
137
|
+
const entry = parse(googleStandard.encode(input));
|
|
138
|
+
if (input.client.clientSecret)
|
|
139
|
+
entry.clientSecret = input.client.clientSecret;
|
|
140
|
+
else
|
|
141
|
+
delete entry.clientSecret;
|
|
142
|
+
return JSON.stringify(entry);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
125
145
|
/** zm's entry as zoom-cli writes it today: `{accessToken, refreshToken, expiresAt, scopes}`, all four required. */
|
|
126
146
|
export const zoomTokenCodec = {
|
|
127
147
|
decode: (raw) => {
|
|
@@ -33,7 +33,7 @@ export declare const errorDetailOf: (error: unknown, response?: RequestEvent) =>
|
|
|
33
33
|
export declare const framesOf: (error: unknown, limit?: number) => string[];
|
|
34
34
|
/**
|
|
35
35
|
* Where a request went, with nothing in it that names a person or opens an account: no query string, no user, an id
|
|
36
|
-
* or a token in the path as `:id` / `:token
|
|
36
|
+
* or a token in the path as `:id` / `:token`, a webhook's secret after `/rest/<user id>/` among them. The host stays — which service refused is the point.
|
|
37
37
|
*/
|
|
38
38
|
export declare const endpointTemplate: (raw: string) => string;
|
|
39
39
|
/** A phone number as people type it with its country code, and one written as digits only without the "+". */
|
|
@@ -94,16 +94,19 @@ const fileOf = (path) => {
|
|
|
94
94
|
};
|
|
95
95
|
/**
|
|
96
96
|
* Where a request went, with nothing in it that names a person or opens an account: no query string, no user, an id
|
|
97
|
-
* or a token in the path as `:id` / `:token
|
|
97
|
+
* or a token in the path as `:id` / `:token`, a webhook's secret after `/rest/<user id>/` among them. The host stays — which service refused is the point.
|
|
98
98
|
*/
|
|
99
99
|
export const endpointTemplate = (raw) => {
|
|
100
100
|
const trimmed = raw.trim().split(/[?#]/)[0] ?? "";
|
|
101
101
|
const origin = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]*@)?([^/]*)/i.exec(trimmed);
|
|
102
102
|
const path = origin ? trimmed.slice(origin[0].length) : trimmed;
|
|
103
103
|
const scheme = origin ? `${trimmed.slice(0, trimmed.indexOf("://"))}://${origin[1]}` : "";
|
|
104
|
-
const
|
|
104
|
+
const parts = path.split("/");
|
|
105
|
+
const segments = parts.map((segment, at) => {
|
|
105
106
|
if (segment === "" || /^[:{].+/.test(segment))
|
|
106
107
|
return segment;
|
|
108
|
+
if (at >= 2 && parts[at - 2] === "rest" && /^\d+$/.test(parts[at - 1] ?? ""))
|
|
109
|
+
return ":token";
|
|
107
110
|
if (/^bot\d+:/.test(segment) || /^\d{6,}:[\w-]{20,}$/.test(segment))
|
|
108
111
|
return ":token";
|
|
109
112
|
if (/^-?\d+$/.test(segment) || /^[0-9a-f-]{16,}$/i.test(segment))
|
package/dist/runs/events.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface RequestEvent {
|
|
|
37
37
|
* requests when it has any, so one operation over three frames is three requests, never four.
|
|
38
38
|
*/
|
|
39
39
|
level?: "operation" | "wire";
|
|
40
|
-
transport?: "http" | "mtproto" | "max-ws" | "wa-engine";
|
|
40
|
+
transport?: "http" | "mtproto" | "max-ws" | "wa-engine" | "sftp";
|
|
41
41
|
/** 1 for the first try, 2 and up for a retry of the same call. */
|
|
42
42
|
attempt?: number;
|
|
43
43
|
/** How long the client waited before this attempt: a flood wait or a `Retry-After`. */
|
package/dist/runs/secrets.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ export declare const holdsCredential: (text: string) => boolean;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const looksRandom: (run: string) => boolean;
|
|
9
9
|
/**
|
|
10
|
-
* Text with each secret inside it replaced by `mark` and the words around it kept: a
|
|
11
|
-
* a private key, a `Bearer`/`Basic` credential, the value of a secret-named
|
|
12
|
-
* or `name value`, a random-looking string of 20 or more printable
|
|
13
|
-
* lower-case hex characters with a Shannon entropy of 3 bits per
|
|
10
|
+
* Text with each secret inside it replaced by `mark` and the words around it kept: a webhook secret in a URL path, a
|
|
11
|
+
* token of a known vendor format, a private key, a `Bearer`/`Basic` credential, the value of a secret-named
|
|
12
|
+
* `name=value`, `name: value`, `name => value` or `name value`, a random-looking string of 20 or more printable
|
|
13
|
+
* characters (`looksRandom`), and a run of 20 or more lower-case hex characters with a Shannon entropy of 3 bits per
|
|
14
|
+
* character or more.
|
|
14
15
|
*/
|
|
15
16
|
export declare const withoutSecrets: (text: string, mark?: string) => string;
|
package/dist/runs/secrets.js
CHANGED
|
@@ -49,6 +49,8 @@ const KNOWN_TOKENS = new RegExp(`${[
|
|
|
49
49
|
]
|
|
50
50
|
.map((pattern) => `${START}${pattern}${END}`)
|
|
51
51
|
.join("|")}|(?<!\\d)\\d{8,10}:[A-Za-z0-9_-]{35}${END}`, "g");
|
|
52
|
+
// A Bitrix24 inbound webhook carries its secret as a path segment: `/rest/<user id>/<secret>/<method>`.
|
|
53
|
+
const WEBHOOK_PATH = /(\/rest\/\d+\/)[^/\s?#"']+/g;
|
|
52
54
|
const PRIVATE_KEY = /-----BEGIN[A-Z ]* PRIVATE KEY-----[\s\S]*?(?:-----END[A-Z ]* PRIVATE KEY-----|$)/g;
|
|
53
55
|
// Capitalised, as in a header, and not followed by a plain word: "the Basic plan" is somebody's words.
|
|
54
56
|
const SCHEME = /(?<![A-Za-z])(Bearer|Basic)(\s+)(?![A-Z]?[a-z]+(?![A-Za-z0-9]))[A-Za-z0-9._~+/=-]{8,}/g;
|
|
@@ -89,12 +91,14 @@ const entropy = (text) => {
|
|
|
89
91
|
return bits;
|
|
90
92
|
};
|
|
91
93
|
/**
|
|
92
|
-
* Text with each secret inside it replaced by `mark` and the words around it kept: a
|
|
93
|
-
* a private key, a `Bearer`/`Basic` credential, the value of a secret-named
|
|
94
|
-
* or `name value`, a random-looking string of 20 or more printable
|
|
95
|
-
* lower-case hex characters with a Shannon entropy of 3 bits per
|
|
94
|
+
* Text with each secret inside it replaced by `mark` and the words around it kept: a webhook secret in a URL path, a
|
|
95
|
+
* token of a known vendor format, a private key, a `Bearer`/`Basic` credential, the value of a secret-named
|
|
96
|
+
* `name=value`, `name: value`, `name => value` or `name value`, a random-looking string of 20 or more printable
|
|
97
|
+
* characters (`looksRandom`), and a run of 20 or more lower-case hex characters with a Shannon entropy of 3 bits per
|
|
98
|
+
* character or more.
|
|
96
99
|
*/
|
|
97
100
|
export const withoutSecrets = (text, mark = "[redacted]") => text
|
|
101
|
+
.replace(WEBHOOK_PATH, `$1${mark}`)
|
|
98
102
|
.replace(PRIVATE_KEY, mark)
|
|
99
103
|
.replace(KNOWN_TOKENS, mark)
|
|
100
104
|
.replace(SCHEME, `$1$2${mark}`)
|
|
@@ -8,6 +8,8 @@ export type PermissionKey = string;
|
|
|
8
8
|
export declare const skipFlagFor: (key: string) => "--allow-dangerous" | "--yes";
|
|
9
9
|
/** Only what cannot be undone asks; the tool is meant to work without questions (owner, NEED-460). */
|
|
10
10
|
export declare const DEFAULT_PERMISSIONS: Readonly<Record<PermissionKey, Level>>;
|
|
11
|
+
/** Commands under a housekeeping word, or store maintenance, that still have a key of their own: their path. */
|
|
12
|
+
export declare const KEYED_UNDER_HOUSEKEEPING: ReadonlySet<PermissionKey>;
|
|
11
13
|
/** Lets an MCP server offer the commands that change what a later run may do (`grantsAuthority`). */
|
|
12
14
|
export declare const AUTHORITY_KEY: PermissionKey;
|
|
13
15
|
/** Whether these levels let an agent run a command that changes what a later run may do; `ask` does, as for any write. */
|
|
@@ -28,6 +28,7 @@ export const DEFAULT_PERMISSIONS = {
|
|
|
28
28
|
"store.clear": "ask",
|
|
29
29
|
"store.decrypt": "ask",
|
|
30
30
|
"store.copies.delete": "ask",
|
|
31
|
+
"store.recover.run": "ask",
|
|
31
32
|
"server.start": "ask",
|
|
32
33
|
"server.stop": "ask",
|
|
33
34
|
"server.restart": "ask",
|
|
@@ -42,7 +43,7 @@ export const DEFAULT_PERMISSIONS = {
|
|
|
42
43
|
"doctor.reports.create": "ask",
|
|
43
44
|
};
|
|
44
45
|
/** Commands under a housekeeping word, or store maintenance, that still have a key of their own: their path. */
|
|
45
|
-
const KEYED_UNDER_HOUSEKEEPING = new Set(Object.keys(DEFAULT_PERMISSIONS).filter((key) => /^(store|server|models|images|schedule|doctor)\./.test(key)));
|
|
46
|
+
export const KEYED_UNDER_HOUSEKEEPING = new Set(Object.keys(DEFAULT_PERMISSIONS).filter((key) => /^(store|server|models|images|schedule|doctor)\./.test(key)));
|
|
46
47
|
/** Lets an MCP server offer the commands that change what a later run may do (`grantsAuthority`). */
|
|
47
48
|
export const AUTHORITY_KEY = "mcp.authority";
|
|
48
49
|
/** Whether these levels let an agent run a command that changes what a later run may do; `ask` does, as for any write. */
|
|
@@ -350,6 +351,8 @@ export const readKeysForCommand = (path) => {
|
|
|
350
351
|
// Checked as `messages` before they had keys of their own: `deny messages` keeps stopping them.
|
|
351
352
|
if (path[0] === "store" && ["reset", "clear", "decrypt"].includes(path[1] ?? ""))
|
|
352
353
|
return [key, "messages"];
|
|
354
|
+
if (key === "store.recover.run")
|
|
355
|
+
return [key, "messages"];
|
|
353
356
|
// A search shows what people wrote, so `deny messages` reaches every leaf that reads messages.
|
|
354
357
|
if (path[0] === "search") {
|
|
355
358
|
if (path[1] === "notes")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFolderProvider, kindIn } from "../domain/providers.js";
|
|
1
|
+
import { isFolderProvider, isImportedProvider, kindIn } from "../domain/providers.js";
|
|
2
2
|
/**
|
|
3
3
|
* Where a hit came from. The document's preferred file says it: its account's provider and its link.
|
|
4
4
|
* A Drive document under a notes folder (before version 31 moves it) is still known by its front matter.
|
|
@@ -7,6 +7,14 @@ import { isFolderProvider, kindIn } from "../domain/providers.js";
|
|
|
7
7
|
export const documentSource = (note, accounts, profiles, file) => {
|
|
8
8
|
const metadata = note.frontMatter;
|
|
9
9
|
const account = accounts.find(({ id }) => String(id) === note.folderId);
|
|
10
|
+
// An import's document stays in its source's account, beside that source's calls and SMS.
|
|
11
|
+
if (note.source === "file" && account !== undefined && isImportedProvider(account.provider))
|
|
12
|
+
return {
|
|
13
|
+
kind: "document",
|
|
14
|
+
provider: account.provider,
|
|
15
|
+
account: account.account,
|
|
16
|
+
...(file?.url ? { url: file.url } : {}),
|
|
17
|
+
};
|
|
10
18
|
const remote = note.source === "file" &&
|
|
11
19
|
((account !== undefined && kindIn(account.provider) === "documents") || metadata?.source === "google-drive");
|
|
12
20
|
const profile = remote && account
|
|
@@ -9,7 +9,7 @@ import { type ResolvedNode } from "../search/lucene/resolved.js";
|
|
|
9
9
|
import { type Stemmer } from "../search/stem.js";
|
|
10
10
|
import { type SearchTotal } from "../search/total.js";
|
|
11
11
|
import type { Link, NearestNote, Note, NoteHit } from "../store/index.js";
|
|
12
|
-
import type { AccountKey, MessageStore } from "../store/store.js";
|
|
12
|
+
import type { AccountKey, MessageStore, StoredAccount } from "../store/store.js";
|
|
13
13
|
import { type EnrichOptions, type EnrichRun } from "./enrichment.js";
|
|
14
14
|
export interface NotesSearchRequest {
|
|
15
15
|
text: string;
|
|
@@ -203,13 +203,18 @@ export declare const RANK_WITHIN = 2000;
|
|
|
203
203
|
* of `filter` holds for every hit, found by words or by meaning; a query of fields alone is not searched by meaning.
|
|
204
204
|
*/
|
|
205
205
|
export declare const searchNotes: (store: MessageStore, query: string, { limit, offset, tag, filter: expression, folderIds, withInternal, source: given, exact, discover, timezone, env, command, embedders, pictures: withPictures, pictureLimit, pictureEmbedder, }?: NotesQuery) => Promise<NotesFound>;
|
|
206
|
-
/**
|
|
207
|
-
|
|
206
|
+
/**
|
|
207
|
+
* What `notes:internal`, `notes:<folder id>` and an import's own account (`phone:office-pbx`) ask of the store: one
|
|
208
|
+
* query, so a page of it is one page. `stored` gives an import's account its store id.
|
|
209
|
+
*/
|
|
210
|
+
export declare const notesScopeOf: (accounts: readonly AccountKey[], stored?: readonly StoredAccount[]) => Pick<NotesQuery, "folderIds" | "withInternal" | "source">;
|
|
211
|
+
/** The accounts of import-only providers: their documents stay under their own key, `phone:office-pbx`. */
|
|
212
|
+
export declare const importAccounts: (store: MessageStore) => Promise<StoredAccount[]>;
|
|
208
213
|
export interface NotesFoundOf extends NotesFound {
|
|
209
|
-
/** Every notes account read: `internal
|
|
214
|
+
/** Every notes account read: `internal`, each folder's id, and each import's account by its own key. */
|
|
210
215
|
accounts: {
|
|
211
216
|
resource: "notes";
|
|
212
|
-
provider:
|
|
217
|
+
provider: string;
|
|
213
218
|
account: string;
|
|
214
219
|
}[];
|
|
215
220
|
/** A `--source` entry naming nothing `search notes` reads. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { dateRange, parseLucene, timezoneOf } from "@wirecat/cli-base/query";
|
|
3
|
-
import { INTERNAL_NOTES } from "../domain/providers.js";
|
|
3
|
+
import { INTERNAL_NOTES, isImportedProvider } from "../domain/providers.js";
|
|
4
4
|
import { normalizeTag } from "../domain/tags.js";
|
|
5
5
|
import { defaultThreads, isTextModelInstalled, openEmbedder, textModelsDirectory, } from "../embeddings/embed.js";
|
|
6
6
|
import { chosenTextModel, meaningFloor, textModel, vectorModelKey } from "../embeddings/models.js";
|
|
@@ -551,13 +551,22 @@ export const searchNotes = async (store, query, { limit = 20, offset = 0, tag, f
|
|
|
551
551
|
...lane,
|
|
552
552
|
};
|
|
553
553
|
};
|
|
554
|
-
/**
|
|
555
|
-
|
|
556
|
-
|
|
554
|
+
/**
|
|
555
|
+
* What `notes:internal`, `notes:<folder id>` and an import's own account (`phone:office-pbx`) ask of the store: one
|
|
556
|
+
* query, so a page of it is one page. `stored` gives an import's account its store id.
|
|
557
|
+
*/
|
|
558
|
+
export const notesScopeOf = (accounts, stored = []) => {
|
|
559
|
+
const folderIds = accounts
|
|
560
|
+
.filter(({ provider, account }) => provider !== "notes" || account !== INTERNAL_NOTES)
|
|
561
|
+
.map(({ provider, account }) => provider === "notes"
|
|
562
|
+
? account
|
|
563
|
+
: String(stored.find((one) => one.provider === provider && one.account === account)?.id ?? 0));
|
|
557
564
|
if (!folderIds.length)
|
|
558
565
|
return { source: "internal" };
|
|
559
566
|
return { folderIds, ...(accounts.length > folderIds.length ? { withInternal: true } : {}) };
|
|
560
567
|
};
|
|
568
|
+
/** The accounts of import-only providers: their documents stay under their own key, `phone:office-pbx`. */
|
|
569
|
+
export const importAccounts = async (store) => (await store.accounts.storedAccounts()).filter(({ provider }) => isImportedProvider(provider));
|
|
561
570
|
/**
|
|
562
571
|
* `search notes` with `--source`: the notes accounts the list names — `notes:internal`, `notes:<folder id>`, `notes`
|
|
563
572
|
* — and every entry naming none of them in `skipped`. Without a list, every notes account `type` leaves in.
|
|
@@ -571,6 +580,7 @@ export const searchNotesOf = async (store, account, text, { accounts: list, app,
|
|
|
571
580
|
...(await store.notes.folders()).map(({ id }) => ({ provider: "notes", account: id })),
|
|
572
581
|
...(await store.notes.documentsAccounts()).map(({ id }) => ({ provider: "notes", account: id })),
|
|
573
582
|
...[await store.notes.addedAccount()].flatMap((added) => (added ? [{ provider: "notes", account: added.id }] : [])),
|
|
583
|
+
...(await importAccounts(store)).map(({ provider, account }) => ({ provider, account })),
|
|
574
584
|
];
|
|
575
585
|
const lock = groupLockOf(app, env);
|
|
576
586
|
const typedScope = list ?? (lock === undefined ? undefined : `group:${lock}`);
|
|
@@ -582,22 +592,24 @@ export const searchNotesOf = async (store, account, text, { accounts: list, app,
|
|
|
582
592
|
? { accounts: held, skipped: [] }
|
|
583
593
|
: fitting(entriesOfList(notesScope, await listContextOf(store, account, app, undefined, env)), ["notes", "documents"], what);
|
|
584
594
|
const source = query.source ?? noteSourceOfQuery(text).source;
|
|
585
|
-
const
|
|
595
|
+
const internal = ({ provider, account }) => provider === "notes" && account === INTERNAL_NOTES;
|
|
596
|
+
const typed = named.accounts.filter((one) => source === undefined || internal(one) === (source === "internal"));
|
|
586
597
|
if (!typed.length && list !== undefined)
|
|
587
598
|
throw new CliError("validation_error", source === "internal"
|
|
588
599
|
? "the query's source:internal keeps the notes written in memo, and the --source list names none of them: " +
|
|
589
600
|
"add notes:internal to --source, or drop source:internal from the query"
|
|
590
601
|
: "the query's source:file keeps the files from notes folders, and the --source list names none of them: " +
|
|
591
602
|
"add notes:<folder id> to --source, or drop source:file from the query");
|
|
592
|
-
const scope = list === undefined ? {} : notesScopeOf(typed);
|
|
603
|
+
const scope = list === undefined ? {} : notesScopeOf(typed, await store.accounts.storedAccounts());
|
|
593
604
|
const found = await searchNotes(store, text, {
|
|
594
605
|
...query,
|
|
595
606
|
...scope,
|
|
596
607
|
...(source ? { source } : {}),
|
|
608
|
+
...(env === undefined ? {} : { env }),
|
|
597
609
|
});
|
|
598
610
|
return {
|
|
599
611
|
...found,
|
|
600
|
-
accounts: typed.map(({ account }) => ({ resource: "notes", provider
|
|
612
|
+
accounts: typed.map(({ provider, account }) => ({ resource: "notes", provider, account })),
|
|
601
613
|
skipped: named.skipped,
|
|
602
614
|
};
|
|
603
615
|
};
|
|
@@ -15,7 +15,7 @@ import { calendarAccounts, searchEvents } from "./events-search.js";
|
|
|
15
15
|
import { excerpt } from "./excerpt.js";
|
|
16
16
|
import { MAX_SEARCH_OFFSET, searchStore } from "./messages-archive-search.js";
|
|
17
17
|
import { nearEligible } from "./messages-discovery.js";
|
|
18
|
-
import { notesScopeOf, RRF_K, searchNotes } from "./notes-search.js";
|
|
18
|
+
import { importAccounts, notesScopeOf, RRF_K, searchNotes } from "./notes-search.js";
|
|
19
19
|
import { BUSINESS_WORDS_ONLY, searchBusiness } from "./search-all-business.js";
|
|
20
20
|
import { meetingLane } from "./search-all-meetings.js";
|
|
21
21
|
import { HARDER_CANDIDATES, reorderHarder } from "./search-harder.js";
|
|
@@ -49,7 +49,7 @@ const filtersBeside = (text) => {
|
|
|
49
49
|
* What a deal or a lead is found by: plain words or phrases, all of them, or any with OR. Anything else is refused,
|
|
50
50
|
* so `search all` skips deals with the reason instead of matching a field they do not have.
|
|
51
51
|
*/
|
|
52
|
-
export const titleWords = (text, refused = "deals and leads are found by the words of their title, company and
|
|
52
|
+
export const titleWords = (text, refused = "deals and leads are found by the words of their title, company, contacts and activities only") => {
|
|
53
53
|
const { root } = parseLucene(text, SEARCH_QUERY);
|
|
54
54
|
const clauses = root.kind === "boolean" ? root.clauses : [{ node: root, occur: "must" }];
|
|
55
55
|
const words = clauses.map(({ node, occur }) => occur !== "must_not" &&
|
|
@@ -85,11 +85,16 @@ const sourceScope = async (store, account, source, asked, messenger) => {
|
|
|
85
85
|
? new Set((await store.business.accounts()).map(accountKeyOf))
|
|
86
86
|
: new Set();
|
|
87
87
|
const holdsBusiness = (one) => imported.has(accountKeyOf(one));
|
|
88
|
-
|
|
88
|
+
// An import's account holds documents under its own key, and the notes lane reads them.
|
|
89
|
+
const holdsDocuments = (one) => asked.includes("notes") && holdsKind(one.provider, "documents");
|
|
90
|
+
const { skipped } = fitting(entries, asked.filter((one) => one !== "business"), "search all", (kind) => `--only leaves ${kind} out`, (one) => holdsBusiness(one) || holdsDocuments(one));
|
|
91
|
+
const holds = (resource, one) => resource === "business"
|
|
92
|
+
? holdsBusiness(one)
|
|
93
|
+
: listedHolds(one, resource) || (resource === "notes" && holdsDocuments(one));
|
|
89
94
|
const named = (resource) => [
|
|
90
95
|
...new Map(entries
|
|
91
96
|
.flatMap(({ accounts }) => accounts)
|
|
92
|
-
.filter((one) => (resource
|
|
97
|
+
.filter((one) => holds(resource, one))
|
|
93
98
|
.map(({ provider, account }) => [`${provider}\u0000${account}`, { provider, account }])).values(),
|
|
94
99
|
];
|
|
95
100
|
const scope = Object.fromEntries(asked.map((resource) => [resource, named(resource)]));
|
|
@@ -243,7 +248,7 @@ export const searchAll = async (store, account, asked, messenger = {}, searchMes
|
|
|
243
248
|
limit: depth,
|
|
244
249
|
command,
|
|
245
250
|
embedders,
|
|
246
|
-
...(chosen === undefined ? {} : notesScopeOf(chosen)),
|
|
251
|
+
...(chosen === undefined ? {} : notesScopeOf(chosen, await store.accounts.storedAccounts())),
|
|
247
252
|
...(request.exact ? { exact: true } : {}),
|
|
248
253
|
...(discover ? { discover: true } : {}),
|
|
249
254
|
...(request.timezone === undefined ? {} : { timezone: request.timezone }),
|
|
@@ -268,13 +273,16 @@ export const searchAll = async (store, account, asked, messenger = {}, searchMes
|
|
|
268
273
|
text: hit.excerpt,
|
|
269
274
|
foundBy: hit.found_by,
|
|
270
275
|
})));
|
|
271
|
-
const read = chosen
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
const read = chosen ?? [
|
|
277
|
+
...[
|
|
278
|
+
INTERNAL_NOTES,
|
|
279
|
+
...(await store.notes.folders()).map(({ id }) => id),
|
|
280
|
+
...(await store.notes.documentsAccounts()).map(({ id }) => id),
|
|
281
|
+
...[await store.notes.addedAccount()].flatMap((added) => (added ? [added.id] : [])),
|
|
282
|
+
].map((account) => ({ provider: "notes", account })),
|
|
283
|
+
...(await importAccounts(store)).map(({ provider, account }) => ({ provider, account })),
|
|
276
284
|
];
|
|
277
|
-
accounts.push(...read.map((account) => ({ resource, provider
|
|
285
|
+
accounts.push(...read.map(({ provider, account }) => ({ resource, provider, account })));
|
|
278
286
|
}
|
|
279
287
|
else if (resource === "events") {
|
|
280
288
|
const read = scope?.events ?? (await calendarAccounts(store));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type HostKey, openSftp, SFTP_CONNECT_TIMEOUT_MS, SFTP_OPERATION_TIMEOUT_MS, SFTP_RETRY, type SftpAuth, type SftpClient, type SftpEntry, type SftpKind, type SftpOptions, type SftpReadOptions, type SftpTarget, sftpHostKey, } from "./session.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { openSftp, SFTP_CONNECT_TIMEOUT_MS, SFTP_OPERATION_TIMEOUT_MS, SFTP_RETRY, sftpHostKey, } from "./session.js";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Duplex } from "node:stream";
|
|
2
|
+
import { type RetryConfig, type SleepLike } from "@wirecat/cli-base";
|
|
3
|
+
import type { RequestEvent } from "../runs/events.js";
|
|
4
|
+
import { type HostKey, type SftpEntry } from "./ssh2.js";
|
|
5
|
+
export type SftpAuth = {
|
|
6
|
+
password: string;
|
|
7
|
+
} | {
|
|
8
|
+
privateKey: string | Uint8Array;
|
|
9
|
+
passphrase?: string;
|
|
10
|
+
};
|
|
11
|
+
export interface SftpTarget {
|
|
12
|
+
host: string;
|
|
13
|
+
/** 22 when not given. */
|
|
14
|
+
port?: number;
|
|
15
|
+
/** Seams for a test or a tunnel: a stream already connected to the server, one per connection attempt. */
|
|
16
|
+
socket?: () => Duplex | Promise<Duplex>;
|
|
17
|
+
/** The run's signal: aborting it stops every operation and closes the connection. */
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
/** The run's events (WC-LIFE-17); the current command's run when not given. */
|
|
20
|
+
events?: (event: RequestEvent) => void;
|
|
21
|
+
/** How long a connection may take up to an open SFTP channel. */
|
|
22
|
+
connectTimeoutMs?: number;
|
|
23
|
+
retry?: RetryConfig;
|
|
24
|
+
sleep?: SleepLike;
|
|
25
|
+
random?: () => number;
|
|
26
|
+
}
|
|
27
|
+
export interface SftpOptions extends SftpTarget {
|
|
28
|
+
username: string;
|
|
29
|
+
auth: SftpAuth;
|
|
30
|
+
/** The host key fingerprint the owner confirmed, `SHA256:…` as `sftpHostKey` or `ssh-keygen -lf` print it. */
|
|
31
|
+
hostKey: string;
|
|
32
|
+
/** How long one list or stat may take, and how long a read may go without receiving a byte. */
|
|
33
|
+
operationTimeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface SftpReadOptions {
|
|
36
|
+
/** A larger file is refused before its first byte is read, and a file that grows past it while read is too. */
|
|
37
|
+
maxBytes: number;
|
|
38
|
+
}
|
|
39
|
+
export interface SftpClient {
|
|
40
|
+
/** The entries of a folder, without `.` and `..`. */
|
|
41
|
+
list(path: string): Promise<SftpEntry[]>;
|
|
42
|
+
stat(path: string): Promise<SftpEntry>;
|
|
43
|
+
readFile(path: string, options: SftpReadOptions): Promise<Uint8Array>;
|
|
44
|
+
close(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export type { HostKey, SftpEntry, SftpKind } from "./ssh2.js";
|
|
47
|
+
export declare const SFTP_CONNECT_TIMEOUT_MS = 20000;
|
|
48
|
+
export declare const SFTP_OPERATION_TIMEOUT_MS = 30000;
|
|
49
|
+
/** Every operation only reads, so a transient failure is tried again: three attempts in all. */
|
|
50
|
+
export declare const SFTP_RETRY: RetryConfig;
|
|
51
|
+
/**
|
|
52
|
+
* The server's host key, for a sign-in to show the owner before the fingerprint is pinned: the connection stops at
|
|
53
|
+
* the key exchange and sends no credential.
|
|
54
|
+
*/
|
|
55
|
+
export declare const sftpHostKey: (target: SftpTarget) => Promise<HostKey>;
|
|
56
|
+
/**
|
|
57
|
+
* A read-only SFTP connection: list, stat and read, nothing that writes. The host key must match the pinned
|
|
58
|
+
* fingerprint before a credential is sent. Each operation is a request in the run's events (host and operation,
|
|
59
|
+
* never a path or file content) and is tried again on a transient failure over a fresh connection.
|
|
60
|
+
*/
|
|
61
|
+
export declare const openSftp: (input: SftpOptions) => Promise<SftpClient>;
|