@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.
Files changed (65) hide show
  1. package/dist/{auth.d.ts → agent-definitions/auth.d.ts} +36 -2
  2. package/dist/agent-definitions/auth.d.ts.map +1 -0
  3. package/dist/{auth.js → agent-definitions/auth.js} +69 -8
  4. package/dist/agent-definitions/auth.js.map +1 -0
  5. package/dist/agent-definitions/integrations.d.ts +162 -0
  6. package/dist/agent-definitions/integrations.d.ts.map +1 -0
  7. package/dist/agent-definitions/integrations.js +861 -0
  8. package/dist/agent-definitions/integrations.js.map +1 -0
  9. package/dist/agent-definitions/secrets.d.ts +51 -0
  10. package/dist/agent-definitions/secrets.d.ts.map +1 -0
  11. package/dist/agent-definitions/secrets.js +165 -0
  12. package/dist/agent-definitions/secrets.js.map +1 -0
  13. package/dist/agent-definitions/users.d.ts +80 -0
  14. package/dist/agent-definitions/users.d.ts.map +1 -0
  15. package/dist/agent-definitions/users.js +397 -0
  16. package/dist/agent-definitions/users.js.map +1 -0
  17. package/dist/crypto.d.ts +14 -0
  18. package/dist/crypto.d.ts.map +1 -0
  19. package/dist/crypto.js +40 -0
  20. package/dist/crypto.js.map +1 -0
  21. package/dist/define.d.ts +6 -1
  22. package/dist/define.d.ts.map +1 -1
  23. package/dist/define.js +1 -0
  24. package/dist/define.js.map +1 -1
  25. package/dist/index.d.ts +10 -5
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +9 -2
  28. package/dist/index.js.map +1 -1
  29. package/dist/jwt.d.ts +2 -0
  30. package/dist/jwt.d.ts.map +1 -1
  31. package/dist/jwt.js.map +1 -1
  32. package/dist/server.d.ts +28 -1
  33. package/dist/server.d.ts.map +1 -1
  34. package/dist/server.js +478 -27
  35. package/dist/server.js.map +1 -1
  36. package/dist/slack-oauth.d.ts +27 -0
  37. package/dist/slack-oauth.d.ts.map +1 -0
  38. package/dist/slack-oauth.js +48 -0
  39. package/dist/slack-oauth.js.map +1 -0
  40. package/dist/types.d.ts +66 -0
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/web-pages.d.ts +8 -0
  43. package/dist/web-pages.d.ts.map +1 -0
  44. package/dist/web-pages.js +169 -0
  45. package/dist/web-pages.js.map +1 -0
  46. package/package.json +2 -1
  47. package/src/{auth.ts → agent-definitions/auth.ts} +134 -15
  48. package/src/agent-definitions/integrations.ts +1209 -0
  49. package/src/agent-definitions/secrets.ts +241 -0
  50. package/src/agent-definitions/users.ts +533 -0
  51. package/src/crypto.ts +71 -0
  52. package/src/define.ts +8 -0
  53. package/src/index.ts +62 -4
  54. package/src/jwt.ts +9 -5
  55. package/src/server.ts +567 -35
  56. package/src/slack-oauth.ts +66 -0
  57. package/src/types.ts +83 -0
  58. package/src/web-pages.ts +178 -0
  59. package/dist/auth.d.ts.map +0 -1
  60. package/dist/auth.js.map +0 -1
  61. package/dist/secrets.d.ts +0 -44
  62. package/dist/secrets.d.ts.map +0 -1
  63. package/dist/secrets.js +0 -106
  64. package/dist/secrets.js.map +0 -1
  65. 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
- }