@simpleplatform/sdk 4.2.1 → 4.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.
package/README.md CHANGED
@@ -89,7 +89,7 @@ simple.Handle(async (request) => {
89
89
  The TypeScript SDK is organized into focused modules for different capabilities:
90
90
 
91
91
  | **Core** | `@simpleplatform/sdk` | Request handling and action execution |
92
- | **AI** | `@simpleplatform/sdk/ai` | AI operations (extract, summarize, transcribePages) |
92
+ | **AI** | `@simpleplatform/sdk/ai` | AI operations (extract, summarize, transcribePages, searchWeb, parseWeb, askWeb) |
93
93
  | **GraphQL** | `@simpleplatform/sdk/graphql` | Database queries and mutations |
94
94
  | **HTTP** | `@simpleplatform/sdk/http` | External HTTP requests |
95
95
  | **Security** | `@simpleplatform/sdk/security` | Security policy authoring |
@@ -864,6 +864,39 @@ for (const page of data.pages) {
864
864
  }
865
865
  ```
866
866
 
867
+ #### Search the Web
868
+
869
+ Find pages that match a query:
870
+
871
+ ```typescript
872
+ import { searchWeb } from '@simpleplatform/sdk/ai'
873
+
874
+ const result = await searchWeb('public transit plans', { limit: 5 }, request.context)
875
+ console.log(result.pages[0]?.url)
876
+ ```
877
+
878
+ #### Read Web Pages
879
+
880
+ Read pages from their addresses:
881
+
882
+ ```typescript
883
+ import { parseWeb } from '@simpleplatform/sdk/ai'
884
+
885
+ const result = await parseWeb(['https://example.com'], { fullText: true }, request.context)
886
+ console.log(result.pages[0]?.title)
887
+ ```
888
+
889
+ #### Answer from the Web
890
+
891
+ Get an answer together with the pages it came from:
892
+
893
+ ```typescript
894
+ import { askWeb } from '@simpleplatform/sdk/ai'
895
+
896
+ const result = await askWeb('When was the first public library founded?', {}, request.context)
897
+ console.log(result.answer, result.sources[0]?.url)
898
+ ```
899
+
867
900
  Pages are numbered in the original document. Transcriptions are kept per
868
901
  version of the file and page, so a page already read for an `extract` or
869
902
  `summarize` that asked for text (`deliver_as: 'text'`) is not read again.
package/dist/ai.d.ts CHANGED
@@ -277,6 +277,88 @@ export interface AIFaceSearchOptions {
277
277
  */
278
278
  similarityThreshold?: number;
279
279
  }
280
+ /** Options for a summary added to each web page. */
281
+ export interface AIWebSummaryOptions {
282
+ /** A topic to focus the summary on. */
283
+ focus?: string;
284
+ /** A JSON Schema describing the summary. */
285
+ schema?: JSONSchemaObject;
286
+ }
287
+ /** Options for finding pages on the web. */
288
+ export interface AISearchWebOptions {
289
+ limit?: number;
290
+ depth?: 'fast' | 'standard' | 'deep';
291
+ kind?: 'company' | 'person' | 'news' | 'publication' | 'personal_site' | 'financial_report';
292
+ sites?: string[];
293
+ skipSites?: string[];
294
+ publishedAfter?: string;
295
+ publishedBefore?: string;
296
+ country?: string;
297
+ freshWithinHours?: number;
298
+ fullText?: boolean;
299
+ focus?: string;
300
+ summary?: true | AIWebSummaryOptions;
301
+ schema?: JSONSchemaObject;
302
+ }
303
+ /** Options for reading pages from their addresses. */
304
+ export interface AIParseWebOptions {
305
+ fullText?: boolean;
306
+ focus?: string;
307
+ summary?: true | AIWebSummaryOptions;
308
+ subpages?: number;
309
+ freshWithinHours?: number;
310
+ }
311
+ /** Options for answering a question from the web. */
312
+ export interface AIAskWebOptions {
313
+ schema?: JSONSchemaObject;
314
+ country?: string;
315
+ }
316
+ /** A page that was found or read. */
317
+ export interface AIWebPage {
318
+ url: string;
319
+ title?: string;
320
+ publishedAt?: string;
321
+ author?: string;
322
+ excerpts?: string[];
323
+ text?: string;
324
+ summary?: string | Record<string, unknown>;
325
+ }
326
+ /** A page that was read or could not be read. */
327
+ export type AIParsedWebPage = (AIWebPage & {
328
+ ok: true;
329
+ }) | {
330
+ url: string;
331
+ ok: false;
332
+ failure: 'not_found' | 'blocked' | 'timeout' | 'unreachable';
333
+ };
334
+ /** A page used to answer a structured field. */
335
+ export interface AIWebSource {
336
+ url: string;
337
+ title?: string;
338
+ publishedAt?: string;
339
+ }
340
+ /** The pages and confidence reported for one structured field. */
341
+ export interface AIWebFieldSource {
342
+ field: string;
343
+ sources: AIWebSource[];
344
+ confidence?: string;
345
+ }
346
+ /** The pages found, with any structured values requested by a schema. */
347
+ export interface AISearchWebResult {
348
+ pages: AIWebPage[];
349
+ data?: Record<string, unknown>;
350
+ fieldSources?: AIWebFieldSource[];
351
+ }
352
+ /** The pages read from the requested addresses. */
353
+ export interface AIParseWebResult {
354
+ pages: AIParsedWebPage[];
355
+ }
356
+ /** The answer and the pages it came from. */
357
+ export interface AIAskWebResult {
358
+ answer?: string;
359
+ data?: Record<string, unknown>;
360
+ sources: AIWebSource[];
361
+ }
280
362
  /**
281
363
  * How one file an AI operation carried reached the model. Page numbers are
282
364
  * the original document's, whatever range was cut from it.
@@ -433,6 +515,30 @@ export declare function enrollFace(subjectId: string, image: DocumentHandle | st
433
515
  * @throws Will throw an error if the operation fails or inputs are invalid.
434
516
  */
435
517
  export declare function searchFace(image: DocumentHandle | string, options: AIFaceSearchOptions | undefined, context: Context): Promise<any>;
518
+ /**
519
+ * Finds pages on the web that match a query.
520
+ *
521
+ * @example
522
+ * const result = await searchWeb('public transit plans', { limit: 5 }, request.context)
523
+ * console.log(result.pages[0]?.url)
524
+ */
525
+ export declare function searchWeb(query: string, options: AISearchWebOptions | undefined, context: Context): Promise<AISearchWebResult>;
526
+ /**
527
+ * Reads pages from their addresses.
528
+ *
529
+ * @example
530
+ * const result = await parseWeb(['https://example.com'], { fullText: true }, request.context)
531
+ * console.log(result.pages[0]?.title)
532
+ */
533
+ export declare function parseWeb(urls: string[], options: AIParseWebOptions | undefined, context: Context): Promise<AIParseWebResult>;
534
+ /**
535
+ * Answers a question from the web and returns its sources.
536
+ *
537
+ * @example
538
+ * const result = await askWeb('When was the first public library founded?', {}, request.context)
539
+ * console.log(result.answer, result.sources[0]?.url)
540
+ */
541
+ export declare function askWeb(question: string, options: AIAskWebOptions | undefined, context: Context): Promise<AIAskWebResult>;
436
542
  /**
437
543
  * Deletes one or more faces from the tenant's collection by their face IDs.
438
544
  *
package/dist/ai.js CHANGED
@@ -412,6 +412,60 @@ export async function searchFace(image, options = {}, context) {
412
412
  }
413
413
  return response.data;
414
414
  }
415
+ /**
416
+ * Finds pages on the web that match a query.
417
+ *
418
+ * @example
419
+ * const result = await searchWeb('public transit plans', { limit: 5 }, request.context)
420
+ * console.log(result.pages[0]?.url)
421
+ */
422
+ export async function searchWeb(query, options = {}, context) {
423
+ const payload = {
424
+ options: Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)),
425
+ query,
426
+ };
427
+ const response = await hostExecute('action:ai/web/search', payload, context);
428
+ if (!response.ok) {
429
+ throw new Error(response.error?.message || 'Web search failed.');
430
+ }
431
+ return response.data;
432
+ }
433
+ /**
434
+ * Reads pages from their addresses.
435
+ *
436
+ * @example
437
+ * const result = await parseWeb(['https://example.com'], { fullText: true }, request.context)
438
+ * console.log(result.pages[0]?.title)
439
+ */
440
+ export async function parseWeb(urls, options = {}, context) {
441
+ const payload = {
442
+ options: Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)),
443
+ urls,
444
+ };
445
+ const response = await hostExecute('action:ai/web/parse', payload, context);
446
+ if (!response.ok) {
447
+ throw new Error(response.error?.message || 'Web page reading failed.');
448
+ }
449
+ return response.data;
450
+ }
451
+ /**
452
+ * Answers a question from the web and returns its sources.
453
+ *
454
+ * @example
455
+ * const result = await askWeb('When was the first public library founded?', {}, request.context)
456
+ * console.log(result.answer, result.sources[0]?.url)
457
+ */
458
+ export async function askWeb(question, options = {}, context) {
459
+ const payload = {
460
+ options: Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)),
461
+ question,
462
+ };
463
+ const response = await hostExecute('action:ai/web/ask', payload, context);
464
+ if (!response.ok) {
465
+ throw new Error(response.error?.message || 'Web answer failed.');
466
+ }
467
+ return response.data;
468
+ }
415
469
  /**
416
470
  * Deletes one or more faces from the tenant's collection by their face IDs.
417
471
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleplatform/sdk",
3
- "version": "4.2.1",
3
+ "version": "4.3.0",
4
4
  "description": "Simple Platform Typescript SDK",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://docs.simple.dev",