@slashfi/agents-sdk 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{auth.d.ts → agent-definitions/auth.d.ts} +36 -2
- package/dist/agent-definitions/auth.d.ts.map +1 -0
- package/dist/{auth.js → agent-definitions/auth.js} +69 -8
- package/dist/agent-definitions/auth.js.map +1 -0
- package/dist/agent-definitions/integrations.d.ts +162 -0
- package/dist/agent-definitions/integrations.d.ts.map +1 -0
- package/dist/agent-definitions/integrations.js +861 -0
- package/dist/agent-definitions/integrations.js.map +1 -0
- package/dist/agent-definitions/secrets.d.ts +51 -0
- package/dist/agent-definitions/secrets.d.ts.map +1 -0
- package/dist/agent-definitions/secrets.js +165 -0
- package/dist/agent-definitions/secrets.js.map +1 -0
- package/dist/agent-definitions/users.d.ts +80 -0
- package/dist/agent-definitions/users.d.ts.map +1 -0
- package/dist/agent-definitions/users.js +397 -0
- package/dist/agent-definitions/users.js.map +1 -0
- package/dist/crypto.d.ts +14 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +40 -0
- package/dist/crypto.js.map +1 -0
- package/dist/define.d.ts +6 -1
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +1 -0
- package/dist/define.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/jwt.d.ts +2 -0
- package/dist/jwt.d.ts.map +1 -1
- package/dist/jwt.js.map +1 -1
- package/dist/server.d.ts +28 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +478 -27
- package/dist/server.js.map +1 -1
- package/dist/slack-oauth.d.ts +27 -0
- package/dist/slack-oauth.d.ts.map +1 -0
- package/dist/slack-oauth.js +48 -0
- package/dist/slack-oauth.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/web-pages.d.ts +8 -0
- package/dist/web-pages.d.ts.map +1 -0
- package/dist/web-pages.js +169 -0
- package/dist/web-pages.js.map +1 -0
- package/package.json +2 -1
- package/src/{auth.ts → agent-definitions/auth.ts} +134 -15
- package/src/agent-definitions/integrations.ts +1209 -0
- package/src/agent-definitions/secrets.ts +241 -0
- package/src/agent-definitions/users.ts +533 -0
- package/src/crypto.ts +71 -0
- package/src/define.ts +8 -0
- package/src/index.ts +62 -4
- package/src/jwt.ts +9 -5
- package/src/server.ts +567 -35
- package/src/slack-oauth.ts +66 -0
- package/src/types.ts +83 -0
- package/src/web-pages.ts +178 -0
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js.map +0 -1
- package/dist/secrets.d.ts +0 -44
- package/dist/secrets.d.ts.map +0 -1
- package/dist/secrets.js +0 -106
- package/dist/secrets.js.map +0 -1
- package/src/secrets.ts +0 -154
package/src/secrets.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Secrets - encrypted secret storage and resolution for tool params.
|
|
3
|
-
*
|
|
4
|
-
* Secrets are stored encrypted and referenced via `secret:<id>` strings.
|
|
5
|
-
* The SDK automatically:
|
|
6
|
-
* - Resolves `secret:xxx` refs in tool params before execution
|
|
7
|
-
* - Stores raw values in `secret: true` schema fields and replaces with refs
|
|
8
|
-
* - Redacts secrets from tool results in LLM context
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// ============================================
|
|
13
|
-
// SecretStore Interface
|
|
14
|
-
// ============================================
|
|
15
|
-
|
|
16
|
-
export interface SecretStore {
|
|
17
|
-
/** Store a secret value. Returns the secret ref (e.g., "secret:abc123"). */
|
|
18
|
-
store(value: string, ownerId: string): Promise<string>;
|
|
19
|
-
|
|
20
|
-
/** Resolve a secret ref to its value. Returns null if not found or unauthorized. */
|
|
21
|
-
resolve(ref: string, ownerId: string): Promise<string | null>;
|
|
22
|
-
|
|
23
|
-
/** Delete a secret. */
|
|
24
|
-
delete(ref: string, ownerId: string): Promise<boolean>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// ============================================
|
|
28
|
-
// Secret Ref Helpers
|
|
29
|
-
// ============================================
|
|
30
|
-
|
|
31
|
-
const SECRET_PREFIX = "secret:";
|
|
32
|
-
|
|
33
|
-
export function isSecretRef(value: unknown): value is string {
|
|
34
|
-
return typeof value === "string" && value.startsWith(SECRET_PREFIX);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function getSecretId(ref: string): string {
|
|
38
|
-
return ref.slice(SECRET_PREFIX.length);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function makeSecretRef(id: string): string {
|
|
42
|
-
return `${SECRET_PREFIX}${id}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function randomSecretId(): string {
|
|
46
|
-
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
47
|
-
let id = "";
|
|
48
|
-
for (let i = 0; i < 24; i++) id += chars[Math.floor(Math.random() * chars.length)];
|
|
49
|
-
return id;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// ============================================
|
|
53
|
-
// In-Memory SecretStore (default)
|
|
54
|
-
// ============================================
|
|
55
|
-
|
|
56
|
-
export function createInMemorySecretStore(): SecretStore {
|
|
57
|
-
const secrets = new Map<string, { value: string; ownerId: string }>();
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
async store(value, ownerId) {
|
|
61
|
-
const id = randomSecretId();
|
|
62
|
-
secrets.set(id, { value, ownerId });
|
|
63
|
-
return makeSecretRef(id);
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
async resolve(ref, ownerId) {
|
|
67
|
-
const id = getSecretId(ref);
|
|
68
|
-
const entry = secrets.get(id);
|
|
69
|
-
if (!entry || entry.ownerId !== ownerId) return null;
|
|
70
|
-
return entry.value;
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
async delete(ref, ownerId) {
|
|
74
|
-
const id = getSecretId(ref);
|
|
75
|
-
const entry = secrets.get(id);
|
|
76
|
-
if (!entry || entry.ownerId !== ownerId) return false;
|
|
77
|
-
secrets.delete(id);
|
|
78
|
-
return true;
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ============================================
|
|
84
|
-
// Param Resolution
|
|
85
|
-
// ============================================
|
|
86
|
-
|
|
87
|
-
interface SchemaProperty {
|
|
88
|
-
type?: string;
|
|
89
|
-
secret?: boolean;
|
|
90
|
-
properties?: Record<string, SchemaProperty>;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Walk tool params, resolve `secret:xxx` refs and store raw secret values.
|
|
95
|
-
*
|
|
96
|
-
* - If a param value is `secret:xxx`, resolve it from the store.
|
|
97
|
-
* - If a param has `secret: true` in schema and value is a raw string,
|
|
98
|
-
* store it and replace with a ref (for logging/context).
|
|
99
|
-
*
|
|
100
|
-
* Returns: { resolved: params with real values for tool execution,
|
|
101
|
-
* redacted: params with refs for logging }
|
|
102
|
-
*/
|
|
103
|
-
export async function processSecretParams(
|
|
104
|
-
params: Record<string, unknown>,
|
|
105
|
-
schema: { properties?: Record<string, SchemaProperty> } | undefined,
|
|
106
|
-
secretStore: SecretStore,
|
|
107
|
-
ownerId: string,
|
|
108
|
-
): Promise<{ resolved: Record<string, unknown>; redacted: Record<string, unknown> }> {
|
|
109
|
-
const resolved: Record<string, unknown> = { ...params };
|
|
110
|
-
const redacted: Record<string, unknown> = { ...params };
|
|
111
|
-
|
|
112
|
-
if (!schema?.properties) return { resolved, redacted };
|
|
113
|
-
|
|
114
|
-
for (const [key, schemaProp] of Object.entries(schema.properties)) {
|
|
115
|
-
const value = params[key];
|
|
116
|
-
if (value === undefined || value === null) continue;
|
|
117
|
-
|
|
118
|
-
// Recurse into nested objects
|
|
119
|
-
if (schemaProp.type === "object" && typeof value === "object" && !Array.isArray(value)) {
|
|
120
|
-
const nested = await processSecretParams(
|
|
121
|
-
value as Record<string, unknown>,
|
|
122
|
-
schemaProp,
|
|
123
|
-
secretStore,
|
|
124
|
-
ownerId,
|
|
125
|
-
);
|
|
126
|
-
resolved[key] = nested.resolved;
|
|
127
|
-
redacted[key] = nested.redacted;
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (typeof value !== "string") continue;
|
|
132
|
-
|
|
133
|
-
// Case 1: Value is already a secret ref - resolve it
|
|
134
|
-
if (isSecretRef(value)) {
|
|
135
|
-
const realValue = await secretStore.resolve(value, ownerId);
|
|
136
|
-
if (realValue === null) {
|
|
137
|
-
throw new Error(`Secret not found or unauthorized: ${value}`);
|
|
138
|
-
}
|
|
139
|
-
resolved[key] = realValue;
|
|
140
|
-
redacted[key] = value; // keep the ref in redacted version
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Case 2: Schema says this field is secret + value is raw - store it
|
|
145
|
-
if (schemaProp.secret && (value as string).length > 0) {
|
|
146
|
-
const ref = await secretStore.store(value, ownerId);
|
|
147
|
-
resolved[key] = value; // tool gets the real value
|
|
148
|
-
redacted[key] = ref; // logs/context get the ref
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return { resolved, redacted };
|
|
154
|
-
}
|