@sapiom/tools 0.6.2 → 0.7.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 (61) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +16 -11
  3. package/dist/cjs/_client/index.d.ts +22 -2
  4. package/dist/cjs/_client/index.d.ts.map +1 -1
  5. package/dist/cjs/_client/index.js +16 -6
  6. package/dist/cjs/_client/index.js.map +1 -1
  7. package/dist/cjs/client.d.ts +20 -1
  8. package/dist/cjs/client.d.ts.map +1 -1
  9. package/dist/cjs/client.js +8 -0
  10. package/dist/cjs/client.js.map +1 -1
  11. package/dist/cjs/content-generation/index.d.ts +55 -3
  12. package/dist/cjs/content-generation/index.d.ts.map +1 -1
  13. package/dist/cjs/content-generation/index.js +76 -4
  14. package/dist/cjs/content-generation/index.js.map +1 -1
  15. package/dist/cjs/index.d.ts +3 -1
  16. package/dist/cjs/index.d.ts.map +1 -1
  17. package/dist/cjs/index.js +4 -1
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/search/errors.d.ts +16 -0
  20. package/dist/cjs/search/errors.d.ts.map +1 -0
  21. package/dist/cjs/search/errors.js +36 -0
  22. package/dist/cjs/search/errors.js.map +1 -0
  23. package/dist/cjs/search/index.d.ts +105 -0
  24. package/dist/cjs/search/index.d.ts.map +1 -0
  25. package/dist/cjs/search/index.js +129 -0
  26. package/dist/cjs/search/index.js.map +1 -0
  27. package/dist/cjs/stub/index.d.ts.map +1 -1
  28. package/dist/cjs/stub/index.js +39 -1
  29. package/dist/cjs/stub/index.js.map +1 -1
  30. package/dist/esm/_client/index.d.ts +22 -2
  31. package/dist/esm/_client/index.d.ts.map +1 -1
  32. package/dist/esm/_client/index.js +16 -6
  33. package/dist/esm/_client/index.js.map +1 -1
  34. package/dist/esm/client.d.ts +20 -1
  35. package/dist/esm/client.d.ts.map +1 -1
  36. package/dist/esm/client.js +8 -0
  37. package/dist/esm/client.js.map +1 -1
  38. package/dist/esm/content-generation/index.d.ts +55 -3
  39. package/dist/esm/content-generation/index.d.ts.map +1 -1
  40. package/dist/esm/content-generation/index.js +74 -3
  41. package/dist/esm/content-generation/index.js.map +1 -1
  42. package/dist/esm/index.d.ts +3 -1
  43. package/dist/esm/index.d.ts.map +1 -1
  44. package/dist/esm/index.js +3 -1
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/esm/search/errors.d.ts +16 -0
  47. package/dist/esm/search/errors.d.ts.map +1 -0
  48. package/dist/esm/search/errors.js +31 -0
  49. package/dist/esm/search/errors.js.map +1 -0
  50. package/dist/esm/search/index.d.ts +105 -0
  51. package/dist/esm/search/index.d.ts.map +1 -0
  52. package/dist/esm/search/index.js +124 -0
  53. package/dist/esm/search/index.js.map +1 -0
  54. package/dist/esm/stub/index.d.ts.map +1 -1
  55. package/dist/esm/stub/index.js +39 -1
  56. package/dist/esm/stub/index.js.map +1 -1
  57. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  58. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  59. package/package.json +6 -1
  60. package/src/content-generation/README.md +23 -2
  61. package/src/search/README.md +126 -0
@@ -1,6 +1,6 @@
1
1
  # contentGeneration
2
2
 
3
- Generate media — images today (video and audio to come) — with an optional
3
+ Generate media — images and video today (audio to come) — with an optional
4
4
  `storage` param that persists each output to Sapiom file storage, so you get a
5
5
  durable `fileId` back inline.
6
6
 
