sideagent 0.3.0 → 0.5.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/keys.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ type KeyEnvironment = "test" | "live";
2
+ interface PublishableKeyParts {
3
+ environment: KeyEnvironment;
4
+ /** host[:port], no scheme. */
5
+ host: string;
6
+ agentId: string;
7
+ }
8
+ /** Request header that carries the publishable key. Authorization stays free for the user's token. */
9
+ declare const PUBLISHABLE_KEY_HEADER = "x-sideagent-key";
10
+ declare function publishableKey(environment: KeyEnvironment, host: string, agentId: string): string;
11
+ /** The key's parts, or null when it is not a well-formed publishable key. */
12
+ declare function parsePublishableKey(key: string): PublishableKeyParts | null;
13
+ /** The agent's data-plane URL. https, except http for localhost and 127.0.0.1 (local development). */
14
+ declare function publishableEndpoint({ host, agentId }: PublishableKeyParts): string;
15
+
16
+ export { type KeyEnvironment, PUBLISHABLE_KEY_HEADER, type PublishableKeyParts, parsePublishableKey, publishableEndpoint, publishableKey };
package/dist/keys.js ADDED
@@ -0,0 +1,12 @@
1
+ import {
2
+ PUBLISHABLE_KEY_HEADER,
3
+ parsePublishableKey,
4
+ publishableEndpoint,
5
+ publishableKey
6
+ } from "./chunk-73FXXOAR.js";
7
+ export {
8
+ PUBLISHABLE_KEY_HEADER,
9
+ parsePublishableKey,
10
+ publishableEndpoint,
11
+ publishableKey
12
+ };
@@ -1,8 +1,12 @@
1
1
  import { ThreadMeta } from '../protocol.js';
2
2
  export { AgentEvent, ChatRequest } from '../protocol.js';
3
3
  import { z } from 'zod';
4
- import { BaseCheckpointSaver } from '@langchain/langgraph';
5
4
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
5
+ import { BaseStore, BaseCheckpointSaver } from '@langchain/langgraph';
6
+ import { Document } from '@langchain/core/documents';
7
+ import { EmbeddingsInterface } from '@langchain/core/embeddings';
8
+ import { VectorStore, VectorStoreInterface } from '@langchain/core/vectorstores';
9
+ export { VectorStoreInterface as VectorStore } from '@langchain/core/vectorstores';
6
10
 
