@stigmer/sdk 3.12.3 → 3.12.5
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/__tests__/billing.test.js +36 -0
- package/__tests__/billing.test.js.map +1 -1
- package/__tests__/mcpserver-connect.test.d.ts +2 -0
- package/__tests__/mcpserver-connect.test.d.ts.map +1 -0
- package/__tests__/mcpserver-connect.test.js +146 -0
- package/__tests__/mcpserver-connect.test.js.map +1 -0
- package/__tests__/skill.test.d.ts +2 -0
- package/__tests__/skill.test.d.ts.map +1 -0
- package/__tests__/skill.test.js +117 -0
- package/__tests__/skill.test.js.map +1 -0
- package/__tests__/update-input.test.d.ts +2 -0
- package/__tests__/update-input.test.d.ts.map +1 -0
- package/__tests__/update-input.test.js +169 -0
- package/__tests__/update-input.test.js.map +1 -0
- package/billing.d.ts +27 -0
- package/billing.d.ts.map +1 -1
- package/billing.js +26 -1
- package/billing.js.map +1 -1
- package/errors.d.ts +1 -1
- package/errors.d.ts.map +1 -1
- package/errors.js +1 -1
- package/errors.js.map +1 -1
- package/execution/__tests__/tool-view.fixtures.test.js +23 -4
- package/execution/__tests__/tool-view.fixtures.test.js.map +1 -1
- package/execution/tool-view.d.ts +32 -0
- package/execution/tool-view.d.ts.map +1 -1
- package/execution/tool-view.js +45 -0
- package/execution/tool-view.js.map +1 -1
- package/gen/agentexecution.d.ts +6 -0
- package/gen/agentexecution.d.ts.map +1 -1
- package/gen/agentexecution.js +9 -1
- package/gen/agentexecution.js.map +1 -1
- package/gen/client.d.ts +4 -4
- package/gen/client.d.ts.map +1 -1
- package/gen/client.js +1 -1
- package/gen/client.js.map +1 -1
- package/gen/errors.d.ts +7 -0
- package/gen/errors.d.ts.map +1 -1
- package/gen/errors.js +9 -0
- package/gen/errors.js.map +1 -1
- package/gen/identityaccount.d.ts +8 -0
- package/gen/identityaccount.d.ts.map +1 -1
- package/gen/identityaccount.js +11 -1
- package/gen/identityaccount.js.map +1 -1
- package/gen/mcpserver.d.ts +1 -0
- package/gen/mcpserver.d.ts.map +1 -1
- package/gen/mcpserver.js +8 -0
- package/gen/mcpserver.js.map +1 -1
- package/gen/oauthapp.d.ts +2 -1
- package/gen/oauthapp.d.ts.map +1 -1
- package/gen/oauthapp.js +1 -0
- package/gen/oauthapp.js.map +1 -1
- package/gen/organization.d.ts +5 -0
- package/gen/organization.d.ts.map +1 -1
- package/gen/organization.js +8 -1
- package/gen/organization.js.map +1 -1
- package/gen/platformclient.d.ts +1 -0
- package/gen/platformclient.d.ts.map +1 -1
- package/gen/platformclient.js +2 -0
- package/gen/platformclient.js.map +1 -1
- package/index.d.ts +6 -2
- package/index.d.ts.map +1 -1
- package/index.js +8 -2
- package/index.js.map +1 -1
- package/mcpserver-connect.d.ts +79 -0
- package/mcpserver-connect.d.ts.map +1 -0
- package/mcpserver-connect.js +114 -0
- package/mcpserver-connect.js.map +1 -0
- package/package.json +2 -2
- package/provider-standing.d.ts +19 -0
- package/provider-standing.d.ts.map +1 -0
- package/provider-standing.js +31 -0
- package/provider-standing.js.map +1 -0
- package/skill.d.ts +51 -0
- package/skill.d.ts.map +1 -0
- package/skill.js +102 -0
- package/skill.js.map +1 -0
- package/src/__tests__/billing.test.ts +44 -0
- package/src/__tests__/mcpserver-connect.test.ts +181 -0
- package/src/__tests__/skill.test.ts +150 -0
- package/src/__tests__/update-input.test.ts +219 -0
- package/src/billing.ts +44 -0
- package/src/errors.ts +1 -0
- package/src/execution/__tests__/tool-view.fixtures.test.ts +41 -4
- package/src/execution/tool-view.ts +52 -0
- package/src/gen/agentexecution.ts +17 -1
- package/src/gen/client.ts +4 -4
- package/src/gen/errors.ts +10 -0
- package/src/gen/identityaccount.ts +21 -1
- package/src/gen/mcpserver.ts +6 -0
- package/src/gen/oauthapp.ts +3 -1
- package/src/gen/organization.ts +15 -1
- package/src/gen/platformclient.ts +3 -0
- package/src/index.ts +22 -0
- package/src/mcpserver-connect.ts +159 -0
- package/src/provider-standing.ts +37 -0
- package/src/skill.ts +125 -0
- package/src/stigmer.ts +12 -0
- package/src/update-input.ts +168 -0
- package/stigmer.d.ts +10 -0
- package/stigmer.d.ts.map +1 -1
- package/stigmer.js +12 -0
- package/stigmer.js.map +1 -1
- package/update-input.d.ts +24 -0
- package/update-input.d.ts.map +1 -0
- package/update-input.js +126 -0
- package/update-input.js.map +1 -0
package/index.js
CHANGED
|
@@ -8,9 +8,11 @@ export { createGuestAuth, GuestAuth, } from "./guest-auth.js";
|
|
|
8
8
|
// Agent sharing (hosted link + embed snippet; framework-free)
|
|
9
9
|
export { MAX_ALLOWED_ORIGINS, LINK_TOKEN_PARAM, validateOrigin, chatPath, buildChatUrl, appendLinkToken, buildEmbedLoaderUrl, buildEmbedSnippet, } from "./sharing.js";
|
|
10
10
|
// Error handling
|
|
11
|
-
export { StigmerError, isNotFound, isUnauthenticated, isPermissionDenied, isRetryable, isConnectError, classifyError, isRetryableError, isTransientStreamError, getUserMessage, getErrorReason, annotateRpcError, getRpcMetadata, } from "./errors.js";
|
|
11
|
+
export { StigmerError, isNotFound, isUnauthenticated, isPermissionDenied, isRetryable, isUnimplemented, isConnectError, classifyError, isRetryableError, isTransientStreamError, getUserMessage, getErrorReason, annotateRpcError, getRpcMetadata, } from "./errors.js";
|
|
12
12
|
// Resource availability
|
|
13
13
|
export { isResourceAvailable, } from "./resource-availability.js";
|
|
14
|
+
// Complete update-input mappers (full-spec-replace round-trip safety)
|
|
15
|
+
export { toOrganizationUpdateInput, toIdentityAccountUpdateInput, } from "./update-input.js";
|
|
14
16
|
// Authorization config and IAM role utilities
|
|
15
17
|
export { getGrantableRoles, hasGrantableRoles, isRoleGrantable, } from "./authorization-config.js";
|
|
16
18
|
export { iamRoleToString, iamRoleFromString, iamRoleDisplayName, iamRoleDescription, } from "./iam-role.js";
|
|
@@ -21,6 +23,8 @@ export { ActivityClient, } from "./activity.js";
|
|
|
21
23
|
export { BillingClient, } from "./billing.js";
|
|
22
24
|
// Cursor accounts client (platform operators only)
|
|
23
25
|
export { CursorAccountsClient, } from "./cursor-accounts.js";
|
|
26
|
+
// Provider standing client (platform operators only, read-only)
|
|
27
|
+
export { ProviderStandingClient } from "./provider-standing.js";
|
|
24
28
|
// Search client
|
|
25
29
|
export { SearchClient, ApiResourceKind, } from "./search.js";
|
|
26
30
|
// GitHub OAuth client
|
|
@@ -45,6 +49,7 @@ export { InvitationClient, } from "./gen/invitation.js";
|
|
|
45
49
|
export { IdentityProviderClient, } from "./gen/identityprovider.js";
|
|
46
50
|
export { OAuthAppClient, } from "./gen/oauthapp.js";
|
|
47
51
|
export { McpServerClient, buildMcpServerProto, } from "./gen/mcpserver.js";
|
|
52
|
+
export { connectAndWait, ConnectStillRunningError, CONNECT_POLL_INTERVAL_MS, CONNECT_SETTLE_BOUND_MS, } from "./mcpserver-connect.js";
|
|
48
53
|
export { OrganizationClient, } from "./gen/organization.js";
|
|
49
54
|
export { PlatformClientClient, } from "./gen/platformclient.js";
|
|
50
55
|
export { ProjectClient } from "./gen/project.js";
|
|
@@ -53,12 +58,13 @@ export { SessionClient, } from "./gen/session.js";
|
|
|
53
58
|
// Session utilities (hand-written)
|
|
54
59
|
export { PENDING_SUBJECT, SESSION_CONTEXT_METADATA_KEY, mergeSessionContext, resolvedSubject, } from "./session.js";
|
|
55
60
|
// Tool-call view model (framework-agnostic; shared by @stigmer/react and @stigmer/ink)
|
|
56
|
-
export { ToolKind, FileChangeCaptureLevel, resolveToolKind, resolveToolKindByName, normalizeToolResult, } from "./execution/tool-view.js";
|
|
61
|
+
export { ToolKind, FileChangeCaptureLevel, resolveToolKind, resolveToolKindByName, normalizeToolResult, SHELL_INTENT_ARG_FIELD, extractShellIntent, shellIntentFromArgs, } from "./execution/tool-view.js";
|
|
57
62
|
export { ApprovalPolicySource, describeApprovalPolicySource, isInformativePolicySource, } from "./execution/approval-provenance.js";
|
|
58
63
|
export { isTerminalPhase } from "./execution/execution-phases.js";
|
|
59
64
|
export { foldFileReviewEventStream, displayFileChangeSets, } from "./execution/file-review-fold.js";
|
|
60
65
|
export { toDisplayFileChange } from "./execution/to-display-file-change.js";
|
|
61
66
|
export { SkillClient } from "./gen/skill.js";
|
|
67
|
+
export { RoutedSkillClient, MAX_INLINE_ARTIFACT_BYTES } from "./skill.js";
|
|
62
68
|
export { WorkflowClient, } from "./gen/workflow.js";
|
|
63
69
|
export { WorkflowExecutionClient, } from "./gen/workflowexecution.js";
|
|
64
70
|
export { WorkflowInstanceClient, } from "./gen/workflowinstance.js";
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,iBAAiB;AACjB,OAAO,EAGL,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAK7B,4EAA4E;AAC5E,OAAO,EACL,eAAe,EACf,SAAS,GAGV,MAAM,iBAAiB,CAAC;AAEzB,8DAA8D;AAC9D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,iBAAiB;AACjB,OAAO,EACL,YAAY,EAEZ,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,iBAAiB;AACjB,OAAO,EAGL,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAK7B,4EAA4E;AAC5E,OAAO,EACL,eAAe,EACf,SAAS,GAGV,MAAM,iBAAiB,CAAC;AAEzB,8DAA8D;AAC9D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,cA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B,GAInB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,GAMd,MAAM,kBAAkB,CAAC;AAE1B,mCAAmC;AACnC,OAAO,EACL,eAAe,EACf,4BAA4B,EAC5B,mBAAmB,EACnB,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB,uFAAuF;AACvF,OAAO,EACL,QAAQ,EACR,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,GAIpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EACL,cAAc,GAMf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,uBAAuB,GAExB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { McpServer } from "@stigmer/protos/ai/stigmer/agentic/mcpserver/v1/api_pb";
|
|
2
|
+
import type { ConnectInput } from "@stigmer/protos/ai/stigmer/agentic/mcpserver/v1/io_pb";
|
|
3
|
+
/**
|
|
4
|
+
* The slice of {@link McpServerClient} the connect protocol needs — the
|
|
5
|
+
* async-lane pair plus the blocking fallback. Structural on purpose: the
|
|
6
|
+
* full client satisfies it, and tests can hand in three functions.
|
|
7
|
+
*/
|
|
8
|
+
export interface McpServerConnectLane {
|
|
9
|
+
startConnect(input: ConnectInput): Promise<McpServer>;
|
|
10
|
+
connect(input: ConnectInput): Promise<McpServer>;
|
|
11
|
+
get(id: string): Promise<McpServer>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* How often {@link connectAndWait} re-reads the resource while a connect
|
|
15
|
+
* operation runs. Discovery legitimately takes tens of seconds to minutes;
|
|
16
|
+
* a few seconds of staleness is invisible next to that, and each poll is
|
|
17
|
+
* one cheap get.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CONNECT_POLL_INTERVAL_MS = 2500;
|
|
20
|
+
/**
|
|
21
|
+
* Absolute bound on waiting for a connect to settle: the backend's async
|
|
22
|
+
* connect ceiling (its asyncConnectTimeout, 60 min) plus margin. Every
|
|
23
|
+
* operation settles within the ceiling by construction; only a
|
|
24
|
+
* connect_status orphaned by a backend restart can still read CONNECTING
|
|
25
|
+
* past it, and this bound turns that into a typed error instead of an
|
|
26
|
+
* infinite wait.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CONNECT_SETTLE_BOUND_MS: number;
|
|
29
|
+
/**
|
|
30
|
+
* Thrown by {@link connectAndWait} when it stopped waiting while the
|
|
31
|
+
* server-side operation was still running. NOT a failure: the backend
|
|
32
|
+
* finishes the connect on its own and persists the result — re-read the
|
|
33
|
+
* resource (or re-run the connect) to observe the outcome.
|
|
34
|
+
*/
|
|
35
|
+
export declare class ConnectStillRunningError extends Error {
|
|
36
|
+
readonly mcpServerId: string;
|
|
37
|
+
constructor(mcpServerId: string, waitedMs: number);
|
|
38
|
+
}
|
|
39
|
+
/** Options for {@link connectAndWait}. */
|
|
40
|
+
export interface ConnectAndWaitOptions {
|
|
41
|
+
/** Poll cadence. Defaults to {@link CONNECT_POLL_INTERVAL_MS}. */
|
|
42
|
+
readonly pollIntervalMs?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Stop waiting after this long (soft bound — the server-side operation
|
|
45
|
+
* keeps running). Defaults to {@link CONNECT_SETTLE_BOUND_MS}, and is
|
|
46
|
+
* capped by it: waiting longer than the backend's own ceiling can only
|
|
47
|
+
* ever observe an orphaned record.
|
|
48
|
+
*/
|
|
49
|
+
readonly deadlineMs?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Observe the CONNECTING snapshot the moment the operation is accepted —
|
|
52
|
+
* the place to read `status.connect_status.warning` (the dead-runner
|
|
53
|
+
* advisory) before the wait begins. Not called on the blocking fallback,
|
|
54
|
+
* which has no start-time snapshot.
|
|
55
|
+
*/
|
|
56
|
+
readonly onStarted?: (started: McpServer) => void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Connect an MCP server and wait for the operation to settle, without any
|
|
60
|
+
* long-lived RPC (stigmer/stigmer#425).
|
|
61
|
+
*
|
|
62
|
+
* Uses the async lane — `startConnect` returns immediately with
|
|
63
|
+
* `status.connect_status = CONNECTING`, then the resource is polled until
|
|
64
|
+
* the operation settles — so the wait survives transport limits that kill
|
|
65
|
+
* a long-blocking unary call (browsers drop no-bytes responses around
|
|
66
|
+
* ~300s, below the server's discovery ceiling). Callers never see the
|
|
67
|
+
* mechanics: the promise resolves with the updated server exactly as the
|
|
68
|
+
* blocking `connect` RPC resolved, and a failed operation rejects with the
|
|
69
|
+
* same {@link StigmerError} classification the blocking RPC would have
|
|
70
|
+
* thrown (`connect_status.failure_code` is the Go gRPC code name, which
|
|
71
|
+
* matches connect-es `Code` member names — rehydration is lossless).
|
|
72
|
+
*
|
|
73
|
+
* Backends that predate the async lane answer UNIMPLEMENTED for
|
|
74
|
+
* `startConnect`; this falls back to the blocking `connect` RPC — the same
|
|
75
|
+
* edition capability-probe idiom as the skill artifact-transfer lane
|
|
76
|
+
* (skill.ts) and the org-OAuth-app surface.
|
|
77
|
+
*/
|
|
78
|
+
export declare function connectAndWait(client: McpServerConnectLane, input: ConnectInput, options?: ConnectAndWaitOptions): Promise<McpServer>;
|
|
79
|
+
//# sourceMappingURL=mcpserver-connect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpserver-connect.d.ts","sourceRoot":"","sources":["../src/mcpserver-connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wDAAwD,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uDAAuD,CAAC;AAI1F;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACtD,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACjD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACrC;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,OAAQ,CAAC;AAE9C;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,QAAc,CAAC;AAEnD;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAQlD;AAED,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,IAAI,CAAC;CACnD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,SAAS,CAAC,CA2BpB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Code, ConnectError } from "@connectrpc/connect";
|
|
2
|
+
import { ConnectPhase } from "@stigmer/protos/ai/stigmer/agentic/mcpserver/v1/status_pb";
|
|
3
|
+
import { isUnimplemented, wrapError } from "./gen/errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* How often {@link connectAndWait} re-reads the resource while a connect
|
|
6
|
+
* operation runs. Discovery legitimately takes tens of seconds to minutes;
|
|
7
|
+
* a few seconds of staleness is invisible next to that, and each poll is
|
|
8
|
+
* one cheap get.
|
|
9
|
+
*/
|
|
10
|
+
export const CONNECT_POLL_INTERVAL_MS = 2_500;
|
|
11
|
+
/**
|
|
12
|
+
* Absolute bound on waiting for a connect to settle: the backend's async
|
|
13
|
+
* connect ceiling (its asyncConnectTimeout, 60 min) plus margin. Every
|
|
14
|
+
* operation settles within the ceiling by construction; only a
|
|
15
|
+
* connect_status orphaned by a backend restart can still read CONNECTING
|
|
16
|
+
* past it, and this bound turns that into a typed error instead of an
|
|
17
|
+
* infinite wait.
|
|
18
|
+
*/
|
|
19
|
+
export const CONNECT_SETTLE_BOUND_MS = 65 * 60_000;
|
|
20
|
+
/**
|
|
21
|
+
* Thrown by {@link connectAndWait} when it stopped waiting while the
|
|
22
|
+
* server-side operation was still running. NOT a failure: the backend
|
|
23
|
+
* finishes the connect on its own and persists the result — re-read the
|
|
24
|
+
* resource (or re-run the connect) to observe the outcome.
|
|
25
|
+
*/
|
|
26
|
+
export class ConnectStillRunningError extends Error {
|
|
27
|
+
mcpServerId;
|
|
28
|
+
constructor(mcpServerId, waitedMs) {
|
|
29
|
+
super(`the connect of MCP server '${mcpServerId}' is still running server-side after ${Math.round(waitedMs / 1000)}s — ` +
|
|
30
|
+
"it will persist its result on its own; re-read the server to observe the outcome");
|
|
31
|
+
this.name = "ConnectStillRunningError";
|
|
32
|
+
this.mcpServerId = mcpServerId;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Connect an MCP server and wait for the operation to settle, without any
|
|
37
|
+
* long-lived RPC (stigmer/stigmer#425).
|
|
38
|
+
*
|
|
39
|
+
* Uses the async lane — `startConnect` returns immediately with
|
|
40
|
+
* `status.connect_status = CONNECTING`, then the resource is polled until
|
|
41
|
+
* the operation settles — so the wait survives transport limits that kill
|
|
42
|
+
* a long-blocking unary call (browsers drop no-bytes responses around
|
|
43
|
+
* ~300s, below the server's discovery ceiling). Callers never see the
|
|
44
|
+
* mechanics: the promise resolves with the updated server exactly as the
|
|
45
|
+
* blocking `connect` RPC resolved, and a failed operation rejects with the
|
|
46
|
+
* same {@link StigmerError} classification the blocking RPC would have
|
|
47
|
+
* thrown (`connect_status.failure_code` is the Go gRPC code name, which
|
|
48
|
+
* matches connect-es `Code` member names — rehydration is lossless).
|
|
49
|
+
*
|
|
50
|
+
* Backends that predate the async lane answer UNIMPLEMENTED for
|
|
51
|
+
* `startConnect`; this falls back to the blocking `connect` RPC — the same
|
|
52
|
+
* edition capability-probe idiom as the skill artifact-transfer lane
|
|
53
|
+
* (skill.ts) and the org-OAuth-app surface.
|
|
54
|
+
*/
|
|
55
|
+
export async function connectAndWait(client, input, options) {
|
|
56
|
+
const pollIntervalMs = options?.pollIntervalMs ?? CONNECT_POLL_INTERVAL_MS;
|
|
57
|
+
const waitMs = Math.min(options?.deadlineMs ?? CONNECT_SETTLE_BOUND_MS, CONNECT_SETTLE_BOUND_MS);
|
|
58
|
+
let started;
|
|
59
|
+
try {
|
|
60
|
+
started = await client.startConnect(input);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
if (!isUnimplemented(err))
|
|
64
|
+
throw err;
|
|
65
|
+
return blockingConnect(client, input, waitMs);
|
|
66
|
+
}
|
|
67
|
+
options?.onStarted?.(started);
|
|
68
|
+
const deadline = Date.now() + waitMs;
|
|
69
|
+
for (;;) {
|
|
70
|
+
if (Date.now() >= deadline) {
|
|
71
|
+
throw new ConnectStillRunningError(input.mcpServerId, waitMs);
|
|
72
|
+
}
|
|
73
|
+
await sleep(Math.min(pollIntervalMs, Math.max(1, deadline - Date.now())));
|
|
74
|
+
const current = await client.get(input.mcpServerId);
|
|
75
|
+
const cs = current.status?.connectStatus;
|
|
76
|
+
if (cs?.phase === ConnectPhase.succeeded)
|
|
77
|
+
return current;
|
|
78
|
+
if (cs?.phase === ConnectPhase.failed) {
|
|
79
|
+
throw rehydrateConnectFailure(cs.failureCode, cs.failureMessage);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// The pre-async-lane path, kept behaviorally identical for old backends: one
|
|
84
|
+
// blocking RPC, raced (not cancelled — the server finishes and persists on
|
|
85
|
+
// its own) against the caller's soft bound.
|
|
86
|
+
async function blockingConnect(client, input, waitMs) {
|
|
87
|
+
const push = client.connect(input);
|
|
88
|
+
// The losing push may settle after the caller has moved on; swallow its
|
|
89
|
+
// late rejection so it cannot surface as an unhandled-rejection crash.
|
|
90
|
+
void push.catch(() => { });
|
|
91
|
+
let timer;
|
|
92
|
+
const timeout = new Promise((_, reject) => {
|
|
93
|
+
timer = setTimeout(() => reject(new ConnectStillRunningError(input.mcpServerId, waitMs)), waitMs);
|
|
94
|
+
});
|
|
95
|
+
try {
|
|
96
|
+
return await Promise.race([push, timeout]);
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
if (timer !== undefined)
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Rebuild the failure the blocking connect RPC would have thrown, from the
|
|
104
|
+
// classification the backend persisted on connect_status. Routing the
|
|
105
|
+
// rehydrated ConnectError through wrapError makes the result byte-identical
|
|
106
|
+
// to a live RPC failure (same StigmerError code mapping, same raw message).
|
|
107
|
+
function rehydrateConnectFailure(failureCode, failureMessage) {
|
|
108
|
+
const code = Code[failureCode];
|
|
109
|
+
return wrapError(new ConnectError(failureMessage, typeof code === "number" ? code : Code.Unknown));
|
|
110
|
+
}
|
|
111
|
+
function sleep(ms) {
|
|
112
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=mcpserver-connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpserver-connect.js","sourceRoot":"","sources":["../src/mcpserver-connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,2DAA2D,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAa7D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,MAAM,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxC,WAAW,CAAS;IAE7B,YAAY,WAAmB,EAAE,QAAgB;QAC/C,KAAK,CACH,8BAA8B,WAAW,wCAAwC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM;YAChH,kFAAkF,CACrF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AAsBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,KAAmB,EACnB,OAA+B;IAE/B,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,wBAAwB,CAAC;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,IAAI,uBAAuB,EAAE,uBAAuB,CAAC,CAAC;IAEjG,IAAI,OAAkB,CAAC;IACvB,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;I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AAK,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAE1B,IAAI,KAAgD,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC/C,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,wBAAwB,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACpG,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C,CAAC;YAAS,CAAC;QACT,IAAI,KAAK,KAAK,SAAS;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,sEAAsE;AACtE,4EAA4E;AAC5E,4EAA4E;AAC5E,SAAS,uBAAuB,CAAC,WAAmB,EAAE,cAAsB;IAC1E,MAAM,IAAI,GAAI,IAAgC,CAAC,WAAW,CAAC,CAAC;IAC5D,OAAO,SAAS,CAAC,IAAI,YAAY,CAAC,cAAc,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAE,IAAa,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/G,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stigmer/sdk",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.5",
|
|
4
4
|
"description": "Stigmer TypeScript SDK — typed API client for all Stigmer platform resources",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@bufbuild/protobuf": "^2.0.0",
|
|
47
47
|
"@connectrpc/connect-node": "^2.0.0",
|
|
48
|
-
"@stigmer/protos": "3.12.
|
|
48
|
+
"@stigmer/protos": "3.12.5"
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Transport } from "@connectrpc/connect";
|
|
2
|
+
import { type ProviderStandingView } from "@stigmer/protos/ai/stigmer/platform/providerstanding/v1/io_pb";
|
|
3
|
+
/**
|
|
4
|
+
* Client for platform provider standing (platform operators only).
|
|
5
|
+
*
|
|
6
|
+
* Serves the read-only operator view of the platform's LLM provider
|
|
7
|
+
* account health: the latest canary-probe verdict per provider (status,
|
|
8
|
+
* HTTP status, latency, bounded error summary, probe time) recorded by
|
|
9
|
+
* the hourly standing probe. Requires `can_view_provider_standing` on
|
|
10
|
+
* `platform:stigmer`. Cloud-only — the OSS Go server does not implement
|
|
11
|
+
* this controller.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ProviderStandingClient {
|
|
14
|
+
private readonly query;
|
|
15
|
+
constructor(transport: Transport);
|
|
16
|
+
/** Retrieve the latest probe verdict for every platform provider. */
|
|
17
|
+
getStandingView(): Promise<ProviderStandingView>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=provider-standing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-standing.d.ts","sourceRoot":"","sources":["../src/provider-standing.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhF,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,+DAA+D,CAAC;AAGvE;;;;;;;;;GASG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiD;gBAE3D,SAAS,EAAE,SAAS;IAIhC,qEAAqE;IAC/D,eAAe,IAAI,OAAO,CAAC,oBAAoB,CAAC;CASvD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createClient } from "@connectrpc/connect";
|
|
2
|
+
import { create } from "@bufbuild/protobuf";
|
|
3
|
+
import { ProviderStandingQueryController } from "@stigmer/protos/ai/stigmer/platform/providerstanding/v1/query_pb";
|
|
4
|
+
import { GetProviderStandingViewInputSchema, } from "@stigmer/protos/ai/stigmer/platform/providerstanding/v1/io_pb";
|
|
5
|
+
import { wrapError } from "./gen/errors.js";
|
|
6
|
+
/**
|
|
7
|
+
* Client for platform provider standing (platform operators only).
|
|
8
|
+
*
|
|
9
|
+
* Serves the read-only operator view of the platform's LLM provider
|
|
10
|
+
* account health: the latest canary-probe verdict per provider (status,
|
|
11
|
+
* HTTP status, latency, bounded error summary, probe time) recorded by
|
|
12
|
+
* the hourly standing probe. Requires `can_view_provider_standing` on
|
|
13
|
+
* `platform:stigmer`. Cloud-only — the OSS Go server does not implement
|
|
14
|
+
* this controller.
|
|
15
|
+
*/
|
|
16
|
+
export class ProviderStandingClient {
|
|
17
|
+
query;
|
|
18
|
+
constructor(transport) {
|
|
19
|
+
this.query = createClient(ProviderStandingQueryController, transport);
|
|
20
|
+
}
|
|
21
|
+
/** Retrieve the latest probe verdict for every platform provider. */
|
|
22
|
+
async getStandingView() {
|
|
23
|
+
try {
|
|
24
|
+
return await this.query.getProviderStandingView(create(GetProviderStandingViewInputSchema, {}));
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
throw wrapError(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=provider-standing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-standing.js","sourceRoot":"","sources":["../src/provider-standing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA+B,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,+BAA+B,EAAE,MAAM,kEAAkE,CAAC;AACnH,OAAO,EACL,kCAAkC,GAEnC,MAAM,+DAA+D,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,OAAO,sBAAsB;IAChB,KAAK,CAAiD;IAEvE,YAAY,SAAoB;QAC9B,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,+BAA+B,EAAE,SAAS,CAAC,CAAC;IACxE,CAAC;IAED,qEAAqE;IACrE,KAAK,CAAC,eAAe;QACnB,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAC7C,MAAM,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAC/C,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;CACF"}
|
package/skill.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Transport } from "@connectrpc/connect";
|
|
2
|
+
import type { Skill } from "@stigmer/protos/ai/stigmer/agentic/skill/v1/api_pb";
|
|
3
|
+
import { type PushSkillRequest } from "@stigmer/protos/ai/stigmer/agentic/skill/v1/io_pb";
|
|
4
|
+
import { SkillClient } from "./gen/skill.js";
|
|
5
|
+
/**
|
|
6
|
+
* Largest artifact pushed inline in the gRPC request (#675). The server's
|
|
7
|
+
* transport cap is 10MB for the WHOLE message, so the artifact leaves 64KB
|
|
8
|
+
* of headroom for the request envelope (org, tag, provenance, framing).
|
|
9
|
+
* Mirrors the Go SDK's maxInlineArtifactBytes.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAX_INLINE_ARTIFACT_BYTES: number;
|
|
12
|
+
/**
|
|
13
|
+
* Skill client with transport-aware push routing (stigmer#675 / #701).
|
|
14
|
+
*
|
|
15
|
+
* The gRPC transport caps messages at 10MB while skills may be up to 100MB,
|
|
16
|
+
* so `push` routes by size: small artifacts travel inline in the request
|
|
17
|
+
* (one round trip, unchanged behavior), larger ones are staged over HTTP
|
|
18
|
+
* via `createArtifactUploadUrl` — a capability URL, so no auth header —
|
|
19
|
+
* and pushed by reference. Callers never see the mechanics: `push(req)`
|
|
20
|
+
* simply works for any valid skill size.
|
|
21
|
+
*
|
|
22
|
+
* Every other method is the generated client's, inherited unchanged.
|
|
23
|
+
*/
|
|
24
|
+
export declare class RoutedSkillClient extends SkillClient {
|
|
25
|
+
private readonly fetchImpl;
|
|
26
|
+
/**
|
|
27
|
+
* @param fetchImpl - Custom `fetch` for the staging PUT. Must be the same
|
|
28
|
+
* implementation the transport uses where the global one is restricted
|
|
29
|
+
* (the Tauri CSP/CORS case the `Stigmer.fetch` property documents).
|
|
30
|
+
*/
|
|
31
|
+
constructor(transport: Transport, fetchImpl?: typeof globalThis.fetch);
|
|
32
|
+
/**
|
|
33
|
+
* Push a skill, routing the artifact by size (see the class comment).
|
|
34
|
+
*
|
|
35
|
+
* A request that already carries an `artifactUploadRef` is passed through
|
|
36
|
+
* untouched — the caller has done its own staging.
|
|
37
|
+
*/
|
|
38
|
+
push(input: PushSkillRequest): Promise<Skill>;
|
|
39
|
+
/**
|
|
40
|
+
* Stage the artifact over HTTP and push by reference:
|
|
41
|
+
* createArtifactUploadUrl → PUT bytes → push(artifactUploadRef).
|
|
42
|
+
*/
|
|
43
|
+
private pushViaUploadUrl;
|
|
44
|
+
/**
|
|
45
|
+
* PUT the artifact ZIP to the staging URL. The URL is the credential
|
|
46
|
+
* (capability semantics — a pre-signed R2 URL on cloud, the server's own
|
|
47
|
+
* transfer lane on OSS), so no auth header is attached.
|
|
48
|
+
*/
|
|
49
|
+
private putArtifact;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=skill.d.ts.map
|
package/skill.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../src/skill.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oDAAoD,CAAC;AAChF,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,mDAAmD,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,QAA+B,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsC;IAEhE;;;;OAIG;gBACS,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK;IAKrE;;;;;OAKG;IACY,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC;IAO5D;;;OAGG;YACW,gBAAgB;IAqC9B;;;;OAIG;YACW,WAAW;CAoB1B"}
|
package/skill.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { create } from "@bufbuild/protobuf";
|
|
2
|
+
import { Code } from "@connectrpc/connect";
|
|
3
|
+
import { CreateSkillArtifactUploadUrlRequestSchema, PushSkillRequestSchema, } from "@stigmer/protos/ai/stigmer/agentic/skill/v1/io_pb";
|
|
4
|
+
import { isUnimplemented, StigmerError } from "./gen/errors.js";
|
|
5
|
+
import { SkillClient } from "./gen/skill.js";
|
|
6
|
+
/**
|
|
7
|
+
* Largest artifact pushed inline in the gRPC request (#675). The server's
|
|
8
|
+
* transport cap is 10MB for the WHOLE message, so the artifact leaves 64KB
|
|
9
|
+
* of headroom for the request envelope (org, tag, provenance, framing).
|
|
10
|
+
* Mirrors the Go SDK's maxInlineArtifactBytes.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_INLINE_ARTIFACT_BYTES = 10 * 1024 * 1024 - 64 * 1024;
|
|
13
|
+
/**
|
|
14
|
+
* Skill client with transport-aware push routing (stigmer#675 / #701).
|
|
15
|
+
*
|
|
16
|
+
* The gRPC transport caps messages at 10MB while skills may be up to 100MB,
|
|
17
|
+
* so `push` routes by size: small artifacts travel inline in the request
|
|
18
|
+
* (one round trip, unchanged behavior), larger ones are staged over HTTP
|
|
19
|
+
* via `createArtifactUploadUrl` — a capability URL, so no auth header —
|
|
20
|
+
* and pushed by reference. Callers never see the mechanics: `push(req)`
|
|
21
|
+
* simply works for any valid skill size.
|
|
22
|
+
*
|
|
23
|
+
* Every other method is the generated client's, inherited unchanged.
|
|
24
|
+
*/
|
|
25
|
+
export class RoutedSkillClient extends SkillClient {
|
|
26
|
+
fetchImpl;
|
|
27
|
+
/**
|
|
28
|
+
* @param fetchImpl - Custom `fetch` for the staging PUT. Must be the same
|
|
29
|
+
* implementation the transport uses where the global one is restricted
|
|
30
|
+
* (the Tauri CSP/CORS case the `Stigmer.fetch` property documents).
|
|
31
|
+
*/
|
|
32
|
+
constructor(transport, fetchImpl) {
|
|
33
|
+
super(transport);
|
|
34
|
+
this.fetchImpl = fetchImpl;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Push a skill, routing the artifact by size (see the class comment).
|
|
38
|
+
*
|
|
39
|
+
* A request that already carries an `artifactUploadRef` is passed through
|
|
40
|
+
* untouched — the caller has done its own staging.
|
|
41
|
+
*/
|
|
42
|
+
async push(input) {
|
|
43
|
+
if (input.artifactUploadRef !== "" || input.artifact.length <= MAX_INLINE_ARTIFACT_BYTES) {
|
|
44
|
+
return super.push(input);
|
|
45
|
+
}
|
|
46
|
+
return this.pushViaUploadUrl(input);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Stage the artifact over HTTP and push by reference:
|
|
50
|
+
* createArtifactUploadUrl → PUT bytes → push(artifactUploadRef).
|
|
51
|
+
*/
|
|
52
|
+
async pushViaUploadUrl(input) {
|
|
53
|
+
let minted;
|
|
54
|
+
try {
|
|
55
|
+
minted = await super.createArtifactUploadUrl(create(CreateSkillArtifactUploadUrlRequestSchema, {
|
|
56
|
+
org: input.org,
|
|
57
|
+
sizeBytes: BigInt(input.artifact.length),
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (isUnimplemented(err)) {
|
|
62
|
+
// Pre-transfer-lane server: without staging, an artifact this size
|
|
63
|
+
// physically cannot travel. Say so instead of surfacing the raw
|
|
64
|
+
// transport error (the failure mode #675 reported).
|
|
65
|
+
throw new StigmerError("unknown", `skill artifact is ${input.artifact.length} bytes, above the ~10MB gRPC message cap, ` +
|
|
66
|
+
"and this server does not support the HTTP artifact transfer lane — " +
|
|
67
|
+
"upgrade stigmer-server to push skills of this size", Code.Unimplemented, { cause: err });
|
|
68
|
+
}
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
await this.putArtifact(minted.url, input.artifact);
|
|
72
|
+
// Same request, artifact traveling by reference instead of by value.
|
|
73
|
+
const byRef = create(PushSkillRequestSchema, {
|
|
74
|
+
...input,
|
|
75
|
+
artifact: new Uint8Array(0),
|
|
76
|
+
artifactUploadRef: minted.artifactUploadRef,
|
|
77
|
+
});
|
|
78
|
+
return super.push(byRef);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* PUT the artifact ZIP to the staging URL. The URL is the credential
|
|
82
|
+
* (capability semantics — a pre-signed R2 URL on cloud, the server's own
|
|
83
|
+
* transfer lane on OSS), so no auth header is attached.
|
|
84
|
+
*/
|
|
85
|
+
async putArtifact(url, artifact) {
|
|
86
|
+
const doFetch = this.fetchImpl ?? globalThis.fetch;
|
|
87
|
+
const resp = await doFetch(url, {
|
|
88
|
+
method: "PUT",
|
|
89
|
+
// Both DOM and undici accept an ArrayBufferView body at runtime; the
|
|
90
|
+
// cast bridges TS 5.7's ArrayBufferLike generic, which BodyInit's
|
|
91
|
+
// typing predates. A Blob/Buffer wrapper would copy up to 100MB for
|
|
92
|
+
// nothing, and Buffer is Node-only while this client is isomorphic.
|
|
93
|
+
body: artifact,
|
|
94
|
+
headers: { "content-type": "application/zip" },
|
|
95
|
+
});
|
|
96
|
+
if (!resp.ok) {
|
|
97
|
+
const detail = (await resp.text().catch(() => "")).slice(0, 512).trim();
|
|
98
|
+
throw new StigmerError("unknown", `skill artifact upload rejected with HTTP ${resp.status}${detail === "" ? "" : `: ${detail}`}`, Code.Unknown);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=skill.js.map
|
package/skill.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.js","sourceRoot":"","sources":["../src/skill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAG3C,OAAO,EACL,yCAAyC,EACzC,sBAAsB,GAEvB,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAC/B,SAAS,CAAsC;IAEhE;;;;OAIG;IACH,YAAY,SAAoB,EAAE,SAAmC;QACnE,KAAK,CAAC,SAAS,CAAC,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACM,KAAK,CAAC,IAAI,CAAC,KAAuB;QACzC,IAAI,KAAK,CAAC,iBAAiB,KAAK,EAAE,IAA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;IACK,KAAK,CAAC,WAAW,CAAC,GAAW,EAAE,QAAoB;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC;QACnD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE;YAC9B,MAAM,EAAE,KAAK;YACb,qEAAqE;YACrE,kEAAkE;YAClE,oEAAoE;YACpE,oEAAoE;YACpE,IAAI,EAAE,QAA0C;YAChD,OAAO,EAAE,EAAE,cAAc,EAAE,iBAAiB,EAAE;SAC/C,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YACxE,MAAM,IAAI,YAAY,CACpB,SAAS,EACT,4CAA4C,IAAI,CAAC,MAAM,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE,EAC9F,IAAI,CAAC,OAAO,CACb,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -12,6 +12,7 @@ import { BillingQueryController } from "@stigmer/protos/ai/stigmer/billing/v1/qu
|
|
|
12
12
|
import {
|
|
13
13
|
CreditLedgerResponseSchema,
|
|
14
14
|
type AdjustCreditsInput,
|
|
15
|
+
type GrantCreditsInput,
|
|
15
16
|
type GetCreditLedgerInput,
|
|
16
17
|
} from "@stigmer/protos/ai/stigmer/billing/v1/io_pb";
|
|
17
18
|
import { CreditLedgerEntrySchema } from "@stigmer/protos/ai/stigmer/billing/v1/credit_pb";
|
|
@@ -20,6 +21,7 @@ import { BillingClient } from "../billing.js";
|
|
|
20
21
|
|
|
21
22
|
interface Captured {
|
|
22
23
|
adjustCredits?: AdjustCreditsInput;
|
|
24
|
+
grantCredits?: GrantCreditsInput;
|
|
23
25
|
getCreditLedger?: GetCreditLedgerInput;
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -30,6 +32,10 @@ function fakeTransport(captured: Captured): Transport {
|
|
|
30
32
|
captured.adjustCredits = req;
|
|
31
33
|
return create(CreditLedgerEntrySchema, { amountMicros: req.amountMicros });
|
|
32
34
|
},
|
|
35
|
+
grantCredits: (req) => {
|
|
36
|
+
captured.grantCredits = req;
|
|
37
|
+
return create(CreditLedgerEntrySchema, { amountMicros: req.amountMicros });
|
|
38
|
+
},
|
|
33
39
|
});
|
|
34
40
|
service(BillingQueryController, {
|
|
35
41
|
getCreditLedger: (req) => {
|
|
@@ -60,6 +66,44 @@ describe("BillingClient.adjustCredits", () => {
|
|
|
60
66
|
});
|
|
61
67
|
});
|
|
62
68
|
|
|
69
|
+
describe("BillingClient.grantCredits", () => {
|
|
70
|
+
it("maps params including the expiry onto GrantCreditsInput", async () => {
|
|
71
|
+
const captured: Captured = {};
|
|
72
|
+
const client = new BillingClient(fakeTransport(captured));
|
|
73
|
+
|
|
74
|
+
const expiresAt = new Date("2026-08-31T23:59:59Z");
|
|
75
|
+
const entry = await client.grantCredits({
|
|
76
|
+
orgId: "acme",
|
|
77
|
+
amountMicros: 5_000_000n,
|
|
78
|
+
expiresAt,
|
|
79
|
+
reason: "monthly free allowance 2026-08",
|
|
80
|
+
idempotencyKey: "allowance-acme-2026-08",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(entry.amountMicros).toBe(5_000_000n);
|
|
84
|
+
const req = captured.grantCredits;
|
|
85
|
+
expect(req?.orgId).toBe("acme");
|
|
86
|
+
expect(req?.amountMicros).toBe(5_000_000n);
|
|
87
|
+
expect(req?.expiresAt && timestampDate(req.expiresAt)).toEqual(expiresAt);
|
|
88
|
+
expect(req?.reason).toBe("monthly free allowance 2026-08");
|
|
89
|
+
expect(req?.idempotencyKey).toBe("allowance-acme-2026-08");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("omits the expiry for a never-expiring grant", async () => {
|
|
93
|
+
const captured: Captured = {};
|
|
94
|
+
const client = new BillingClient(fakeTransport(captured));
|
|
95
|
+
|
|
96
|
+
await client.grantCredits({
|
|
97
|
+
orgId: "acme",
|
|
98
|
+
amountMicros: 1_000_000n,
|
|
99
|
+
reason: "welcome credit",
|
|
100
|
+
idempotencyKey: "welcome-acme",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(captured.grantCredits?.expiresAt).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
63
107
|
describe("BillingClient.getCreditLedger", () => {
|
|
64
108
|
it("maps all filters including the time range", async () => {
|
|
65
109
|
const captured: Captured = {};
|