@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
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Stigmer Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# @stigmer/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Stigmer platform. Provides typed API clients for all Stigmer resources with authentication, error handling, and cross-resource search.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @stigmer/sdk @stigmer/protos @bufbuild/protobuf
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`@stigmer/protos` and `@bufbuild/protobuf` are peer dependencies.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### Server-to-server (static API key)
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Stigmer } from "@stigmer/sdk";
|
|
19
|
+
|
|
20
|
+
const stigmer = new Stigmer({
|
|
21
|
+
baseUrl: "https://api.stigmer.io",
|
|
22
|
+
apiKey: "sk_live_abc123",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const agent = await stigmer.agent.get("agent-id");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Browser / rotating credentials
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Stigmer } from "@stigmer/sdk";
|
|
32
|
+
|
|
33
|
+
const stigmer = new Stigmer({
|
|
34
|
+
baseUrl: "https://api.stigmer.io",
|
|
35
|
+
getAccessToken: () => authStore.getToken(),
|
|
36
|
+
onUnauthenticated: () => router.push("/login"),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const agents = await stigmer.agent.list({ org: "my-org" });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Resource Clients
|
|
43
|
+
|
|
44
|
+
Every resource type has a typed client accessible as a property on the `Stigmer` instance:
|
|
45
|
+
|
|
46
|
+
| Property | Resource |
|
|
47
|
+
|----------------------|--------------------|
|
|
48
|
+
| `agent` | Agent |
|
|
49
|
+
| `agentExecution` | AgentExecution |
|
|
50
|
+
| `agentInstance` | AgentInstance |
|
|
51
|
+
| `apiKey` | ApiKey |
|
|
52
|
+
| `environment` | Environment |
|
|
53
|
+
| `executionContext` | ExecutionContext |
|
|
54
|
+
| `iamPolicy` | IamPolicy |
|
|
55
|
+
| `identityAccount` | IdentityAccount |
|
|
56
|
+
| `identityProvider` | IdentityProvider |
|
|
57
|
+
| `mcpServer` | McpServer |
|
|
58
|
+
| `organization` | Organization |
|
|
59
|
+
| `project` | Project |
|
|
60
|
+
| `session` | Session |
|
|
61
|
+
| `skill` | Skill |
|
|
62
|
+
| `workflow` | Workflow |
|
|
63
|
+
| `workflowExecution` | WorkflowExecution |
|
|
64
|
+
| `workflowInstance` | WorkflowInstance |
|
|
65
|
+
| `search` | Cross-resource search |
|
|
66
|
+
|
|
67
|
+
### Common operations
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// Create
|
|
71
|
+
const agent = await stigmer.agent.create({
|
|
72
|
+
name: "my-agent",
|
|
73
|
+
org: "my-org",
|
|
74
|
+
description: "Handles customer inquiries",
|
|
75
|
+
instructions: "Be helpful and concise.",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Get by ID
|
|
79
|
+
const agent = await stigmer.agent.get("agent-id");
|
|
80
|
+
|
|
81
|
+
// Get by reference (org + slug)
|
|
82
|
+
const agent = await stigmer.agent.getByReference({
|
|
83
|
+
org: "my-org",
|
|
84
|
+
slug: "my-agent",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Update
|
|
88
|
+
const updated = await stigmer.agent.update({
|
|
89
|
+
name: "my-agent",
|
|
90
|
+
org: "my-org",
|
|
91
|
+
description: "Updated description",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Delete
|
|
95
|
+
const deleted = await stigmer.agent.delete("agent-id");
|
|
96
|
+
|
|
97
|
+
// List (search-backed)
|
|
98
|
+
const results = await stigmer.agent.list({
|
|
99
|
+
org: "my-org",
|
|
100
|
+
query: "customer",
|
|
101
|
+
page: { num: 1, size: 20 },
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Cross-resource search
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { ApiResourceKind } from "@stigmer/sdk";
|
|
109
|
+
|
|
110
|
+
const results = await stigmer.search.query({
|
|
111
|
+
kinds: [ApiResourceKind.agent, ApiResourceKind.skill],
|
|
112
|
+
org: "my-org",
|
|
113
|
+
query: "customer support",
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Streaming
|
|
118
|
+
|
|
119
|
+
Resources with streaming RPCs return `AsyncGenerator`:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
for await (const event of stigmer.agentExecution.watch("execution-id")) {
|
|
123
|
+
console.log(event);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// With cancellation
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
for await (const event of stigmer.agentExecution.watch("execution-id", controller.signal)) {
|
|
129
|
+
if (shouldStop(event)) {
|
|
130
|
+
controller.abort();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Error Handling
|
|
136
|
+
|
|
137
|
+
All SDK operations throw `StigmerError` with structured error codes:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { StigmerError, isNotFound, isRetryable } from "@stigmer/sdk";
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const agent = await stigmer.agent.get("nonexistent");
|
|
144
|
+
} catch (err) {
|
|
145
|
+
if (isNotFound(err)) {
|
|
146
|
+
console.log("Agent not found");
|
|
147
|
+
} else if (isRetryable(err)) {
|
|
148
|
+
console.log("Transient error, retry later");
|
|
149
|
+
} else if (err instanceof StigmerError) {
|
|
150
|
+
console.log(`Error [${err.code}]: ${err.message}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Error codes: `not-found`, `permission-denied`, `unauthenticated`, `invalid-argument`, `already-exists`, `resource-exhausted`, `failed-precondition`, `internal`, `unavailable`, `cancelled`, `unknown`.
|
|
156
|
+
|
|
157
|
+
## Transport Protocol
|
|
158
|
+
|
|
159
|
+
The SDK supports two transport protocols. Both are supported by the Stigmer server.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// gRPC-Web (default) — compact binary protocol
|
|
163
|
+
const stigmer = new Stigmer({
|
|
164
|
+
baseUrl: "https://api.stigmer.io",
|
|
165
|
+
apiKey: "sk_live_abc123",
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Connect protocol — HTTP/JSON, easier to debug with browser devtools
|
|
169
|
+
const stigmer = new Stigmer({
|
|
170
|
+
baseUrl: "https://api.stigmer.io",
|
|
171
|
+
apiKey: "sk_live_abc123",
|
|
172
|
+
transport: "connect",
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Configuration
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
interface StigmerConfig {
|
|
180
|
+
baseUrl: string;
|
|
181
|
+
apiKey?: string; // Static API key (mutually exclusive with getAccessToken)
|
|
182
|
+
getAccessToken?: () => string | null | Promise<string | null>; // Dynamic token provider
|
|
183
|
+
onUnauthenticated?: () => void; // Called once on UNAUTHENTICATED (code 16)
|
|
184
|
+
transport?: "grpc-web" | "connect"; // Default: "grpc-web"
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Exactly one of `apiKey` or `getAccessToken` must be provided.
|
|
189
|
+
|
|
190
|
+
## Code Generation
|
|
191
|
+
|
|
192
|
+
The resource clients in `src/gen/` are generated from protobuf service schemas. To regenerate after proto changes:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
cd sdk/typescript
|
|
196
|
+
make codegen
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Handwritten code lives in `src/` (outside `src/gen/`): `config.ts`, `transport.ts`, `stigmer.ts`, `search.ts`, `index.ts`, and `internal/`.
|
package/config.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
* Configuration for the Stigmer SDK client.
|
|
9
|
+
*
|
|
10
|
+
* Exactly one of `apiKey` or `getAccessToken` must be provided:
|
|
11
|
+
* - `apiKey`: Static API key for server-to-server usage.
|
|
12
|
+
* - `getAccessToken`: Dynamic token provider for browser or rotating credentials.
|
|
13
|
+
*/
|
|
14
|
+
export interface StigmerConfig {
|
|
15
|
+
/** Base URL of the Stigmer API server (e.g., "https://api.stigmer.io"). */
|
|
16
|
+
readonly baseUrl: string;
|
|
17
|
+
/** Static API key. Sent as `Authorization: Bearer <apiKey>` on every request. */
|
|
18
|
+
readonly apiKey?: string;
|
|
19
|
+
/** Dynamic token provider. Called per-request to obtain a Bearer token. */
|
|
20
|
+
readonly getAccessToken?: TokenProvider;
|
|
21
|
+
/**
|
|
22
|
+
* Called when the server returns UNAUTHENTICATED (code 16).
|
|
23
|
+
* Typically used to clear auth state and redirect to login.
|
|
24
|
+
* Invoked at most once per client instance to prevent cascading redirects.
|
|
25
|
+
*/
|
|
26
|
+
readonly onUnauthenticated?: () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Transport protocol to use for API communication.
|
|
29
|
+
* - `"grpc-web"` (default): gRPC-Web binary protocol. Compact, battle-tested.
|
|
30
|
+
* - `"connect"`: Connect protocol over HTTP/JSON. Easier to debug with standard HTTP tooling.
|
|
31
|
+
*
|
|
32
|
+
* Both protocols are supported by the Stigmer server.
|
|
33
|
+
*/
|
|
34
|
+
readonly transport?: "grpc-web" | "connect";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validate a StigmerConfig and throw a descriptive error for invalid configurations.
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateConfig(config: StigmerConfig): void;
|
|
40
|
+
//# sourceMappingURL=config.d.ts.map
|
package/config.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,2EAA2E;IAC3E,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC;IAExC;;;;OAIG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAExC;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CAC7C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAmB1D"}
|
package/config.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a StigmerConfig and throw a descriptive error for invalid configurations.
|
|
3
|
+
*/
|
|
4
|
+
export function validateConfig(config) {
|
|
5
|
+
if (!config.baseUrl) {
|
|
6
|
+
throw new Error("stigmer: baseUrl is required");
|
|
7
|
+
}
|
|
8
|
+
const hasApiKey = typeof config.apiKey === "string" && config.apiKey.length > 0;
|
|
9
|
+
const hasTokenProvider = typeof config.getAccessToken === "function";
|
|
10
|
+
if (!hasApiKey && !hasTokenProvider) {
|
|
11
|
+
throw new Error("stigmer: either apiKey or getAccessToken must be provided");
|
|
12
|
+
}
|
|
13
|
+
if (hasApiKey && hasTokenProvider) {
|
|
14
|
+
throw new Error("stigmer: apiKey and getAccessToken are mutually exclusive — provide one, not both");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=config.js.map
|
package/config.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAqB;IAClD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAChF,MAAM,gBAAgB,GAAG,OAAO,MAAM,CAAC,cAAc,KAAK,UAAU,CAAC;IAErE,IAAI,CAAC,SAAS,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,IAAI,gBAAgB,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/errors.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ConnectError } from "@connectrpc/connect";
|
|
2
|
+
export { StigmerError, type ErrorCode, wrapError, isNotFound, isUnauthenticated, isPermissionDenied, isRetryable, } from "./gen/errors";
|
|
3
|
+
/**
|
|
4
|
+
* Coarse-grained error categories derived from gRPC/Connect status codes.
|
|
5
|
+
* Each category maps to a distinct UX treatment:
|
|
6
|
+
*
|
|
7
|
+
* - `auth` — session expired or missing credentials (redirect to login)
|
|
8
|
+
* - `permission` — valid session but insufficient access (inline error)
|
|
9
|
+
* - `not-found` — requested resource does not exist (inline error)
|
|
10
|
+
* - `validation` — request rejected due to invalid input (inline / form error)
|
|
11
|
+
* - `server` — unexpected server failure (inline error with retry)
|
|
12
|
+
* - `unavailable` — server unreachable or overloaded (inline error with retry)
|
|
13
|
+
* - `cancelled` — request aborted, usually by the user (silent)
|
|
14
|
+
* - `unknown` — non-RPC error or unmapped code (inline error)
|
|
15
|
+
*/
|
|
16
|
+
export type ErrorCategory = "auth" | "permission" | "not-found" | "validation" | "server" | "unavailable" | "cancelled" | "unknown";
|
|
17
|
+
/**
|
|
18
|
+
* Narrow an unknown thrown value to {@link ConnectError}.
|
|
19
|
+
*
|
|
20
|
+
* Uses `ConnectError[Symbol.hasInstance]` which handles cross-package
|
|
21
|
+
* identity correctly (multiple copies of `@connectrpc/connect` in the
|
|
22
|
+
* dependency tree).
|
|
23
|
+
*/
|
|
24
|
+
export declare function isConnectError(error: unknown): error is ConnectError;
|
|
25
|
+
/**
|
|
26
|
+
* Map any thrown value to an {@link ErrorCategory}.
|
|
27
|
+
*
|
|
28
|
+
* Handles both {@link StigmerError} (thrown by SDK methods) and raw
|
|
29
|
+
* {@link ConnectError} (from direct transport usage). All other values
|
|
30
|
+
* are classified as `"unknown"`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function classifyError(error: unknown): ErrorCategory;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the error represents a transient failure worth retrying.
|
|
35
|
+
*
|
|
36
|
+
* Only `server` and `unavailable` categories are retryable. Auth, permission,
|
|
37
|
+
* not-found, and validation errors are deterministic — the same request
|
|
38
|
+
* will produce the same failure.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Extract a clean, user-appropriate error message from any thrown value.
|
|
43
|
+
*
|
|
44
|
+
* 1. For {@link StigmerError} or {@link ConnectError}, uses the raw message
|
|
45
|
+
* (which excludes the `[code]` prefix added by Connect-RPC).
|
|
46
|
+
* 2. Sanitizes infrastructure noise (e.g., "no healthy upstream") into
|
|
47
|
+
* readable text.
|
|
48
|
+
* 3. Falls back to a category-specific default when the raw message is
|
|
49
|
+
* empty or is infrastructure noise.
|
|
50
|
+
*
|
|
51
|
+
* @param error — the thrown value (typically from a catch block)
|
|
52
|
+
* @param fallback — optional override for the default fallback message
|
|
53
|
+
*/
|
|
54
|
+
export declare function getUserMessage(error: unknown, fallback?: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Metadata about the RPC call that produced an error. Attached by the
|
|
57
|
+
* SDK's metadata interceptor and readable via {@link getRpcMetadata}.
|
|
58
|
+
*/
|
|
59
|
+
export interface RpcErrorMetadata {
|
|
60
|
+
readonly method: string;
|
|
61
|
+
readonly path: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Attach RPC call metadata to an error object.
|
|
65
|
+
*
|
|
66
|
+
* Called by the metadata interceptor — application code should use
|
|
67
|
+
* {@link getRpcMetadata} to read metadata, not this function.
|
|
68
|
+
*
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export declare function annotateRpcError(error: object, metadata: RpcErrorMetadata): void;
|
|
72
|
+
/**
|
|
73
|
+
* Retrieve RPC metadata previously attached by the metadata interceptor.
|
|
74
|
+
* Returns `undefined` if the error was not annotated.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getRpcMetadata(error: unknown): RpcErrorMetadata | undefined;
|
|
77
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/errors.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAQ,MAAM,qBAAqB,CAAC;AAIzD,OAAO,EACL,YAAY,EACZ,KAAK,SAAS,EACd,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,GACZ,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,QAAQ,GACR,aAAa,GACb,WAAW,GACX,SAAS,CAAC;AAmCd;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAQ3D;AAOD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAExD;AAyBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAOxE;AA0BD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAID;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,gBAAgB,GACzB,IAAI,CAEN;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAK3E"}
|