7
11
  declare const configSchema: z.ZodObject<{
8
12
  spec: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
@@ -65,6 +69,46 @@ interface UrlGuardOptions {
65
69
  /** Throws unless `url` is safe to call under the pinned config. */
66
70
  declare function assertAllowedUrl(url: string, opts: UrlGuardOptions): URL;
67
71
 
72
+ interface ChunkMeta {
73
+ sourceId: string;
74
+ title: string;
75
+ /** Only set for sources that came from a URL listed in config. */
76
+ url?: string;
77
+ }
78
+ interface Hit {
79
+ text: string;
80
+ score: number;
81
+ meta: ChunkMeta;
82
+ }
83
+
84
+ /** Default store: cosine similarity over everything in process memory. */
85
+ declare class MemoryVectorStore extends VectorStore {
86
+ FilterType: object;
87
+ lc_namespace: string[];
88
+ private rows;
89
+ constructor(embeddings: EmbeddingsInterface);
90
+ _vectorstoreType(): string;
91
+ addVectors(vectors: number[][], documents: Document[], options?: {
92
+ ids?: string[];
93
+ }): Promise<string[]>;
94
+ addDocuments(documents: Document[], options?: {
95
+ ids?: string[];
96
+ }): Promise<string[]>;
97
+ delete(params?: {
98
+ ids?: string[];
99
+ }): Promise<void>;
100
+ similaritySearchVectorWithScore(query: number[], k: number): Promise<[Document, number][]>;
101
+ }
102
+
103
+ /** Splits markdown/plain text into chunks of at most about `size` chars, each prefixed with its nearest heading. */
104
+ declare function chunkText(content: string, size: number): Promise<string[]>;
105
+
106
+ /** HTML to text/markdown-ish conversion on a real parser. Plain text out; never HTML. */
107
+ declare function htmlToText(html: string): {
108
+ title?: string;
109
+ text: string;
110
+ };
111
+
68
112
  interface KnowledgeSourceInput {
69
113
  id: string;
70
114
  title: string;
@@ -83,39 +127,6 @@ interface KnowledgeOptions {
83
127
  maxChunks: number;
84
128
  chunkSize: number;
85
129
  }
86
- interface ChunkMeta {
87
- sourceId: string;
88
- title: string;
89
- /** Only set for sources that came from a URL listed in config. */
90
- url?: string;
91
- }
92
- interface StoredChunk {
93
- text: string;
94
- vector: number[];
95
- meta: ChunkMeta;
96
- }
97
- interface Hit {
98
- text: string;
99
- score: number;
100
- meta: ChunkMeta;
101
- }
102
- /** Plug in your own (pgvector, Vectorize, …). The default is an in-memory cosine store. */
103
- interface VectorStore {
104
- replace(sourceId: string, chunks: StoredChunk[]): Promise<void>;
105
- search(vector: number[], k: number): Promise<Hit[]>;
106
- }
107
- declare class MemoryVectorStore implements VectorStore {
108
- private bySource;
109
- replace(sourceId: string, chunks: StoredChunk[]): Promise<void>;
110
- search(vector: number[], k: number): Promise<Hit[]>;
111
- }
112
- /** Splits markdown/plain text into chunks of roughly `size` chars, keeping the nearest heading as context. */
113
- declare function chunkText(content: string, size: number): string[];
114
- /** Dependency-free HTML to text/markdown-ish conversion. Plain text out; never HTML. */
115
- declare function htmlToText(html: string): {
116
- title?: string;
117
- text: string;
118
- };
119
130
  interface SourceStatus {
120
131
  id: string;
121
132
  title: string;
@@ -127,7 +138,7 @@ interface SourceStatus {
127
138
  interface KnowledgeDeps {
128
139
  embedDocuments(texts: string[]): Promise<number[][]>;
129
140
  embedQuery(text: string): Promise<number[]>;
130
- store?: VectorStore;
141
+ store?: VectorStoreInterface;
131
142
  allowPrivateNetworks?: boolean;
132
143
  fetch?: typeof fetch;
133
144
  now?: () => number;
@@ -135,8 +146,10 @@ interface KnowledgeDeps {
135
146
  declare class KnowledgeBase {
136
147
  private opts;
137
148
  private deps;
138
- readonly store: VectorStore;
149
+ readonly store: VectorStoreInterface;
139
150
  private statuses;
151
+ /** Chunk ids currently stored per source, so a refresh can drop the ones that disappeared. */
152
+ private chunkIds;
140
153
  private refreshing;
141
154
  private lastRefresh;
142
155
  private totalChunks;
@@ -147,12 +160,33 @@ declare class KnowledgeBase {
147
160
  load(): Promise<void>;
148
161
  private loadUrls;
149
162
  private ingest;
150
- private fetchPage;
151
163
  /** Re-fetches URL sources. Keeps the old data for any source that fails. Concurrent calls share one run. */
152
164
  refresh(): Promise<void>;
153
165
  search(query: string): Promise<Hit[]>;
154
166
  }
155
167
 
168
+ interface DoctorReport {
169
+ ok: boolean;
170
+ checks: {
171
+ name: string;
172
+ ok: boolean;
173
+ detail: string;
174
+ }[];
175
+ tools: {
176
+ operationId: string;
177
+ method: string;
178
+ path: string;
179
+ approval: "required" | "auto";
180
+ }[];
181
+ knowledge?: {
182
+ id: string;
183
+ title: string;
184
+ url?: string;
185
+ chunks: number;
186
+ error?: string;
187
+ }[];
188
+ }
189
+
156
190
  interface AuditEvent {
157
191
  at: number;
158
192
  userId: string;
@@ -184,6 +218,20 @@ declare class MemoryThreadStore implements ThreadStore {
184
218
  touch(userId: string, threadId: string, title: string): Promise<void>;
185
219
  delete(userId: string, threadId: string): Promise<void>;
186
220
  }
221
+ /**
222
+ * Thread index on any LangGraph `BaseStore` (Postgres, Redis, …), so one store can serve the checkpointer
223
+ * ecosystem and the thread list. Keeps at most 200 threads per user, like `MemoryThreadStore`.
224
+ */
225
+ declare class LangGraphThreadStore implements ThreadStore {
226
+ private store;
227
+ constructor(store: BaseStore);
228
+ private ns;
229
+ private all;
230
+ list(userId: string): Promise<ThreadMeta[]>;
231
+ has(userId: string, threadId: string): Promise<boolean>;
232
+ touch(userId: string, threadId: string, title: string): Promise<void>;
233
+ delete(userId: string, threadId: string): Promise<void>;
234
+ }
187
235
 
188
236
  interface AuthResult {
189
237
  /** Stable identity of the signed-in user. Threads are bound to it. */
@@ -191,11 +239,13 @@ interface AuthResult {
191
239
  /** Headers forwarded to your API (e.g. Authorization, Cookie). Never shown to the LLM. */
192
240
  headers?: Record<string, string>;
193
241
  }
242
+
194
243
  /** Same shape as LangChain's Embeddings, minimal so any adapter fits. */
195
244
  interface EmbeddingsLike {
196
245
  embedDocuments(texts: string[]): Promise<number[][]>;
197
246
  embedQuery(text: string): Promise<number[]>;
198
247
  }
248
+
199
249
  interface CreateAgentOptions extends AgentConfigInput {
200
250
  /** Your own chat model (e.g. workersAiChatModel from sideagent/workers-ai). Use instead of `llm`, never with it. It must support bindTools(). */
201
251
  model?: BaseChatModel;
@@ -212,28 +262,7 @@ interface CreateAgentOptions extends AgentConfigInput {
212
262
  /** Index of each user's conversations (history list). Defaults to in-memory. */
213
263
  threadStore?: ThreadStore;
214
264
  /** Where knowledge embeddings live. Defaults to in-memory (re-embedded on every start). */
215
- vectorStore?: VectorStore;
216
- }
217
- interface DoctorReport {
218
- ok: boolean;
219
- checks: {
220
- name: string;
221
- ok: boolean;
222
- detail: string;
223
- }[];
224
- tools: {
225
- operationId: string;
226
- method: string;
227
- path: string;
228
- approval: "required" | "auto";
229
- }[];
230
- knowledge?: {
231
- id: string;
232
- title: string;
233
- url?: string;
234
- chunks: number;
235
- error?: string;
236
- }[];
265
+ vectorStore?: VectorStoreInterface;
237
266
  }
238
267
  declare function createAgent(options: CreateAgentOptions): Promise<{
239
268
  handler: (request: Request) => Promise<Response>;
@@ -257,4 +286,4 @@ declare function honoHandler(agent: Agent): (c: {
257
286
  /** Express (use express.json() before it): `app.post("/agent", expressHandler(agent))` and `app.options("/agent", expressHandler(agent))` */
258
287
  declare function expressHandler(agent: Agent): (req: any, res: any) => Promise<any>;
259
288
 
260
- export { type Agent, type AgentConfig, type AgentConfigInput, type AuditEvent, type AuthResult, type CreateAgentOptions, type DoctorReport, type EmbeddingsLike, KnowledgeBase, type KnowledgeSourceInput, MemoryThreadStore, MemoryVectorStore, type ThreadStore, type VectorStore, assertAllowedUrl, chunkText, configSchema, createAgent, expressHandler, honoHandler, htmlToText, nextRoute, parseConfig };
289
+ export { type Agent, type AgentConfig, type AgentConfigInput, type AuditEvent, type AuthResult, type CreateAgentOptions, type DoctorReport, type EmbeddingsLike, KnowledgeBase, type KnowledgeSourceInput, LangGraphThreadStore, MemoryThreadStore, MemoryVectorStore, type ThreadStore, assertAllowedUrl, chunkText, configSchema, createAgent, expressHandler, honoHandler, htmlToText, nextRoute, parseConfig };