@promptev/client 1.2.0 → 1.3.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.
@@ -12,7 +12,7 @@
12
12
  * - `uploadDocument()` — put files into the key's project corpus.
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.PromptevClient = exports.NetworkError = exports.ServerError = exports.InsufficientCreditsError = exports.RateLimitError = exports.NotFoundError = exports.AuthenticationError = exports.ValidationError = exports.PromptevError = exports.MAX_FILES_PER_RUN = exports.MAX_UPLOAD_BYTES = exports.MAX_FILES_PER_REQUEST = exports.MAX_MESSAGE_CHARS = exports.DEFAULT_BASE_URL = void 0;
15
+ exports.PromptevClient = exports.NetworkError = exports.ServerError = exports.InsufficientCreditsError = exports.RateLimitError = exports.NotFoundError = exports.AuthenticationError = exports.ValidationError = exports.PromptevError = exports.KNOWLEDGE_ACTIONS = exports.MAX_FILES_PER_RUN = exports.MAX_UPLOAD_BYTES = exports.MAX_FILES_PER_REQUEST = exports.MAX_MESSAGE_CHARS = exports.DEFAULT_BASE_URL = void 0;
16
16
  // ── Configuration ───────────────────────────────────────
17
17
  /**
18
18
  * The default host. NOT `api.promptev.ai` — that host still serves the
@@ -39,6 +39,13 @@ exports.MAX_UPLOAD_BYTES = 25 * 1024 * 1024;
39
39
  /** Files ONE orchestration run may carry — the same ceiling a chat turn has.
40
40
  * Server-side: `run_inputs.MAX_FILE_PARTS`. */
41
41
  exports.MAX_FILES_PER_RUN = 5;
42
+ /** The knowledge base's actions, as the project MCP's `search_knowledge_base`
43
+ * offers them. Informational: the server decides, so an action added there
44
+ * works here without a new SDK. */
45
+ exports.KNOWLEDGE_ACTIONS = [
46
+ "discover", "search", "get_doc", "list", "query_meta", "compute", "get_chunks",
47
+ "get_docs", "map_reduce", "traverse", "find_related", "get_neighbors", "community_summary",
48
+ ];
42
49
  // ── Errors ──────────────────────────────────────────────
