@felspar/sdk 0.1.1 → 0.2.1
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/README.md +68 -34
- package/bin/felspar-sdk.mjs +10 -0
- package/bin/skill.mjs +33 -0
- package/dist/chunks/chunk-B4BWUYQY.js +53 -0
- package/dist/chunks/{chunk-C2VMKF3S.js → chunk-XLKRU5RA.js} +1190 -829
- package/dist/chunks/chunk-Y6KRRIQI.js +908 -0
- package/dist/draft-action-gate-claude.js +7 -6
- package/dist/draft-action-gate-eve.js +5 -48
- package/dist/draft-action-gate-openai.js +7 -6
- package/dist/draft-action-gate.js +6 -2
- package/dist/draft-hosted-client.js +1 -1
- package/dist/eve.js +53 -0
- package/dist/types/draft-action-gate-cases.d.ts +31 -0
- package/dist/types/draft-action-gate-decisions.d.ts +33 -3
- package/dist/types/draft-action-gate-describe.d.ts +81 -0
- package/dist/types/draft-action-gate-rules.d.ts +15 -0
- package/dist/types/draft-action-gate-subject.d.ts +33 -0
- package/dist/types/draft-action-gate.d.ts +17 -11
- package/dist/types/draft-hosted-client.d.ts +427 -30
- package/dist/types/eve.d.ts +22 -0
- package/package.json +10 -1
- package/skills/felspar/SKILL.md +128 -0
- package/dist/chunks/chunk-6EZBI7O6.js +0 -583
package/README.md
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
# @felspar/sdk
|
|
2
2
|
|
|
3
|
-
Felspar is a shared, versioned decision system for enterprise agents. A
|
|
4
|
-
company's approved meaning, the evidence a decision needs and the decision
|
|
5
|
-
itself travel together in a released Decision Pack. Agents ask Felspar for a
|
|
6
|
-
decision, get a receipt they can verify, and act only on what Felspar decided.
|
|
3
|
+
Felspar is a shared, versioned decision system for enterprise agents. A company's approved meaning, the evidence a decision needs and the decision itself travel together in a released Decision Pack. Agents ask Felspar for a decision, get a receipt they can verify, and act only on what Felspar decided.
|
|
7
4
|
|
|
8
|
-
This package
|
|
9
|
-
gate that keeps an agent's tools from acting without a verified Felspar
|
|
10
|
-
decision. It runs on Node.js 24 or later, and its only dependency is `zod`.
|
|
11
|
-
The SDK is a transport client: decisions and policy stay with the Felspar
|
|
12
|
-
service, and the SDK does not reimplement them.
|
|
5
|
+
This package connects an agent to Felspar: an [Eve](https://github.com/vercel/eve) connection in two lines, a TypeScript client for the hosted Felspar API, an action gate that keeps an agent's tools from acting without a verified Felspar decision, and the agent skill for running any Felspar job. It runs on Node.js 24 or later, and its only dependency is `zod`. The SDK is a transport client: decisions and policy stay with the Felspar service and the released pack, and the SDK does not reimplement them.
|
|
13
6
|
|
|
14
|
-
The modules
|
|
15
|
-
minor versions before 1.0.
|
|
7
|
+
The modules under `draft/` may change between minor versions while the API settles, before 1.0.
|
|
16
8
|
|
|
17
9
|
## Install
|
|
18
10
|
|
|
@@ -20,6 +12,18 @@ minor versions before 1.0.
|
|
|
20
12
|
npm install @felspar/sdk
|
|
21
13
|
```
|
|
22
14
|
|
|
15
|
+
## Connect an Eve agent
|
|
16
|
+
|
|
17
|
+
In `agent/connections/felspar.ts`:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineMcpClientConnection } from "eve/connections";
|
|
21
|
+
import { felsparConnection } from "@felspar/sdk/eve";
|
|
22
|
+
export default defineMcpClientConnection(felsparConnection());
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The agent gets Felspar's `list_jobs`, `get_job_requirements`, `get_job_decision` and `check_output` tools and nothing else. The key is the agent's own, created on the Felspar web page (Workspace → Agents) and read from `FELSPAR_AGENT_KEY` when Eve connects; the endpoint is `FELSPAR_MCP_URL`, or production. Pass `{ url, agentKey, description }` to override them. Add the skill (below) so the agent knows the method.
|
|
26
|
+
|
|
23
27
|
## Hosted client
|
|
24
28
|
|
|
25
29
|
```ts
|
|
@@ -30,7 +34,7 @@ const felspar = createHostedFelsparClient({
|
|
|
30
34
|
agentKey: process.env.FELSPAR_AGENT_KEY,
|
|
31
35
|
});
|
|
32
36
|
|
|
33
|
-
// What the job needs: questions, evidence rules and
|
|
37
|
+
// What the job needs: questions, evidence rules, outcomes and their outputs.
|
|
34
38
|
const job = await felspar.describeJob(releaseId, "classify-prospect");
|
|
35
39
|
|
|
36
40
|
// Facts in, decision out. The release pin comes from the job description.
|
|
@@ -49,45 +53,67 @@ const response = await felspar.resolveFacts(releaseId, {
|
|
|
49
53
|
if (response.status === "ready") {
|
|
50
54
|
console.log(response.result?.outcome, response.result?.receipt);
|
|
51
55
|
}
|
|
56
|
+
|
|
57
|
+
// The jobs this agent key may run, by ID.
|
|
58
|
+
const { jobs } = await felspar.listJobs();
|
|
52
59
|
```
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
How a case is identified comes from the job's description (`identity`): send `entityId` for the record's own ID (`provided`), `identity` field values (`fields`), or nothing (`content`, and the first decision of an `issued` job). The result's `case` gives the case's `id` and `mode`; send `case.id` as `entityId` for every later decision on the same case. Results are typed (`FelsparJobResult`): `case`, `subject` with its `related` records, `escalation` (`id`, `trigger`, `why`) and `missing` for a gap.
|
|
62
|
+
|
|
63
|
+
A refused request throws `FelsparRequestError` with the HTTP `status` and the service's `refusal` (its `error` code, where there is one a `fix`, and any `escalation` it names, such as for `attempt_limit_reached`).
|
|
56
64
|
|
|
57
65
|
## Action gate
|
|
58
66
|
|
|
59
|
-
The gate sits in front of a tool that acts, such as writing an email draft. It
|
|
60
|
-
allows a call only when the call's fields are allowed, every recipient belongs
|
|
61
|
-
to a company Felspar decided on in this session, Felspar re-verifies that
|
|
62
|
-
decision's receipt, and the decided outcome allows the tool. Any error denies.
|
|
67
|
+
The gate sits in front of a tool that acts, such as writing an email draft or replying to a ticket. It allows a call only when the call's fields are allowed, the call is about a case Felspar decided on in this session, Felspar re-verifies that decision's receipt, and the decided outcome permits the tool. Any error, and anything unknown or ambiguous, denies.
|
|
63
68
|
|
|
64
69
|
```ts
|
|
65
|
-
import {
|
|
70
|
+
import {
|
|
71
|
+
createActionGate,
|
|
72
|
+
felsparJobDescriber,
|
|
73
|
+
felsparOutputCheckVerifier,
|
|
74
|
+
felsparVerifier,
|
|
75
|
+
} from "@felspar/sdk/draft/action-gate";
|
|
66
76
|
|
|
77
|
+
const felspar = { origin: "https://api.felspar.ai", agentKey };
|
|
67
78
|
const gate = createActionGate({
|
|
68
|
-
job: "
|
|
69
|
-
decisionTool: "felspar__get_job_decision", // exact tool
|
|
79
|
+
job: "route-support-ticket",
|
|
80
|
+
decisionTool: "felspar__get_job_decision", // exact tool names in your runtime
|
|
81
|
+
outputCheckTool: "felspar__check_output",
|
|
70
82
|
tools: {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
helpdesk__reply: {
|
|
84
|
+
writes: "billing-team-reply",
|
|
85
|
+
entity: { field: "ticketId" },
|
|
86
|
+
fields: ["ticketId", "body"],
|
|
87
|
+
outputCheck: { fields: ["body"] },
|
|
74
88
|
},
|
|
75
89
|
},
|
|
76
|
-
verify: felsparVerifier(
|
|
90
|
+
verify: felsparVerifier(felspar),
|
|
91
|
+
describe: felsparJobDescriber(felspar),
|
|
92
|
+
verifyOutputCheck: felsparOutputCheckVerifier(felspar),
|
|
77
93
|
});
|
|
78
94
|
```
|
|
79
95
|
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
What a tool may do comes from the released pack, not from the gate's config:
|
|
97
|
+
|
|
98
|
+
- `writes` names the output the tool writes, by its id in the pack. The call is allowed only when the released job description lists that output under the outcome Felspar's replay reports. (A rule may give `outcomes`, a list of outcome ids, instead; exactly one of the two.)
|
|
99
|
+
- Which case a call is about comes from the released job's subject and identity. A decision is recorded by the `case.id` Felspar's result names (so an agent that sends no `entity_id`, for an issued, fields or content job, still gets one), and Felspar's replay must name the same case ID and mode. By default:
|
|
100
|
+
- for a job whose subject is a provided, case-insensitive ID such as a web domain (or a release with no subject), every recipient's email domain must belong to the one company Felspar decided on; a decided ID that isn't a company domain allows no recipient, so give such a rule an entity field;
|
|
101
|
+
- for any other job, the call is about the one case decided in the session for this job; with several, the call is denied until the rule names a field.
|
|
102
|
+
- `entity: { field }` overrides that: the input field must hold the case's ID, the record's own ID (such as a ticket ID) or the `case.id` Felspar issued or derived, trimmed and matched by the subject's match rule (exact unless the subject is case-insensitive; with no subject, `HC-1201` and `hc-1201` are two cases). Recipients are then not tied to the case, so a tool that can address anyone should also limit them (`testRecipients`, or the tool's own settings).
|
|
103
|
+
- `outputCheck` requires that Felspar passed exactly the text the call sends for that decision (`check_output`); with `writes`, for that output.
|
|
104
|
+
|
|
105
|
+
A denial is `{ allow: false, reason, escalate?, escalation? }`. `escalate` is the company's next step, quoted from the released description: the outcome's next step when the outcome doesn't permit the tool, or what to do when nothing is decided. For a missing or failed output check it is the fixed instruction to fix what `check_output` flagged and check again. `escalation` is the hand-off the policy names: `{ id, trigger, why }`, with the id from Felspar's replay of the outcome (or the job's unresolved path) and `why` quoted from the release. Both are absent when the release doesn't say. Every adapter below shows them to the model with the reason.
|
|
106
|
+
|
|
107
|
+
Then connect the gate to your agent framework. Tool names must match exactly as the runtime reports them.
|
|
82
108
|
|
|
83
109
|
### Eve
|
|
84
110
|
|
|
85
111
|
```ts
|
|
86
|
-
import { felsparDecisionEvents, felsparGate } from "@felspar/sdk/
|
|
112
|
+
import { felsparDecisionEvents, felsparGate } from "@felspar/sdk/eve";
|
|
87
113
|
|
|
88
114
|
// On the connection whose tools act:
|
|
89
115
|
approval: felsparGate(gate),
|
|
90
|
-
// And in a hook that records Felspar's decisions:
|
|
116
|
+
// And in a hook that records Felspar's decisions and output checks:
|
|
91
117
|
export default defineHook({ events: felsparDecisionEvents(gate) });
|
|
92
118
|
```
|
|
93
119
|
|
|
@@ -118,12 +144,20 @@ toolInputGuardrails: [felsparToolInputGuardrail(gate, { sessionOf })],
|
|
|
118
144
|
toolOutputGuardrails: [felsparDecisionOutputGuardrail(gate, { sessionOf })],
|
|
119
145
|
```
|
|
120
146
|
|
|
121
|
-
Outside an agent framework, `checkAction({ rules, toolName, input, decisions, verify })`
|
|
122
|
-
|
|
147
|
+
Outside an agent framework, `checkAction({ rules, toolName, input, decisions, verify, describe })` returns the same verdict.
|
|
148
|
+
|
|
149
|
+
A Felspar receipt records what Felspar decided from the evidence it was given. It is not a factual, legal or security certification, and a passed output check means the text follows the released rules, not that it is true or approved to send.
|
|
150
|
+
|
|
151
|
+
## Agent skill
|
|
152
|
+
|
|
153
|
+
The package ships the skill that teaches an agent the method for any Felspar job: get the requirements, gather exact evidence, get the decision, write and check what the decision asks for, and escalate with the company's next step.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npx @felspar/sdk skill # writes agent/skills/felspar/SKILL.md
|
|
157
|
+
npx @felspar/sdk skill .claude --force
|
|
158
|
+
```
|
|
123
159
|
|
|
124
|
-
|
|
125
|
-
It is not a factual, legal or security certification, and the gate checks
|
|
126
|
-
fields, recipients and the decision, not what the tool writes.
|
|
160
|
+
The directory defaults to `agent`, where an Eve agent keeps its skills; an existing copy is kept unless you pass `--force`.
|
|
127
161
|
|
|
128
162
|
## Documentation
|
|
129
163
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The package's command line: `npx @felspar/sdk skill [dir] [--force]`.
|
|
3
|
+
import { main } from "./skill.mjs";
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
console.log(`Wrote ${main(process.argv.slice(2))}`);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
console.error(error.message);
|
|
9
|
+
process.exitCode = 1;
|
|
10
|
+
}
|
package/bin/skill.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// `npx @felspar/sdk skill [dir] [--force]` copies Felspar's agent skill, the
|
|
2
|
+
// method for running any Felspar job, to <dir>/skills/felspar/SKILL.md. The
|
|
3
|
+
// directory defaults to agent, where an Eve agent keeps its skills.
|
|
4
|
+
import { constants, copyFileSync, mkdirSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
export const skillSource = path.join(import.meta.dirname, "../skills/felspar/SKILL.md");
|
|
8
|
+
const usage = "usage: npx @felspar/sdk skill [dir] [--force]";
|
|
9
|
+
|
|
10
|
+
// Copies the skill and returns where it went. Without force an existing file
|
|
11
|
+
// is kept: COPYFILE_EXCL fails on any existing path, a dangling link included.
|
|
12
|
+
export function installSkill(directory = "agent", { force = false } = {}) {
|
|
13
|
+
const target = path.join(directory, "skills", "felspar", "SKILL.md");
|
|
14
|
+
const mode = force ? 0 : constants.COPYFILE_EXCL;
|
|
15
|
+
mkdirSync(path.dirname(target), { recursive: true });
|
|
16
|
+
try {
|
|
17
|
+
copyFileSync(skillSource, target, mode);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw error.code === "EEXIST"
|
|
20
|
+
? new Error(`${target} exists; pass --force to replace it`, { cause: error })
|
|
21
|
+
: error;
|
|
22
|
+
}
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function main(argv) {
|
|
27
|
+
const force = argv.includes("--force");
|
|
28
|
+
const [command, directory, ...rest] = argv.filter((argument) => argument !== "--force");
|
|
29
|
+
if (command !== "skill" || rest.length > 0 || directory?.startsWith("-")) {
|
|
30
|
+
throw new Error(usage);
|
|
31
|
+
}
|
|
32
|
+
return installSkill(directory, { force });
|
|
33
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
denialText,
|
|
3
|
+
entityIdOf,
|
|
4
|
+
jobOf
|
|
5
|
+
} from "./chunk-Y6KRRIQI.js";
|
|
6
|
+
|
|
7
|
+
// src/draft-action-gate-eve.ts
|
|
8
|
+
function felsparGate(gate) {
|
|
9
|
+
return async (call) => {
|
|
10
|
+
if (!gate.isGated(call.toolName)) {
|
|
11
|
+
return "not-applicable";
|
|
12
|
+
}
|
|
13
|
+
const verdict = await gate.check(call.session.id, call.toolName, call.toolInput);
|
|
14
|
+
return verdict.allow ? { type: "approved", reason: verdict.reason } : { type: "denied", reason: denialText(verdict) };
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function felsparDecisionEvents(gate) {
|
|
18
|
+
const checks = /* @__PURE__ */ new Map();
|
|
19
|
+
function requested(event) {
|
|
20
|
+
const { actions } = event.data;
|
|
21
|
+
if (actions === void 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
for (const action of actions) {
|
|
25
|
+
const job = jobOf(action.input);
|
|
26
|
+
if (gate.isDecisionTool(action.toolName ?? "")) {
|
|
27
|
+
gate.decisions.noteRequest(action.callId, { entity: entityIdOf(action.input), job });
|
|
28
|
+
}
|
|
29
|
+
if (job !== void 0 && gate.isOutputCheckTool(action.toolName ?? "")) {
|
|
30
|
+
checks.set(action.callId, job);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function result(event, context) {
|
|
35
|
+
const action = event.data.result;
|
|
36
|
+
const job = action?.callId === void 0 ? void 0 : checks.get(action.callId);
|
|
37
|
+
if (job !== void 0 && action?.callId !== void 0) {
|
|
38
|
+
checks.delete(action.callId);
|
|
39
|
+
if (action.isError !== true) {
|
|
40
|
+
gate.decisions.recordOutputCheck(context.session.id, job, action.output);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (action?.callId !== void 0 && gate.isDecisionTool(action.toolName ?? "") && action.isError !== true) {
|
|
44
|
+
gate.decisions.noteResult(context.session.id, action.callId, action.output);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { "actions.requested": requested, "action.result": result };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
felsparGate,
|
|
52
|
+
felsparDecisionEvents
|
|
53
|
+
};
|