@stigmer/sdk 0.0.36
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 +190 -0
- package/README.md +199 -0
- package/config.d.ts +40 -0
- package/config.d.ts.map +1 -0
- package/config.js +17 -0
- package/config.js.map +1 -0
- package/errors.d.ts +77 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +163 -0
- package/errors.js.map +1 -0
- package/gen/agent.d.ts +56 -0
- package/gen/agent.d.ts.map +1 -0
- package/gen/agent.js +113 -0
- package/gen/agent.js.map +1 -0
- package/gen/agentexecution.d.ts +68 -0
- package/gen/agentexecution.d.ts.map +1 -0
- package/gen/agentexecution.js +197 -0
- package/gen/agentexecution.js.map +1 -0
- package/gen/agentinstance.d.ts +26 -0
- package/gen/agentinstance.d.ts.map +1 -0
- package/gen/agentinstance.js +92 -0
- package/gen/agentinstance.js.map +1 -0
- package/gen/apikey.d.ts +25 -0
- package/gen/apikey.d.ts.map +1 -0
- package/gen/apikey.js +85 -0
- package/gen/apikey.js.map +1 -0
- package/gen/client.d.ts +76 -0
- package/gen/client.d.ts.map +1 -0
- package/gen/client.js +77 -0
- package/gen/client.js.map +1 -0
- package/gen/environment.d.ts +23 -0
- package/gen/environment.d.ts.map +1 -0
- package/gen/environment.js +86 -0
- package/gen/environment.js.map +1 -0
- package/gen/errors.d.ts +15 -0
- package/gen/errors.d.ts.map +1 -0
- package/gen/errors.js +52 -0
- package/gen/errors.js.map +1 -0
- package/gen/executioncontext.d.ts +24 -0
- package/gen/executioncontext.d.ts.map +1 -0
- package/gen/executioncontext.js +87 -0
- package/gen/executioncontext.js.map +1 -0
- package/gen/iampolicy.d.ts +34 -0
- package/gen/iampolicy.d.ts.map +1 -0
- package/gen/iampolicy.js +107 -0
- package/gen/iampolicy.js.map +1 -0
- package/gen/identityaccount.d.ts +35 -0
- package/gen/identityaccount.d.ts.map +1 -0
- package/gen/identityaccount.js +113 -0
- package/gen/identityaccount.js.map +1 -0
- package/gen/identityprovider.d.ts +27 -0
- package/gen/identityprovider.d.ts.map +1 -0
- package/gen/identityprovider.js +90 -0
- package/gen/identityprovider.js.map +1 -0
- package/gen/mcpserver.d.ts +50 -0
- package/gen/mcpserver.d.ts.map +1 -0
- package/gen/mcpserver.js +124 -0
- package/gen/mcpserver.js.map +1 -0
- package/gen/organization.d.ts +31 -0
- package/gen/organization.d.ts.map +1 -0
- package/gen/organization.js +102 -0
- package/gen/organization.js.map +1 -0
- package/gen/project.d.ts +24 -0
- package/gen/project.d.ts.map +1 -0
- package/gen/project.js +84 -0
- package/gen/project.js.map +1 -0
- package/gen/session.d.ts +49 -0
- package/gen/session.d.ts.map +1 -0
- package/gen/session.js +94 -0
- package/gen/session.js.map +1 -0
- package/gen/skill.d.ts +26 -0
- package/gen/skill.d.ts.map +1 -0
- package/gen/skill.js +101 -0
- package/gen/skill.js.map +1 -0
- package/gen/types.d.ts +43 -0
- package/gen/types.d.ts.map +1 -0
- package/gen/types.js +3 -0
- package/gen/types.js.map +1 -0
- package/gen/workflow.d.ts +51 -0
- package/gen/workflow.d.ts.map +1 -0
- package/gen/workflow.js +85 -0
- package/gen/workflow.js.map +1 -0
- package/gen/workflowexecution.d.ts +37 -0
- package/gen/workflowexecution.d.ts.map +1 -0
- package/gen/workflowexecution.js +161 -0
- package/gen/workflowexecution.js.map +1 -0
- package/gen/workflowinstance.d.ts +26 -0
- package/gen/workflowinstance.d.ts.map +1 -0
- package/gen/workflowinstance.js +92 -0
- package/gen/workflowinstance.js.map +1 -0
- package/index.d.ts +23 -0
- package/index.d.ts.map +1 -0
- package/index.js +26 -0
- package/index.js.map +1 -0
- package/internal/interceptors.d.ts +25 -0
- package/internal/interceptors.d.ts.map +1 -0
- package/internal/interceptors.js +75 -0
- package/internal/interceptors.js.map +1 -0
- package/package.json +40 -0
- package/search.d.ts +41 -0
- package/search.d.ts.map +1 -0
- package/search.js +45 -0
- package/search.js.map +1 -0
- package/src/config.ts +64 -0
- package/src/errors.ts +219 -0
- package/src/gen/agent.ts +146 -0
- package/src/gen/agentexecution.ts +205 -0
- package/src/gen/agentinstance.ts +91 -0
- package/src/gen/apikey.ts +86 -0
- package/src/gen/client.ts +99 -0
- package/src/gen/environment.ts +86 -0
- package/src/gen/errors.ts +74 -0
- package/src/gen/executioncontext.ts +87 -0
- package/src/gen/iampolicy.ts +108 -0
- package/src/gen/identityaccount.ts +115 -0
- package/src/gen/identityprovider.ts +94 -0
- package/src/gen/mcpserver.ts +147 -0
- package/src/gen/organization.ts +103 -0
- package/src/gen/project.ts +85 -0
- package/src/gen/session.ts +120 -0
- package/src/gen/skill.ts +102 -0
- package/src/gen/types.ts +51 -0
- package/src/gen/workflow.ts +116 -0
- package/src/gen/workflowexecution.ts +147 -0
- package/src/gen/workflowinstance.ts +91 -0
- package/src/index.ts +124 -0
- package/src/internal/interceptors.ts +83 -0
- package/src/search.ts +71 -0
- package/src/stigmer.ts +83 -0
- package/src/transport.ts +46 -0
- package/stigmer.d.ts +57 -0
- package/stigmer.d.ts.map +1 -0
- package/stigmer.js +64 -0
- package/stigmer.js.map +1 -0
- package/transport.d.ts +13 -0
- package/transport.d.ts.map +1 -0
- package/transport.js +34 -0
- package/transport.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflowinstance.js","sourceRoot":"","sources":["../../src/gen/workflowinstance.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAA+B,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAyB,MAAM,+DAA+D,CAAC;AAC9H,OAAO,EAAE,iCAAiC,EAAE,MAAM,mEAAmE,CAAC;AACtH,OAAO,EAAE,wBAAwB,EAAkJ,MAAM,8DAA8D,CAAC;AACxP,OAAO,EAAE,+BAA+B,EAA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,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,yBAAyB,CAAC,EAAE;YACzD,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,EAAE,KAAK,CAAC,GAAG;SACf,CAAC;QACF,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,0BAA0B,CAAC,EAAE;YACtD,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC;KACH,CAAqB,CAAC;AACzB,CAAC"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { Stigmer } from "./stigmer";
|
|
2
|
+
export { type StigmerConfig, type TokenProvider } from "./config";
|
|
3
|
+
export { StigmerError, type ErrorCode, isNotFound, isUnauthenticated, isPermissionDenied, isRetryable, type ErrorCategory, isConnectError, classifyError, isRetryableError, getUserMessage, type RpcErrorMetadata, annotateRpcError, getRpcMetadata, } from "./errors";
|
|
4
|
+
export { SearchClient, type SearchParams, type SearchResponse, ApiResourceKind, } from "./search";
|
|
5
|
+
export { type DeleteResourceInput, type ResourceRef, type Page, type ListParams, type ListResult, type EnvSpecInput, type EnvVarInput, } from "./gen/types";
|
|
6
|
+
export { AgentClient, type AgentInput, type McpServerUsageInput, type ToolApprovalOverrideInput, type SubAgentInput, type McpAccessInput, } from "./gen/agent";
|
|
7
|
+
export { AgentExecutionClient, type AgentExecutionInput, type ExecutionConfigInput, type ContextManagementConfigInput, type AttachmentInput, } from "./gen/agentexecution";
|
|
8
|
+
export { AgentInstanceClient, type AgentInstanceInput, } from "./gen/agentinstance";
|
|
9
|
+
export { ApiKeyClient, type ApiKeyInput } from "./gen/apikey";
|
|
10
|
+
export { EnvironmentClient, type EnvironmentInput, } from "./gen/environment";
|
|
11
|
+
export { ExecutionContextClient, type ExecutionContextInput, } from "./gen/executioncontext";
|
|
12
|
+
export { IamPolicyClient, type IamPolicyInput, type ApiResourceRefInput, } from "./gen/iampolicy";
|
|
13
|
+
export { IdentityAccountClient, type IdentityAccountInput, } from "./gen/identityaccount";
|
|
14
|
+
export { IdentityProviderClient, type IdentityProviderInput, } from "./gen/identityprovider";
|
|
15
|
+
export { McpServerClient, type McpServerInput, type StdioServerConfigInput, type HttpServerConfigInput, type ToolApprovalPolicyInput, } from "./gen/mcpserver";
|
|
16
|
+
export { OrganizationClient, type OrganizationInput, } from "./gen/organization";
|
|
17
|
+
export { ProjectClient, type ProjectInput } from "./gen/project";
|
|
18
|
+
export { SessionClient, type SessionInput, type WorkspaceEntryInput, type WorkspaceSourceInput, type GitRepoSourceInput, type LocalPathSourceInput, } from "./gen/session";
|
|
19
|
+
export { SkillClient, type SkillInput } from "./gen/skill";
|
|
20
|
+
export { WorkflowClient, type WorkflowInput, type WorkflowDocumentInput, type WorkflowTaskInput, type ExportInput, type FlowControlInput, } from "./gen/workflow";
|
|
21
|
+
export { WorkflowExecutionClient, type WorkflowExecutionInput, } from "./gen/workflowexecution";
|
|
22
|
+
export { WorkflowInstanceClient, type WorkflowInstanceInput, } from "./gen/workflowinstance";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,EACL,YAAY,EACZ,KAAK,SAAS,EACd,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,KAAK,aAAa,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,KAAK,gBAAgB,EACrB,gBAAgB,EAChB,cAAc,GACf,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,YAAY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C;AAC5B,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EACL,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,wBAAwB,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Public API for @stigmer/sdk
|
|
2
|
+
// Top-level client
|
|
3
|
+
export { Stigmer } from "./stigmer";
|
|
4
|
+
// Error handling
|
|
5
|
+
export { StigmerError, isNotFound, isUnauthenticated, isPermissionDenied, isRetryable, isConnectError, classifyError, isRetryableError, getUserMessage, annotateRpcError, getRpcMetadata, } from "./errors";
|
|
6
|
+
// Search client
|
|
7
|
+
export { SearchClient, ApiResourceKind, } from "./search";
|
|
8
|
+
// Re-export all resource client classes and input types
|
|
9
|
+
export { AgentClient, } from "./gen/agent";
|
|
10
|
+
export { AgentExecutionClient, } from "./gen/agentexecution";
|
|
11
|
+
export { AgentInstanceClient, } from "./gen/agentinstance";
|
|
12
|
+
export { ApiKeyClient } from "./gen/apikey";
|
|
13
|
+
export { EnvironmentClient, } from "./gen/environment";
|
|
14
|
+
export { ExecutionContextClient, } from "./gen/executioncontext";
|
|
15
|
+
export { IamPolicyClient, } from "./gen/iampolicy";
|
|
16
|
+
export { IdentityAccountClient, } from "./gen/identityaccount";
|
|
17
|
+
export { IdentityProviderClient, } from "./gen/identityprovider";
|
|
18
|
+
export { McpServerClient, } from "./gen/mcpserver";
|
|
19
|
+
export { OrganizationClient, } from "./gen/organization";
|
|
20
|
+
export { ProjectClient } from "./gen/project";
|
|
21
|
+
export { SessionClient, } from "./gen/session";
|
|
22
|
+
export { SkillClient } from "./gen/skill";
|
|
23
|
+
export { WorkflowClient, } from "./gen/workflow";
|
|
24
|
+
export { WorkflowExecutionClient, } from "./gen/workflowexecution";
|
|
25
|
+
export { WorkflowInstanceClient, } from "./gen/workflowinstance";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,iBAAiB;AACjB,OAAO,EACL,YAAY,EAEZ,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EAEX,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,cAAc,EAEd,gBAAgB,EAChB,cAAc,GACf,MAAM,UAAU,CAAC;AAElB,gBAAgB;AAChB,OAAO,EACL,YAAY,EAGZ,eAAe,GAChB,MAAM,UAAU,CAAC;AAalB,wDAAwD;AACxD,OAAO,EACL,WAAW,GAMZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,GAKrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,GAEpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAoB,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,iBAAiB,GAElB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,GAGhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,GAEtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,GAKhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,GAEnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAqB,MAAM,eAAe,CAAC;AACjE,OAAO,EACL,aAAa,GAMd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,cAAc,GAMf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,uBAAuB,GAExB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Interceptor } from "@connectrpc/connect";
|
|
2
|
+
import type { TokenProvider } from "../config";
|
|
3
|
+
/**
|
|
4
|
+
* Create an interceptor that attaches `Authorization: Bearer <token>` to
|
|
5
|
+
* every outgoing request. Supports both static API keys and dynamic token
|
|
6
|
+
* providers.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createAuthInterceptor(getAccessToken: TokenProvider): Interceptor;
|
|
9
|
+
/**
|
|
10
|
+
* Interceptor that annotates every error with the RPC method name and
|
|
11
|
+
* service path that produced it. Must run before error-transforming
|
|
12
|
+
* interceptors so the raw request context is available.
|
|
13
|
+
*/
|
|
14
|
+
export declare const rpcMetadataInterceptor: Interceptor;
|
|
15
|
+
/**
|
|
16
|
+
* Interceptor that strips gRPC status-code prefixes (e.g., `[internal]`)
|
|
17
|
+
* from error messages. The structured code remains on `ConnectError.code`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const errorStripInterceptor: Interceptor;
|
|
20
|
+
/**
|
|
21
|
+
* Create an interceptor that invokes a callback on UNAUTHENTICATED (code 16).
|
|
22
|
+
* The callback fires at most once per client to prevent cascading redirects.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createAuthRedirectInterceptor(onUnauthenticated: () => void): Interceptor;
|
|
25
|
+
//# sourceMappingURL=interceptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../src/internal/interceptors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG/C;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,aAAa,GAC5B,WAAW,CAQb;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,WAgBlC,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,WASnC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,iBAAiB,EAAE,MAAM,IAAI,GAC5B,WAAW,CAiBb"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ConnectError, Code } from "@connectrpc/connect";
|
|
2
|
+
import { annotateRpcError } from "../errors";
|
|
3
|
+
/**
|
|
4
|
+
* Create an interceptor that attaches `Authorization: Bearer <token>` to
|
|
5
|
+
* every outgoing request. Supports both static API keys and dynamic token
|
|
6
|
+
* providers.
|
|
7
|
+
*/
|
|
8
|
+
export function createAuthInterceptor(getAccessToken) {
|
|
9
|
+
return (next) => async (request) => {
|
|
10
|
+
const token = await getAccessToken();
|
|
11
|
+
if (token) {
|
|
12
|
+
request.header.set("Authorization", `Bearer ${token}`);
|
|
13
|
+
}
|
|
14
|
+
return next(request);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Interceptor that annotates every error with the RPC method name and
|
|
19
|
+
* service path that produced it. Must run before error-transforming
|
|
20
|
+
* interceptors so the raw request context is available.
|
|
21
|
+
*/
|
|
22
|
+
export const rpcMetadataInterceptor = (next) => async (request) => {
|
|
23
|
+
try {
|
|
24
|
+
return await next(request);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error !== null && typeof error === "object") {
|
|
28
|
+
const segments = request.url.split("/");
|
|
29
|
+
const method = segments.at(-1) ?? "";
|
|
30
|
+
const service = segments.at(-2) ?? "";
|
|
31
|
+
annotateRpcError(error, {
|
|
32
|
+
method: method.charAt(0).toLowerCase() + method.slice(1),
|
|
33
|
+
path: `/${service}/${method}`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Interceptor that strips gRPC status-code prefixes (e.g., `[internal]`)
|
|
41
|
+
* from error messages. The structured code remains on `ConnectError.code`.
|
|
42
|
+
*/
|
|
43
|
+
export const errorStripInterceptor = (next) => async (request) => {
|
|
44
|
+
try {
|
|
45
|
+
return await next(request);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof Error && error.message) {
|
|
49
|
+
error.message = error.message.replace(/^\[.*?]\s*/, "");
|
|
50
|
+
}
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Create an interceptor that invokes a callback on UNAUTHENTICATED (code 16).
|
|
56
|
+
* The callback fires at most once per client to prevent cascading redirects.
|
|
57
|
+
*/
|
|
58
|
+
export function createAuthRedirectInterceptor(onUnauthenticated) {
|
|
59
|
+
let fired = false;
|
|
60
|
+
return (next) => async (request) => {
|
|
61
|
+
try {
|
|
62
|
+
return await next(request);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (!fired &&
|
|
66
|
+
error instanceof ConnectError &&
|
|
67
|
+
error.code === Code.Unauthenticated) {
|
|
68
|
+
fired = true;
|
|
69
|
+
onUnauthenticated();
|
|
70
|
+
}
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=interceptors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../src/internal/interceptors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAoB,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,cAA6B;IAE7B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACjC,MAAM,KAAK,GAAG,MAAM,cAAc,EAAE,CAAC;QACrC,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GACjC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IAC1B,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACxC,MAAM,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACrC,MAAM,OAAO,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACtC,gBAAgB,CAAC,KAAK,E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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stigmer/sdk",
|
|
3
|
+
"version": "0.0.36",
|
|
4
|
+
"description": "Stigmer TypeScript SDK — typed API client for all Stigmer platform resources",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/stigmer/stigmer.git",
|
|
11
|
+
"directory": "sdk/typescript"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"stigmer",
|
|
18
|
+
"sdk",
|
|
19
|
+
"api-client",
|
|
20
|
+
"grpc-web",
|
|
21
|
+
"connect-rpc",
|
|
22
|
+
"ai-agents"
|
|
23
|
+
],
|
|
24
|
+
"main": "./index.js",
|
|
25
|
+
"types": "./index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./index.d.ts",
|
|
29
|
+
"import": "./index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@connectrpc/connect": "^2.0.0",
|
|
34
|
+
"@connectrpc/connect-web": "^2.0.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@bufbuild/protobuf": "^2.0.0",
|
|
38
|
+
"@stigmer/protos": "0.0.36"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/search.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Transport } from "@connectrpc/connect";
|
|
2
|
+
import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
|
|
3
|
+
import type { SearchResult } from "@stigmer/protos/ai/stigmer/search/v1/io_pb";
|
|
4
|
+
/** Re-export ApiResourceKind for use with SearchClient. */
|
|
5
|
+
export { ApiResourceKind };
|
|
6
|
+
/** Parameters for a cross-resource search query. */
|
|
7
|
+
export interface SearchParams {
|
|
8
|
+
/** Resource kinds to include in the search. */
|
|
9
|
+
readonly kinds: ApiResourceKind[];
|
|
10
|
+
/** Organization slug to scope the query. */
|
|
11
|
+
readonly org: string;
|
|
12
|
+
/** Free-text search query. */
|
|
13
|
+
readonly query?: string;
|
|
14
|
+
/** Whether to exclude public (non-org) resources from results. */
|
|
15
|
+
readonly excludePublic?: boolean;
|
|
16
|
+
/** Pagination parameters. */
|
|
17
|
+
readonly page?: {
|
|
18
|
+
num: number;
|
|
19
|
+
size: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** A page of cross-resource search results. */
|
|
23
|
+
export interface SearchResponse {
|
|
24
|
+
readonly entries: SearchResult[];
|
|
25
|
+
readonly totalCount: number;
|
|
26
|
+
readonly totalPages: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Cross-resource search client.
|
|
30
|
+
*
|
|
31
|
+
* Unlike the per-resource `list()` methods (which search within a single
|
|
32
|
+
* resource kind), `SearchClient.query()` searches across multiple resource
|
|
33
|
+
* kinds in a single call.
|
|
34
|
+
*/
|
|
35
|
+
export declare class SearchClient {
|
|
36
|
+
private readonly search;
|
|
37
|
+
constructor(transport: Transport);
|
|
38
|
+
/** Perform a cross-resource search. */
|
|
39
|
+
query(params: SearchParams): Promise<SearchResponse>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=search.d.ts.map
|
package/search.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKhF,OAAO,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AACtH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAG/E,2DAA2D;AAC3D,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC;IAClC,4CAA4C;IAC5C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,kEAAkE;IAClE,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,6BAA6B;IAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED,+CAA+C;AAC/C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;gBAE1C,SAAS,EAAE,SAAS;IAIhC,uCAAuC;IACjC,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;CAsB3D"}
|
package/search.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createClient } from "@connectrpc/connect";
|
|
2
|
+
import { create } from "@bufbuild/protobuf";
|
|
3
|
+
import { SearchService } from "@stigmer/protos/ai/stigmer/search/v1/query_pb";
|
|
4
|
+
import { SearchRequestSchema } from "@stigmer/protos/ai/stigmer/search/v1/io_pb";
|
|
5
|
+
import { PageInfoSchema } from "@stigmer/protos/ai/stigmer/commons/rpc/pagination_pb";
|
|
6
|
+
import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
|
|
7
|
+
import { wrapError } from "./gen/errors";
|
|
8
|
+
/** Re-export ApiResourceKind for use with SearchClient. */
|
|
9
|
+
export { ApiResourceKind };
|
|
10
|
+
/**
|
|
11
|
+
* Cross-resource search client.
|
|
12
|
+
*
|
|
13
|
+
* Unlike the per-resource `list()` methods (which search within a single
|
|
14
|
+
* resource kind), `SearchClient.query()` searches across multiple resource
|
|
15
|
+
* kinds in a single call.
|
|
16
|
+
*/
|
|
17
|
+
export class SearchClient {
|
|
18
|
+
search;
|
|
19
|
+
constructor(transport) {
|
|
20
|
+
this.search = createClient(SearchService, transport);
|
|
21
|
+
}
|
|
22
|
+
/** Perform a cross-resource search. */
|
|
23
|
+
async query(params) {
|
|
24
|
+
try {
|
|
25
|
+
const resp = await this.search.search(create(SearchRequestSchema, {
|
|
26
|
+
kinds: params.kinds,
|
|
27
|
+
query: params.query,
|
|
28
|
+
org: params.org,
|
|
29
|
+
excludePublic: params.excludePublic ?? false,
|
|
30
|
+
page: params.page
|
|
31
|
+
? create(PageInfoSchema, params.page)
|
|
32
|
+
: undefined,
|
|
33
|
+
}));
|
|
34
|
+
return {
|
|
35
|
+
entries: resp.entries,
|
|
36
|
+
totalCount: resp.totalCount,
|
|
37
|
+
totalPages: resp.totalPages,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
throw wrapError(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=search.js.map
|
package/search.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA+B,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AAEtH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,2DAA2D;AAC3D,OAAO,EAAE,eAAe,EAAE,CAAC;AAuB3B;;;;;;GAMG;AACH,MAAM,OAAO,YAAY;IACN,MAAM,CAA+B;IAEtD,YAAY,SAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,uCAAuC;IACvC,KAAK,CAAC,KAAK,CAAC,MAAoB;QAC9B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CACnC,MAAM,CAAC,mBAAmB,EAAE;gBAC1B,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,KAAK;gBAC5C,IAAI,EAAE,MAAM,CAAC,IAAI;oBACf,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC;oBACrC,CAAC,CAAC,SAAS;aACd,CAAC,CACH,CAAC;YACF,OAAO;gBACL,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;aAC5B,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;CACF"}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token provider callback for dynamic authentication.
|
|
3
|
+
* Called per-request, allowing token refresh and auth state changes.
|
|
4
|
+
* Return `null` to skip authentication for that request.
|
|
5
|
+
*/
|
|
6
|
+
export type TokenProvider = () => Promise<string | null> | string | null;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for the Stigmer SDK client.
|
|
10
|
+
*
|
|
11
|
+
* Exactly one of `apiKey` or `getAccessToken` must be provided:
|
|
12
|
+
* - `apiKey`: Static API key for server-to-server usage.
|
|
13
|
+
* - `getAccessToken`: Dynamic token provider for browser or rotating credentials.
|
|
14
|
+
*/
|
|
15
|
+
export interface StigmerConfig {
|
|
16
|
+
/** Base URL of the Stigmer API server (e.g., "https://api.stigmer.io"). */
|
|
17
|
+
readonly baseUrl: string;
|
|
18
|
+
|
|
19
|
+
/** Static API key. Sent as `Authorization: Bearer <apiKey>` on every request. */
|
|
20
|
+
readonly apiKey?: string;
|
|
21
|
+
|
|
22
|
+
/** Dynamic token provider. Called per-request to obtain a Bearer token. */
|
|
23
|
+
readonly getAccessToken?: TokenProvider;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Called when the server returns UNAUTHENTICATED (code 16).
|
|
27
|
+
* Typically used to clear auth state and redirect to login.
|
|
28
|
+
* Invoked at most once per client instance to prevent cascading redirects.
|
|
29
|
+
*/
|
|
30
|
+
readonly onUnauthenticated?: () => void;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Transport protocol to use for API communication.
|
|
34
|
+
* - `"grpc-web"` (default): gRPC-Web binary protocol. Compact, battle-tested.
|
|
35
|
+
* - `"connect"`: Connect protocol over HTTP/JSON. Easier to debug with standard HTTP tooling.
|
|
36
|
+
*
|
|
37
|
+
* Both protocols are supported by the Stigmer server.
|
|
38
|
+
*/
|
|
39
|
+
readonly transport?: "grpc-web" | "connect";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Validate a StigmerConfig and throw a descriptive error for invalid configurations.
|
|
44
|
+
*/
|
|
45
|
+
export function validateConfig(config: StigmerConfig): void {
|
|
46
|
+
if (!config.baseUrl) {
|
|
47
|
+
throw new Error("stigmer: baseUrl is required");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const hasApiKey = typeof config.apiKey === "string" && config.apiKey.length > 0;
|
|
51
|
+
const hasTokenProvider = typeof config.getAccessToken === "function";
|
|
52
|
+
|
|
53
|
+
if (!hasApiKey && !hasTokenProvider) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"stigmer: either apiKey or getAccessToken must be provided",
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (hasApiKey && hasTokenProvider) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"stigmer: apiKey and getAccessToken are mutually exclusive — provide one, not both",
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { ConnectError, Code } from "@connectrpc/connect";
|
|
2
|
+
import { StigmerError, type ErrorCode } from "./gen/errors";
|
|
3
|
+
|
|
4
|
+
// Re-export generated error types
|
|
5
|
+
export {
|
|
6
|
+
StigmerError,
|
|
7
|
+
type ErrorCode,
|
|
8
|
+
wrapError,
|
|
9
|
+
isNotFound,
|
|
10
|
+
isUnauthenticated,
|
|
11
|
+
isPermissionDenied,
|
|
12
|
+
isRetryable,
|
|
13
|
+
} from "./gen/errors";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Coarse-grained error categories derived from gRPC/Connect status codes.
|
|
17
|
+
* Each category maps to a distinct UX treatment:
|
|
18
|
+
*
|
|
19
|
+
* - `auth` — session expired or missing credentials (redirect to login)
|
|
20
|
+
* - `permission` — valid session but insufficient access (inline error)
|
|
21
|
+
* - `not-found` — requested resource does not exist (inline error)
|
|
22
|
+
* - `validation` — request rejected due to invalid input (inline / form error)
|
|
23
|
+
* - `server` — unexpected server failure (inline error with retry)
|
|
24
|
+
* - `unavailable` — server unreachable or overloaded (inline error with retry)
|
|
25
|
+
* - `cancelled` — request aborted, usually by the user (silent)
|
|
26
|
+
* - `unknown` — non-RPC error or unmapped code (inline error)
|
|
27
|
+
*/
|
|
28
|
+
export type ErrorCategory =
|
|
29
|
+
| "auth"
|
|
30
|
+
| "permission"
|
|
31
|
+
| "not-found"
|
|
32
|
+
| "validation"
|
|
33
|
+
| "server"
|
|
34
|
+
| "unavailable"
|
|
35
|
+
| "cancelled"
|
|
36
|
+
| "unknown";
|
|
37
|
+
|
|
38
|
+
const CONNECT_CODE_TO_CATEGORY: Record<number, ErrorCategory> = {
|
|
39
|
+
[Code.Unauthenticated]: "auth",
|
|
40
|
+
[Code.PermissionDenied]: "permission",
|
|
41
|
+
[Code.NotFound]: "not-found",
|
|
42
|
+
[Code.InvalidArgument]: "validation",
|
|
43
|
+
[Code.FailedPrecondition]: "validation",
|
|
44
|
+
[Code.OutOfRange]: "validation",
|
|
45
|
+
[Code.AlreadyExists]: "validation",
|
|
46
|
+
[Code.Aborted]: "validation",
|
|
47
|
+
[Code.Internal]: "server",
|
|
48
|
+
[Code.Unknown]: "server",
|
|
49
|
+
[Code.DataLoss]: "server",
|
|
50
|
+
[Code.Unimplemented]: "server",
|
|
51
|
+
[Code.Unavailable]: "unavailable",
|
|
52
|
+
[Code.DeadlineExceeded]: "unavailable",
|
|
53
|
+
[Code.ResourceExhausted]: "unavailable",
|
|
54
|
+
[Code.Canceled]: "cancelled",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const ERROR_CODE_TO_CATEGORY: Record<ErrorCode, ErrorCategory> = {
|
|
58
|
+
unauthenticated: "auth",
|
|
59
|
+
"permission-denied": "permission",
|
|
60
|
+
"not-found": "not-found",
|
|
61
|
+
"invalid-argument": "validation",
|
|
62
|
+
"already-exists": "validation",
|
|
63
|
+
"failed-precondition": "validation",
|
|
64
|
+
"resource-exhausted": "unavailable",
|
|
65
|
+
internal: "server",
|
|
66
|
+
unavailable: "unavailable",
|
|
67
|
+
cancelled: "cancelled",
|
|
68
|
+
unknown: "server",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Narrow an unknown thrown value to {@link ConnectError}.
|
|
73
|
+
*
|
|
74
|
+
* Uses `ConnectError[Symbol.hasInstance]` which handles cross-package
|
|
75
|
+
* identity correctly (multiple copies of `@connectrpc/connect` in the
|
|
76
|
+
* dependency tree).
|
|
77
|
+
*/
|
|
78
|
+
export function isConnectError(error: unknown): error is ConnectError {
|
|
79
|
+
return error instanceof ConnectError;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Map any thrown value to an {@link ErrorCategory}.
|
|
84
|
+
*
|
|
85
|
+
* Handles both {@link StigmerError} (thrown by SDK methods) and raw
|
|
86
|
+
* {@link ConnectError} (from direct transport usage). All other values
|
|
87
|
+
* are classified as `"unknown"`.
|
|
88
|
+
*/
|
|
89
|
+
export function classifyError(error: unknown): ErrorCategory {
|
|
90
|
+
if (error instanceof StigmerError) {
|
|
91
|
+
return ERROR_CODE_TO_CATEGORY[error.code] ?? "unknown";
|
|
92
|
+
}
|
|
93
|
+
if (isConnectError(error)) {
|
|
94
|
+
return CONNECT_CODE_TO_CATEGORY[error.code] ?? "unknown";
|
|
95
|
+
}
|
|
96
|
+
return "unknown";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const RETRYABLE_CATEGORIES: ReadonlySet<ErrorCategory> = new Set([
|
|
100
|
+
"server",
|
|
101
|
+
"unavailable",
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Whether the error represents a transient failure worth retrying.
|
|
106
|
+
*
|
|
107
|
+
* Only `server` and `unavailable` categories are retryable. Auth, permission,
|
|
108
|
+
* not-found, and validation errors are deterministic — the same request
|
|
109
|
+
* will produce the same failure.
|
|
110
|
+
*/
|
|
111
|
+
export function isRetryableError(error: unknown): boolean {
|
|
112
|
+
return RETRYABLE_CATEGORIES.has(classifyError(error));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const CATEGORY_FALLBACKS: Record<ErrorCategory, string> = {
|
|
116
|
+
auth: "Your session has expired. Please sign in again.",
|
|
117
|
+
permission: "You do not have permission to perform this action.",
|
|
118
|
+
"not-found": "The requested resource was not found.",
|
|
119
|
+
validation: "The request contains invalid data.",
|
|
120
|
+
server: "An unexpected server error occurred. Please try again.",
|
|
121
|
+
unavailable:
|
|
122
|
+
"The server is temporarily unavailable. Please try again in a moment.",
|
|
123
|
+
cancelled: "The request was cancelled.",
|
|
124
|
+
unknown: "An unexpected error occurred.",
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const INFRA_NOISE_PATTERNS: ReadonlyArray<readonly [RegExp, string]> = [
|
|
128
|
+
[/no healthy upstream/i, "The server is temporarily unavailable."],
|
|
129
|
+
[/ECONNREFUSED/i, "Unable to connect to the server."],
|
|
130
|
+
[/ECONNRESET/i, "The connection to the server was lost."],
|
|
131
|
+
[/ETIMEDOUT/i, "The request timed out. Please try again."],
|
|
132
|
+
[/fetch failed/i, "Unable to reach the server. Check your connection."],
|
|
133
|
+
[/network error/i, "A network error occurred. Check your connection."],
|
|
134
|
+
[/failed to fetch/i, "Unable to reach the server. Check your connection."],
|
|
135
|
+
[/load balancer/i, "The server is temporarily unavailable."],
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Extract a clean, user-appropriate error message from any thrown value.
|
|
140
|
+
*
|
|
141
|
+
* 1. For {@link StigmerError} or {@link ConnectError}, uses the raw message
|
|
142
|
+
* (which excludes the `[code]` prefix added by Connect-RPC).
|
|
143
|
+
* 2. Sanitizes infrastructure noise (e.g., "no healthy upstream") into
|
|
144
|
+
* readable text.
|
|
145
|
+
* 3. Falls back to a category-specific default when the raw message is
|
|
146
|
+
* empty or is infrastructure noise.
|
|
147
|
+
*
|
|
148
|
+
* @param error — the thrown value (typically from a catch block)
|
|
149
|
+
* @param fallback — optional override for the default fallback message
|
|
150
|
+
*/
|
|
151
|
+
export function getUserMessage(error: unknown, fallback?: string): string {
|
|
152
|
+
const raw = extractRawMessage(error);
|
|
153
|
+
const sanitized = sanitizeMessage(raw);
|
|
154
|
+
if (sanitized) return sanitized;
|
|
155
|
+
|
|
156
|
+
const category = classifyError(error);
|
|
157
|
+
return fallback ?? CATEGORY_FALLBACKS[category];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function extractRawMessage(error: unknown): string {
|
|
161
|
+
if (error instanceof StigmerError) {
|
|
162
|
+
return error.message;
|
|
163
|
+
}
|
|
164
|
+
if (isConnectError(error)) {
|
|
165
|
+
return error.rawMessage;
|
|
166
|
+
}
|
|
167
|
+
if (error instanceof Error) {
|
|
168
|
+
return error.message;
|
|
169
|
+
}
|
|
170
|
+
if (typeof error === "string") {
|
|
171
|
+
return error;
|
|
172
|
+
}
|
|
173
|
+
return "";
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function sanitizeMessage(message: string): string {
|
|
177
|
+
if (!message) return "";
|
|
178
|
+
for (const [pattern, replacement] of INFRA_NOISE_PATTERNS) {
|
|
179
|
+
if (pattern.test(message)) return replacement;
|
|
180
|
+
}
|
|
181
|
+
return message;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Metadata about the RPC call that produced an error. Attached by the
|
|
186
|
+
* SDK's metadata interceptor and readable via {@link getRpcMetadata}.
|
|
187
|
+
*/
|
|
188
|
+
export interface RpcErrorMetadata {
|
|
189
|
+
readonly method: string;
|
|
190
|
+
readonly path: string;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const rpcMetadataStore = new WeakMap<object, RpcErrorMetadata>();
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Attach RPC call metadata to an error object.
|
|
197
|
+
*
|
|
198
|
+
* Called by the metadata interceptor — application code should use
|
|
199
|
+
* {@link getRpcMetadata} to read metadata, not this function.
|
|
200
|
+
*
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
export function annotateRpcError(
|
|
204
|
+
error: object,
|
|
205
|
+
metadata: RpcErrorMetadata,
|
|
206
|
+
): void {
|
|
207
|
+
rpcMetadataStore.set(error, metadata);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Retrieve RPC metadata previously attached by the metadata interceptor.
|
|
212
|
+
* Returns `undefined` if the error was not annotated.
|
|
213
|
+
*/
|
|
214
|
+
export function getRpcMetadata(error: unknown): RpcErrorMetadata | undefined {
|
|
215
|
+
if (error !== null && typeof error === "object") {
|
|
216
|
+
return rpcMetadataStore.get(error);
|
|
217
|
+
}
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|