43
50
  class PromptevError extends Error {
44
51
  constructor(message, statusCode, responseText, field) {
@@ -459,6 +466,43 @@ class PromptevClient {
459
466
  * );
460
467
  * ```
461
468
  */
469
+ /**
470
+ * Read the key's project knowledge base through the Context Engine: the
471
+ * same tool, with the same actions, as `search_knowledge_base` on the
472
+ * project's MCP server (`POST /api/v1/knowledge`).
473
+ *
474
+ * ```ts
475
+ * const overview = await client.searchKnowledgeBase("discover");
476
+ * const found = await client.searchKnowledgeBase("search", { query: "how many days do customers have to ask for a refund", top_k: 5 });
477
+ * for (const hit of found.hits) console.log(hit.document_name, hit.chunk_text);
478
+ * const doc = await client.searchKnowledgeBase("get_doc", { document_id: found.hits[0].document_id });
479
+ * ```
480
+ *
481
+ * `fields` are that action's fields (`query`, `top_k`, `document_id`,
482
+ * `source_ids`, `mode`, `limit`, `cursor`, ...); undefined and null ones
483
+ * are not sent. Returns the knowledge base's answer as an object.
484
+ */
485
+ async searchKnowledgeBase(action, fields = {}, options) {
486
+ if (typeof action !== "string" || !action.trim()) {
487
+ throw new ValidationError('Name the action, e.g. "search".', undefined, undefined, "action");
488
+ }
489
+ const body = { action: action.trim() };
490
+ for (const [key, value] of Object.entries(fields ?? {})) {
491
+ if (value !== undefined && value !== null)
492
+ body[key] = value;
493
+ }
494
+ const headers = this.authHeaders();
495
+ headers["Content-Type"] = "application/json";
496
+ const resp = await this.fetchWithRetry(`${this.baseUrl}/api/v1/knowledge`, {
497
+ method: "POST",
498
+ headers,
499
+ body: JSON.stringify(body),
500
+ signal: options?.signal,
501
+ });
502
+ const text = await resp.text();
503
+ PromptevClient.raiseForStatus(resp.status, text, resp.headers);
504
+ return text ? JSON.parse(text) : {};
505
+ }
462
506
  async runOrchestration(slug, inputs = {}, options) {
463
507
  if (!slug || !slug.trim()) {
464
508
  throw new ValidationError("Name the orchestration to run.", undefined, undefined, "slug");
@@ -35,6 +35,11 @@ export declare const MAX_UPLOAD_BYTES: number;
35
35
  /** Files ONE orchestration run may carry — the same ceiling a chat turn has.
36
36
  * Server-side: `run_inputs.MAX_FILE_PARTS`. */
37
37
  export declare const MAX_FILES_PER_RUN = 5;
38
+ /** The knowledge base's actions, as the project MCP's `search_knowledge_base`
39
+ * offers them. Informational: the server decides, so an action added there
40
+ * works here without a new SDK. */
41
+ export declare const KNOWLEDGE_ACTIONS: readonly ["discover", "search", "get_doc", "list", "query_meta", "compute", "get_chunks", "get_docs", "map_reduce", "traverse", "find_related", "get_neighbors", "community_summary"];
42
+ export type KnowledgeAction = (typeof KNOWLEDGE_ACTIONS)[number];
38
43
  export interface PromptevClientConfig {
39
44
  /**
40
45
  * Your Promptev API key — `fk_…`, minted in Settings → API keys of the
@@ -539,6 +544,25 @@ export declare class PromptevClient {
539
544
  * );
540
545
  * ```
541
546
  */
547
+ /**
548
+ * Read the key's project knowledge base through the Context Engine: the
549
+ * same tool, with the same actions, as `search_knowledge_base` on the
550
+ * project's MCP server (`POST /api/v1/knowledge`).
551
+ *
552
+ * ```ts
553
+ * const overview = await client.searchKnowledgeBase("discover");
554
+ * const found = await client.searchKnowledgeBase("search", { query: "how many days do customers have to ask for a refund", top_k: 5 });
555
+ * for (const hit of found.hits) console.log(hit.document_name, hit.chunk_text);
556
+ * const doc = await client.searchKnowledgeBase("get_doc", { document_id: found.hits[0].document_id });
557
+ * ```
558
+ *
559
+ * `fields` are that action's fields (`query`, `top_k`, `document_id`,
560
+ * `source_ids`, `mode`, `limit`, `cursor`, ...); undefined and null ones
561
+ * are not sent. Returns the knowledge base's answer as an object.
562
+ */
563
+ searchKnowledgeBase(action: KnowledgeAction | (string & {}), fields?: Record<string, unknown>, options?: {
564
+ signal?: AbortSignal;
565
+ }): Promise<Record<string, any>>;
542
566
  runOrchestration(slug: string, inputs?: RunInputs, options?: RunOptions): Promise<StartedRun>;
543
567
  /**
544
568
  * What became of a run — poll this after {@link runOrchestration}.
package/dist/esm/index.js CHANGED
@@ -36,6 +36,13 @@ export const MAX_UPLOAD_BYTES = 25 * 1024 * 1024;
36
36
  /** Files ONE orchestration run may carry — the same ceiling a chat turn has.
37
37
  * Server-side: `run_inputs.MAX_FILE_PARTS`. */
38
38
  export const MAX_FILES_PER_RUN = 5;
39
+ /** The knowledge base's actions, as the project MCP's `search_knowledge_base`
40
+ * offers them. Informational: the server decides, so an action added there
41
+ * works here without a new SDK. */
42
+ export const KNOWLEDGE_ACTIONS = [
43
+ "discover", "search", "get_doc", "list", "query_meta", "compute", "get_chunks",
44
+ "get_docs", "map_reduce", "traverse", "find_related", "get_neighbors", "community_summary",
45
+ ];
39
46
  // ── Errors ──────────────────────────────────────────────
40
47
  export class PromptevError extends Error {
41
48
  constructor(message, statusCode, responseText, field) {
@@ -448,6 +455,43 @@ export class PromptevClient {
448
455
  * );
449
456
  * ```
450
457
  */
458
+ /**
459
+ * Read the key's project knowledge base through the Context Engine: the
460
+ * same tool, with the same actions, as `search_knowledge_base` on the
461
+ * project's MCP server (`POST /api/v1/knowledge`).
462
+ *
463
+ * ```ts
464
+ * const overview = await client.searchKnowledgeBase("discover");
465
+ * const found = await client.searchKnowledgeBase("search", { query: "how many days do customers have to ask for a refund", top_k: 5 });
466
+ * for (const hit of found.hits) console.log(hit.document_name, hit.chunk_text);
467
+ * const doc = await client.searchKnowledgeBase("get_doc", { document_id: found.hits[0].document_id });
468
+ * ```
469
+ *
470
+ * `fields` are that action's fields (`query`, `top_k`, `document_id`,
471
+ * `source_ids`, `mode`, `limit`, `cursor`, ...); undefined and null ones
472
+ * are not sent. Returns the knowledge base's answer as an object.
473
+ */
474
+ async searchKnowledgeBase(action, fields = {}, options) {
475
+ if (typeof action !== "string" || !action.trim()) {
476
+ throw new ValidationError('Name the action, e.g. "search".', undefined, undefined, "action");
477
+ }
478
+ const body = { action: action.trim() };
479
+ for (const [key, value] of Object.entries(fields ?? {})) {
480
+ if (value !== undefined && value !== null)
481
+ body[key] = value;
482
+ }
483
+ const headers = this.authHeaders();
484
+ headers["Content-Type"] = "application/json";
485
+ const resp = await this.fetchWithRetry(`${this.baseUrl}/api/v1/knowledge`, {
486
+ method: "POST",
487
+ headers,
488
+ body: JSON.stringify(body),
489
+ signal: options?.signal,
490
+ });
491
+ const text = await resp.text();
492
+ PromptevClient.raiseForStatus(resp.status, text, resp.headers);
493
+ return text ? JSON.parse(text) : {};
494
+ }
451
495
  async runOrchestration(slug, inputs = {}, options) {
452
496
  if (!slug || !slug.trim()) {
453
497
  throw new ValidationError("Name the orchestration to run.", undefined, undefined, "slug");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptev/client",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "JavaScript/TypeScript client for Promptev — stream your AI agents and upload documents with a workspace API key",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Promptev JavaScript client
2
2
 
3
- The official JavaScript/TypeScript client for [Promptev](https://promptev.ai) — stream your AI **agents** and upload documents to their knowledge base, from anywhere that has `fetch`.
3
+ The official JavaScript/TypeScript client for [Promptev](https://promptev.ai) — stream your AI **agents**, put documents into the Context Engine and search it, from anywhere that has `fetch`.
4
4
 
5
5
  > In Promptev, an **agent** is your deployed AI assistant: instructions + model + tools (Jira, Slack, GitHub, your own APIs) + the documents it can retrieve, all configured in the app. This client runs those agents. Tools execute server-side, retrieval is governed server-side, and conversation memory is built in.
6
6
 
@@ -274,6 +274,25 @@ A per-file failure is *reported*, not thrown: every file gets a row in `results`
274
274
 
275
275
  > Ingestion is slow and the request does not return until every file is indexed. Raise `timeout` well above its 30-second default: `new PromptevClient({ apiKey, timeout: 300_000 })`.
276
276
 
277
+ ## `searchKnowledgeBase` — search the knowledge base
278
+
279
+ ```ts
280
+ client.searchKnowledgeBase(action, fields?, options?): Promise<Record<string, any>>
281
+ ```
282
+
283
+ Reads your key's project knowledge base through the Context Engine. It is the same tool, with the same actions, as `search_knowledge_base` on the project's MCP server. Start with `discover` to see what is there, then `search` for passages or `get_doc` for one document:
284
+
285
+ ```ts
286
+ const overview = await client.searchKnowledgeBase("discover");
287
+
288
+ const found = await client.searchKnowledgeBase("search", { query: "how many days do customers have to ask for a refund", top_k: 5 });
289
+ for (const hit of found.hits) console.log(hit.document_name, hit.score, hit.chunk_text);
290
+
291
+ const doc = await client.searchKnowledgeBase("get_doc", { document_id: found.hits[0].document_id });
292
+ ```
293
+
294
+ The actions are exported as `KNOWLEDGE_ACTIONS`: `discover`, `search`, `get_doc`, `list`, `query_meta`, `compute`, `get_chunks`, `get_docs`, `map_reduce`, `traverse`, `find_related`, `get_neighbors` and `community_summary`. `fields` are that action's fields (`query`, `top_k`, `document_id`, `source_ids`, `mode`, `limit`, `cursor`, ...). The key reads only its own project.
295
+
277
296
  ## `runOrchestration` — run a team of agents
278
297
 
279
298
  An orchestration is a **team of agents** working one job. `chat` streams one agent's answer inline; an orchestration runs in a worker for as long as it takes, so `runOrchestration` hands back a run id straight away and `getRun` says what became of it.
@@ -394,9 +413,7 @@ All errors extend `PromptevError` and carry:
394
413
  ## What a call costs
395
414
 
396
415
  Promptev is pay as you go and this API is metered. The rates below are the
397
- managed ones; a workspace running on its own database and embedding provider
398
- (BYO) is charged a flat **1** per operation instead, because those bills are
399
- already yours.
416
+ same for every workspace, including one on its own database or models.
400
417
 
401
418
  | what happens | credits |
402
419
  |---|---|
@@ -406,6 +423,7 @@ already yours.
406
423
  | retrieval | **1** per knowledge base searched |
407
424
  | retrieval in graph mode | **5** per knowledge base searched |
408
425
  | a document you upload | **1** per page, slide or MB (minimum 1) |
426
+ | `searchKnowledgeBase` | the same as on the MCP server: **1** per call, **+1** for a search (**+5** when the graph is searched); no `api_call` charge |
409
427
 
410
428
  So an ordinary `chat` costs **2** — one for the request, one for the turn — and
411
429
  more if the agent calls tools or searches knowledge. The same conversation held