@@ -41,7 +41,28 @@ for (const img of out.images ?? []) {
41
41
  Persisting is best-effort per image: if one fails, that image carries a
42
42
  `storageError` string instead of a `fileId` while the others still succeed.
43
43
 
44
- ## Input
44
+ ## Video (async)
45
+
46
+ Video generation is **asynchronous** — `create` submits the job, polls for the
47
+ result, and resolves once it's ready, so you `await` it like an image (it just
48
+ takes longer). `storage` works the same way — the output comes back with a `fileId`.
49
+
50
+ ```typescript
51
+ const out = await sapiom.contentGeneration.video.create({
52
+ prompt: "a calm ocean wave at sunset",
53
+ storage: { visibility: "private" }, // optional — persist the output
54
+ });
55
+
56
+ out.video?.url; // hosted URL of the generated video
57
+ out.video?.fileId; // present when `storage` was passed — use with `fileStorage`
58
+ ```
59
+
60
+ Video input takes `prompt`, plus optional `storage`, `model`, and `params` (as with
61
+ images), and two async controls: `pollIntervalMs` (poll cadence, default 5s) and
62
+ `timeoutMs` (give up and throw if it isn't ready in time, default 5 min). The
63
+ returned `video` is `{ url, contentType?, fileId?, storageError? }`.
64
+
65
+ ## Image input
45
66
 
46
67
  - `prompt` (required) — the text prompt.
47
68
  - `numImages` (optional) — how many images to generate.
@@ -0,0 +1,126 @@
1
+ # search
2
+
3
+ Find information across the web and beyond — searching the web, reading pages,
4
+ and looking up professional emails. More operations land in this namespace as
5
+ they ship; today it offers `webSearch` and `scrape`.
6
+
7
+ ## `webSearch` — search the web
8
+
9
+ Search the web and get a synthesized answer plus supporting results:
10
+
11
+ ```typescript
12
+ import { createClient } from "@sapiom/tools";
13
+ const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
14
+
15
+ const hits = await sapiom.search.webSearch({ query: "what is an LLM agent?" });
16
+ hits.answer; // a synthesized answer
17
+ hits.results; // supporting results: [{ title, url, snippet }]
18
+ ```
19
+
20
+ Ambient import works too: `import { search } from "@sapiom/tools"`.
21
+
22
+ ### Choosing what you get back
23
+
24
+ Pass `intent: "links"` for a list of relevant results instead of a synthesized
25
+ answer, and `depth: "deep"` for a more thorough search:
26
+
27
+ ```typescript
28
+ const hits = await sapiom.search.webSearch({
29
+ query: "best practices for prompt caching",
30
+ intent: "links",
31
+ depth: "deep",
32
+ });
33
+ hits.results; // [{ title, url, snippet }, …]
34
+ ```
35
+
36
+ ### Input
37
+
38
+ - `query` (required) — what to search for.
39
+ - `depth` (optional) — `"standard"` (default) or `"deep"` for a more thorough
40
+ search.
41
+ - `intent` (optional) — `"answer"` (default) for a synthesized answer plus
42
+ supporting results, or `"links"` for a list of relevant results.
43
+
44
+ ### Result
45
+
46
+ ```typescript
47
+ {
48
+ query: string; // the query that was searched
49
+ answer?: string; // a synthesized answer (present for intent: "answer")
50
+ results: Array<{
51
+ title: string;
52
+ url: string;
53
+ snippet: string;
54
+ }>;
55
+ }
56
+ ```
57
+
58
+ ## `scrape` — read a page
59
+
60
+ Read a page and return its content. By default you get markdown:
61
+
62
+ ```typescript
63
+ import { createClient } from "@sapiom/tools";
64
+ const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
65
+
66
+ const page = await sapiom.search.scrape({ url: "https://example.com" });
67
+ page.markdown; // the page content as markdown
68
+ page.metadata.title; // the page title
69
+ ```
70
+
71
+ Ambient import works too: `import { search } from "@sapiom/tools"`.
72
+
73
+ ### Choosing formats
74
+
75
+ Pass `formats` to get HTML, raw HTML, a screenshot, or the page's links — alone
76
+ or alongside markdown:
77
+
78
+ ```typescript
79
+ const page = await sapiom.search.scrape({
80
+ url: "https://example.com",
81
+ formats: ["markdown", "html", "links"],
82
+ });
83
+ page.html; // cleaned HTML
84
+ page.links; // string[] of links found on the page
85
+ ```
86
+
87
+ Each requested format is returned as its own field; a field is present only when
88
+ that format was requested.
89
+
90
+ ### Input
91
+
92
+ - `url` (required) — the page to read.
93
+ - `formats` (optional) — any of `"markdown" | "html" | "rawHtml" | "screenshot" |
94
+ "links"`. Defaults to `["markdown"]`.
95
+ - `onlyMainContent` (optional) — return only the main content, dropping
96
+ navigation, headers, footers, and ads.
97
+ - `waitFor` (optional) — milliseconds to wait before reading, for content
98
+ rendered by JavaScript.
99
+
100
+ ### Result
101
+
102
+ ```typescript
103
+ {
104
+ url: string; // the URL that was read
105
+ markdown?: string;
106
+ html?: string;
107
+ rawHtml?: string;
108
+ screenshot?: string;
109
+ links?: string[];
110
+ metadata: {
111
+ title?: string;
112
+ description?: string;
113
+ language?: string;
114
+ sourceUrl?: string;
115
+ statusCode?: number;
116
+ };
117
+ }
118
+ ```
119
+
120
+ `scrape` works on HTML pages and common documents (PDF, DOCX, TXT). It is not
121
+ meant for images, video, or archives.
122
+
123
+ ## Gotchas
124
+
125
+ - **Failed requests throw `SearchHttpError`** (carries `status` + parsed `body`),
126
+ exported from `@sapiom/tools`.