@ontrove/sdk 0.1.0 → 0.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/CHANGELOG.md +23 -0
- package/README.md +34 -33
- package/dist/define.d.ts +21 -21
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +25 -25
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -10
- package/dist/manifest.d.ts +6 -6
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +7 -7
- package/dist/runtime.d.ts +21 -21
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +15 -15
- package/dist/types.d.ts +57 -55
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -7
- package/package.json +11 -4
- package/src/define.ts +28 -35
- package/src/index.ts +17 -16
- package/src/manifest.ts +10 -10
- package/src/runtime.ts +34 -34
- package/src/types.ts +57 -55
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @ontrove/sdk
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- dbf6fa1: Product-taxonomy renames: connectors are now **sources** (their per-feed
|
|
8
|
+
children are **feeds**), and hosted MCP servers are presented as **toolkits**.
|
|
9
|
+
No compatibility aliases.
|
|
10
|
+
|
|
11
|
+
- `@ontrove/sdk`: `defineConnector` → `defineSource`, `runConnector` →
|
|
12
|
+
`runSource`, `validateConnectorManifest` → `validateSourceManifest`,
|
|
13
|
+
`TroveConnector` → `TroveSource`, and `ConnectorDocument`/`ConnectorContext`/
|
|
14
|
+
`ConnectorSyncResult`/`ConnectorManifest`/`ConnectorContentType` →
|
|
15
|
+
`Source*`.
|
|
16
|
+
- `@ontrove/cli`: the `trove connector`/`trove connectors` command family is now
|
|
17
|
+
`trove source`/`trove sources`; `--connector` filter flags are now `--source`,
|
|
18
|
+
and the child-level `--source` flag is now `--feed` (`trove ingest --source
|
|
19
|
+
<id> --feed <id>`). All GraphQL operations target the renamed schema
|
|
20
|
+
(`sources`, `source`, `createSource`, `addFeed`, `sourceId`/`feedId`,
|
|
21
|
+
`totalSources`, `documentsBySourceType`, …). The `trove mcp *` namespace is
|
|
22
|
+
unchanged.
|
|
23
|
+
- `@ontrove/mcp`: `ctx.trove.search`'s `TroveSearchOpts.connector` option is now
|
|
24
|
+
`source` (requires a Trove cloud that accepts the `source` wire key).
|
|
25
|
+
|
|
3
26
|
## 0.1.0
|
|
4
27
|
|
|
5
28
|
Initial release — the connector authoring SDK: `defineConnector`, the `sync(ctx)`
|
package/README.md
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
# @ontrove/sdk
|
|
2
2
|
|
|
3
|
-
The thin standard library for authoring **Trove
|
|
4
|
-
`sync(ctx)` that fetches
|
|
5
|
-
document shape, the typed `ctx` capability object,
|
|
6
|
-
the local-run harness the CLI drives, and manifest
|
|
3
|
+
The thin standard library for authoring **Trove sources** — the things that fill
|
|
4
|
+
your Library. You write a `sync(ctx)` that fetches new content and returns
|
|
5
|
+
documents; the SDK owns the document shape, the typed `ctx` capability object,
|
|
6
|
+
the watermark/cursor model, the local-run harness the CLI drives, and manifest
|
|
7
|
+
validation.
|
|
7
8
|
|
|
8
|
-
It is symmetric with the
|
|
9
|
+
It is symmetric with the toolkit-authoring SDK
|
|
9
10
|
([`@ontrove/mcp`](https://www.npmjs.com/package/@ontrove/mcp)) `defineMcpServer`
|
|
10
|
-
contract: a
|
|
11
|
-
|
|
11
|
+
contract: a source returns documents to be _stored_ (batch `sync`); a toolkit's
|
|
12
|
+
tools return results to be _read live_.
|
|
12
13
|
|
|
13
|
-
See the full [SDK Reference](https://docs.ontrove.sh/
|
|
14
|
-
the [manifest.json reference](https://docs.ontrove.sh/
|
|
15
|
-
the [cursors &
|
|
14
|
+
See the full [SDK Reference](https://docs.ontrove.sh/sources/sdk-reference/),
|
|
15
|
+
the [manifest.json reference](https://docs.ontrove.sh/sources/manifest/), and
|
|
16
|
+
the [cursors & feeds model](https://docs.ontrove.sh/sources/cursors-and-feeds/)
|
|
16
17
|
in the docs.
|
|
17
18
|
|
|
18
19
|
## Install
|
|
@@ -23,16 +24,16 @@ npm install @ontrove/sdk
|
|
|
23
24
|
|
|
24
25
|
## Quickstart
|
|
25
26
|
|
|
26
|
-
A
|
|
27
|
-
fetches
|
|
27
|
+
A source's `index.ts` must `export default defineSource(...)`. Your `sync`
|
|
28
|
+
fetches new content and returns documents — each field maps 1:1 onto the
|
|
28
29
|
`IngestDocumentInput` the Mac app pushes via `ingestDocuments`.
|
|
29
30
|
|
|
30
31
|
### Hacker News front page
|
|
31
32
|
|
|
32
33
|
```ts
|
|
33
|
-
import {
|
|
34
|
+
import { defineSource } from '@ontrove/sdk';
|
|
34
35
|
|
|
35
|
-
export default
|
|
36
|
+
export default defineSource({
|
|
36
37
|
async sync(ctx) {
|
|
37
38
|
const res = await ctx.fetch('https://hn.algolia.com/api/v1/search?tags=front_page');
|
|
38
39
|
const { hits } = await res.json();
|
|
@@ -60,11 +61,11 @@ export default defineConnector({
|
|
|
60
61
|
> `parseRss` / `stripHtml` below are **your own helpers** — the SDK ships no XML
|
|
61
62
|
> parser. Bring your own (e.g. [`fast-xml-parser`](https://www.npmjs.com/package/fast-xml-parser)).
|
|
62
63
|
|
|
63
|
-
```ts
|
|
64
|
-
import {
|
|
64
|
+
```ts no-typecheck
|
|
65
|
+
import { defineSource } from '@ontrove/sdk';
|
|
65
66
|
// import { parseRss, stripHtml } from './rss-helpers'; // your own — see note above
|
|
66
67
|
|
|
67
|
-
export default
|
|
68
|
+
export default defineSource({
|
|
68
69
|
async sync(ctx) {
|
|
69
70
|
const feedUrl = ctx.config.feedUrl as string;
|
|
70
71
|
const since = ctx.cursor.type === 'date' ? new Date(ctx.cursor.value) : new Date(0);
|
|
@@ -101,9 +102,9 @@ A bare array is accepted too — `return documents;` is shorthand for
|
|
|
101
102
|
| Member | Type | Description |
|
|
102
103
|
| ------------- | ------------------------------------------- | --------------------------------------------------------------------------- |
|
|
103
104
|
| `ctx.config` | `C` (typed preferences) | The user's setup preferences. **Never credentials.** |
|
|
104
|
-
| `ctx.cursor` | `Watermark` (read-only) | The
|
|
105
|
+
| `ctx.cursor` | `Watermark` (read-only) | The feed's current watermark; `{ type: 'none' }` on first sync. |
|
|
105
106
|
| `ctx.fetch` | `(url, init?) => Promise<Response>` | Standard `fetch` — routes through the Mac app's networking. |
|
|
106
|
-
| `ctx.log` | `(...args) => void` | Structured log entry, surfaced in
|
|
107
|
+
| `ctx.log` | `(...args) => void` | Structured log entry, surfaced in the source's logs. |
|
|
107
108
|
| `ctx.now` | `() => Date` | Injected clock (deterministic under test). |
|
|
108
109
|
|
|
109
110
|
`ctx.credentials` (Keychain-resolved auth) and `ctx.browser` (Playwright) are
|
|
@@ -111,9 +112,9 @@ A bare array is accepted too — `return documents;` is shorthand for
|
|
|
111
112
|
|
|
112
113
|
## The document shape → `IngestDocumentInput`
|
|
113
114
|
|
|
114
|
-
`
|
|
115
|
+
`SourceDocument` maps 1:1 onto the GraphQL `IngestDocumentInput` wire type:
|
|
115
116
|
|
|
116
|
-
| `
|
|
117
|
+
| `SourceDocument` | `IngestDocumentInput` | Required |
|
|
117
118
|
| ------------------- | --------------------- | ------------------------------ |
|
|
118
119
|
| `id` | `externalId` | **Yes** |
|
|
119
120
|
| `title` | `title` | No |
|
|
@@ -126,27 +127,27 @@ A bare array is accepted too — `return documents;` is shorthand for
|
|
|
126
127
|
| `metadata` | `metadata` (JSON) | No |
|
|
127
128
|
| `contentType` | `contentType` | No (default `text`) |
|
|
128
129
|
|
|
129
|
-
Dedup is keyed on `(
|
|
130
|
+
Dedup is keyed on `(feed, id)`, so `sync` is safe to retry — re-returning the
|
|
130
131
|
same `id` is skipped.
|
|
131
132
|
|
|
132
133
|
## Watermarks
|
|
133
134
|
|
|
134
|
-
A `Watermark` describes how a
|
|
135
|
+
A `Watermark` describes how a feed resumes between syncs:
|
|
135
136
|
|
|
136
|
-
- `{ type: 'date', value }` — time-ordered
|
|
137
|
+
- `{ type: 'date', value }` — time-ordered feeds with "since <date>" filtering (RSS, most APIs).
|
|
137
138
|
- `{ type: 'idSet', values, max? }` — monotonic ids, no reliable date filter.
|
|
138
139
|
- `{ type: 'none' }` — re-fetch everything; rely on dedup. Always correct, less efficient.
|
|
139
140
|
|
|
140
141
|
## Local run harness
|
|
141
142
|
|
|
142
|
-
`
|
|
143
|
+
`runSource` is what `trove source dev` / `trove source test` call. It
|
|
143
144
|
builds a `ctx`, runs `sync`, validates and dedups the documents:
|
|
144
145
|
|
|
145
|
-
```ts
|
|
146
|
-
import {
|
|
147
|
-
import
|
|
146
|
+
```ts no-typecheck
|
|
147
|
+
import { runSource } from '@ontrove/sdk';
|
|
148
|
+
import source from './index.js';
|
|
148
149
|
|
|
149
|
-
const { documents, cursor, duplicatesSkipped } = await
|
|
150
|
+
const { documents, cursor, duplicatesSkipped } = await runSource(source, {
|
|
150
151
|
config: { feedUrl: 'https://example.com/feed.xml' },
|
|
151
152
|
cursor: { type: 'date', value: '2026-06-01T00:00:00Z' },
|
|
152
153
|
});
|
|
@@ -154,15 +155,15 @@ const { documents, cursor, duplicatesSkipped } = await runConnector(connector, {
|
|
|
154
155
|
|
|
155
156
|
## Manifest validation
|
|
156
157
|
|
|
157
|
-
`
|
|
158
|
+
`validateSourceManifest` backs `trove source validate`. It checks required
|
|
158
159
|
fields and the `id`/`version` patterns, and lints `config` for credential-shaped
|
|
159
160
|
keys — the same spirit as the cloud's `validateConfig` (config holds preferences
|
|
160
161
|
only; credentials live in the macOS Keychain).
|
|
161
162
|
|
|
162
|
-
```ts
|
|
163
|
-
import {
|
|
163
|
+
```ts no-typecheck
|
|
164
|
+
import { validateSourceManifest } from '@ontrove/sdk';
|
|
164
165
|
|
|
165
|
-
const { valid, errors } =
|
|
166
|
+
const { valid, errors } = validateSourceManifest(manifest);
|
|
166
167
|
if (!valid) throw new Error(errors.join('\n'));
|
|
167
168
|
```
|
|
168
169
|
|
package/dist/define.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
3
|
-
* (
|
|
2
|
+
* `defineSource` — the single entry point for authoring a Trove source
|
|
3
|
+
* (sources/sdk-reference). It is the symmetric sibling of `defineMcpServer`
|
|
4
4
|
* in `@ontrove/mcp`.
|
|
5
5
|
*
|
|
6
6
|
* It is an identity function with light, eager validation: it confirms the value
|
|
7
|
-
* is a
|
|
7
|
+
* is a source object with a `sync` method, so a typo (`snyc`, a missing
|
|
8
8
|
* `sync`, a non-function) fails at authoring/deploy time with a clear message
|
|
9
9
|
* rather than at the first scheduled run. It does **not** execute `sync` — that is
|
|
10
|
-
* {@link
|
|
10
|
+
* {@link runSource}'s job.
|
|
11
11
|
*
|
|
12
12
|
* @module
|
|
13
13
|
*/
|
|
14
|
-
import type {
|
|
14
|
+
import type { SourceContext, SourceDocument, SourceSyncResult, TroveSource } from './types.js';
|
|
15
15
|
/**
|
|
16
|
-
* Validate and return a
|
|
16
|
+
* Validate and return a source definition unchanged.
|
|
17
17
|
*
|
|
18
|
-
* Using `
|
|
19
|
-
* gives an eager runtime check: the CLI calls this when loading a
|
|
18
|
+
* Using `defineSource(...)` (rather than a bare `satisfies TroveSource`)
|
|
19
|
+
* gives an eager runtime check: the CLI calls this when loading a source
|
|
20
20
|
* module so a malformed export is rejected before any sync runs. The returned
|
|
21
21
|
* value is the same object, with full inferred types preserved.
|
|
22
22
|
*
|
|
23
|
-
* @typeParam C - The shape of the
|
|
24
|
-
* @param
|
|
25
|
-
* @returns The same
|
|
26
|
-
* @throws {Error} If `
|
|
23
|
+
* @typeParam C - The shape of the source's typed `ctx.config` preferences.
|
|
24
|
+
* @param source - The source object to validate.
|
|
25
|
+
* @returns The same source object.
|
|
26
|
+
* @throws {Error} If `source` is not an object with a `sync` function.
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
|
30
|
-
* export default
|
|
30
|
+
* export default defineSource({
|
|
31
31
|
* async sync(ctx) {
|
|
32
32
|
* const res = await ctx.fetch(ctx.config.feedUrl as string);
|
|
33
33
|
* return parseRss(await res.text());
|
|
@@ -35,15 +35,15 @@ import type { ConnectorContext, ConnectorDocument, ConnectorSyncResult, TroveCon
|
|
|
35
35
|
* });
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
export declare function
|
|
38
|
+
export declare function defineSource<C = Record<string, unknown>>(source: TroveSource<C>): TroveSource<C>;
|
|
39
39
|
/**
|
|
40
|
-
* A
|
|
41
|
-
* where the
|
|
42
|
-
* `
|
|
40
|
+
* A source authored inline as a single `sync` function, for the common case
|
|
41
|
+
* where the source has no other members. Equivalent to
|
|
42
|
+
* `defineSource({ sync })`.
|
|
43
43
|
*
|
|
44
|
-
* @typeParam C - The shape of the
|
|
45
|
-
* @param sync - The
|
|
46
|
-
* @returns A validated {@link
|
|
44
|
+
* @typeParam C - The shape of the source's typed `ctx.config` preferences.
|
|
45
|
+
* @param sync - The source's `sync(ctx)` implementation.
|
|
46
|
+
* @returns A validated {@link TroveSource} wrapping `sync`.
|
|
47
47
|
*/
|
|
48
|
-
export declare function defineSync<C = Record<string, unknown>>(sync: (ctx:
|
|
48
|
+
export declare function defineSync<C = Record<string, unknown>>(sync: (ctx: SourceContext<C>) => Promise<SourceSyncResult | SourceDocument[]>): TroveSource<C>;
|
|
49
49
|
//# sourceMappingURL=define.d.ts.map
|
package/dist/define.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAQhG;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpD,IAAI,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,gBAAgB,GAAG,cAAc,EAAE,CAAC,GAC5E,WAAW,CAAC,CAAC,CAAC,CAEhB"}
|
package/dist/define.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
3
|
-
* (
|
|
2
|
+
* `defineSource` — the single entry point for authoring a Trove source
|
|
3
|
+
* (sources/sdk-reference). It is the symmetric sibling of `defineMcpServer`
|
|
4
4
|
* in `@ontrove/mcp`.
|
|
5
5
|
*
|
|
6
6
|
* It is an identity function with light, eager validation: it confirms the value
|
|
7
|
-
* is a
|
|
7
|
+
* is a source object with a `sync` method, so a typo (`snyc`, a missing
|
|
8
8
|
* `sync`, a non-function) fails at authoring/deploy time with a clear message
|
|
9
9
|
* rather than at the first scheduled run. It does **not** execute `sync` — that is
|
|
10
|
-
* {@link
|
|
10
|
+
* {@link runSource}'s job.
|
|
11
11
|
*
|
|
12
12
|
* @module
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
|
-
* Validate and return a
|
|
15
|
+
* Validate and return a source definition unchanged.
|
|
16
16
|
*
|
|
17
|
-
* Using `
|
|
18
|
-
* gives an eager runtime check: the CLI calls this when loading a
|
|
17
|
+
* Using `defineSource(...)` (rather than a bare `satisfies TroveSource`)
|
|
18
|
+
* gives an eager runtime check: the CLI calls this when loading a source
|
|
19
19
|
* module so a malformed export is rejected before any sync runs. The returned
|
|
20
20
|
* value is the same object, with full inferred types preserved.
|
|
21
21
|
*
|
|
22
|
-
* @typeParam C - The shape of the
|
|
23
|
-
* @param
|
|
24
|
-
* @returns The same
|
|
25
|
-
* @throws {Error} If `
|
|
22
|
+
* @typeParam C - The shape of the source's typed `ctx.config` preferences.
|
|
23
|
+
* @param source - The source object to validate.
|
|
24
|
+
* @returns The same source object.
|
|
25
|
+
* @throws {Error} If `source` is not an object with a `sync` function.
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
28
|
* ```ts
|
|
29
|
-
* export default
|
|
29
|
+
* export default defineSource({
|
|
30
30
|
* async sync(ctx) {
|
|
31
31
|
* const res = await ctx.fetch(ctx.config.feedUrl as string);
|
|
32
32
|
* return parseRss(await res.text());
|
|
@@ -34,24 +34,24 @@
|
|
|
34
34
|
* });
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
export function
|
|
38
|
-
if (
|
|
39
|
-
throw new Error('
|
|
37
|
+
export function defineSource(source) {
|
|
38
|
+
if (source === null || typeof source !== 'object') {
|
|
39
|
+
throw new Error('defineSource: expected a source object with a `sync` method');
|
|
40
40
|
}
|
|
41
|
-
if (typeof
|
|
42
|
-
throw new Error('
|
|
41
|
+
if (typeof source.sync !== 'function') {
|
|
42
|
+
throw new Error('defineSource: source must have a `sync(ctx)` function');
|
|
43
43
|
}
|
|
44
|
-
return
|
|
44
|
+
return source;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* A
|
|
48
|
-
* where the
|
|
49
|
-
* `
|
|
47
|
+
* A source authored inline as a single `sync` function, for the common case
|
|
48
|
+
* where the source has no other members. Equivalent to
|
|
49
|
+
* `defineSource({ sync })`.
|
|
50
50
|
*
|
|
51
|
-
* @typeParam C - The shape of the
|
|
52
|
-
* @param sync - The
|
|
53
|
-
* @returns A validated {@link
|
|
51
|
+
* @typeParam C - The shape of the source's typed `ctx.config` preferences.
|
|
52
|
+
* @param sync - The source's `sync(ctx)` implementation.
|
|
53
|
+
* @returns A validated {@link TroveSource} wrapping `sync`.
|
|
54
54
|
*/
|
|
55
55
|
export function defineSync(sync) {
|
|
56
|
-
return
|
|
56
|
+
return defineSource({ sync });
|
|
57
57
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@ontrove/sdk` — the thin standard library for authoring **Trove
|
|
3
|
-
* You write a `sync(ctx)` that fetches
|
|
2
|
+
* `@ontrove/sdk` — the thin standard library for authoring **Trove sources**.
|
|
3
|
+
* You write a `sync(ctx)` that fetches new content and returns documents; the
|
|
4
4
|
* SDK owns the document shape (which maps 1:1 onto `IngestDocumentInput`), the
|
|
5
5
|
* typed `ctx` capability object, the watermark/cursor model, the local-run
|
|
6
6
|
* harness the CLI drives, and manifest validation.
|
|
7
7
|
*
|
|
8
|
-
* It is the symmetric sibling of `@ontrove/mcp
|
|
9
|
-
*
|
|
10
|
-
* be
|
|
8
|
+
* It is the symmetric sibling of `@ontrove/mcp`, the toolkit-authoring library
|
|
9
|
+
* (every toolkit runs as a full MCP server on Trove's cloud): a source returns
|
|
10
|
+
* documents to be _stored_ (`defineSource` + `sync`); a toolkit's tools return
|
|
11
|
+
* results to be _read live_ (`defineMcpServer`).
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```ts
|
|
14
|
-
* import {
|
|
15
|
+
* import { defineSource } from '@ontrove/sdk';
|
|
15
16
|
*
|
|
16
|
-
* export default
|
|
17
|
+
* export default defineSource({
|
|
17
18
|
* async sync(ctx) {
|
|
18
19
|
* const res = await ctx.fetch('https://hn.algolia.com/api/v1/search?tags=front_page');
|
|
19
20
|
* const { hits } = await res.json();
|
|
@@ -32,8 +33,8 @@
|
|
|
32
33
|
*
|
|
33
34
|
* @module
|
|
34
35
|
*/
|
|
35
|
-
export {
|
|
36
|
-
export { isCredentialConfigKey, type ManifestValidationResult,
|
|
37
|
-
export { type RunOptions, type RunResult,
|
|
38
|
-
export type {
|
|
36
|
+
export { defineSource, defineSync } from './define.js';
|
|
37
|
+
export { isCredentialConfigKey, type ManifestValidationResult, validateSourceManifest, } from './manifest.js';
|
|
38
|
+
export { type RunOptions, type RunResult, runSource, } from './runtime.js';
|
|
39
|
+
export type { FetchLike, ManifestConfigField, SourceContentType, SourceContext, SourceDocument, SourceManifest, SourceSyncResult, TroveSource, Watermark, } from './types.js';
|
|
39
40
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,SAAS,GACV,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,SAAS,GACV,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@ontrove/sdk` — the thin standard library for authoring **Trove
|
|
3
|
-
* You write a `sync(ctx)` that fetches
|
|
2
|
+
* `@ontrove/sdk` — the thin standard library for authoring **Trove sources**.
|
|
3
|
+
* You write a `sync(ctx)` that fetches new content and returns documents; the
|
|
4
4
|
* SDK owns the document shape (which maps 1:1 onto `IngestDocumentInput`), the
|
|
5
5
|
* typed `ctx` capability object, the watermark/cursor model, the local-run
|
|
6
6
|
* harness the CLI drives, and manifest validation.
|
|
7
7
|
*
|
|
8
|
-
* It is the symmetric sibling of `@ontrove/mcp
|
|
9
|
-
*
|
|
10
|
-
* be
|
|
8
|
+
* It is the symmetric sibling of `@ontrove/mcp`, the toolkit-authoring library
|
|
9
|
+
* (every toolkit runs as a full MCP server on Trove's cloud): a source returns
|
|
10
|
+
* documents to be _stored_ (`defineSource` + `sync`); a toolkit's tools return
|
|
11
|
+
* results to be _read live_ (`defineMcpServer`).
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```ts
|
|
14
|
-
* import {
|
|
15
|
+
* import { defineSource } from '@ontrove/sdk';
|
|
15
16
|
*
|
|
16
|
-
* export default
|
|
17
|
+
* export default defineSource({
|
|
17
18
|
* async sync(ctx) {
|
|
18
19
|
* const res = await ctx.fetch('https://hn.algolia.com/api/v1/search?tags=front_page');
|
|
19
20
|
* const { hits } = await res.json();
|
|
@@ -32,6 +33,6 @@
|
|
|
32
33
|
*
|
|
33
34
|
* @module
|
|
34
35
|
*/
|
|
35
|
-
export {
|
|
36
|
-
export { isCredentialConfigKey,
|
|
37
|
-
export {
|
|
36
|
+
export { defineSource, defineSync } from './define.js';
|
|
37
|
+
export { isCredentialConfigKey, validateSourceManifest, } from './manifest.js';
|
|
38
|
+
export { runSource, } from './runtime.js';
|
package/dist/manifest.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* (see the
|
|
2
|
+
* Source manifest validation for `trove source validate`
|
|
3
|
+
* (see the sources manifest reference).
|
|
4
4
|
*
|
|
5
5
|
* Two checks live here:
|
|
6
6
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* `id` pattern (`^[a-z0-9-]+$`), and well-formedness of `config`.
|
|
9
9
|
* 2. **Credential-key lint** — the same spirit as the server-side
|
|
10
10
|
* `validateConfig` (`src/graphql/validate-config.ts`, invariant #6): a
|
|
11
|
-
*
|
|
11
|
+
* source's `config` holds **user preferences only, never credentials**.
|
|
12
12
|
* The cloud rejects writes whose config contains credential-shaped keys, so
|
|
13
13
|
* the SDK lints the manifest locally to catch the mistake before deploy. Auth
|
|
14
14
|
* material belongs in the (PROPOSED) `auth` block — surfaced from the macOS
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function isCredentialConfigKey(key: string): boolean;
|
|
30
30
|
/**
|
|
31
|
-
* The outcome of {@link
|
|
31
|
+
* The outcome of {@link validateSourceManifest}.
|
|
32
32
|
*/
|
|
33
33
|
export interface ManifestValidationResult {
|
|
34
34
|
/** True when no errors were found. */
|
|
@@ -37,7 +37,7 @@ export interface ManifestValidationResult {
|
|
|
37
37
|
errors: string[];
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Validate a
|
|
40
|
+
* Validate a source `manifest.json` for `trove source validate`.
|
|
41
41
|
*
|
|
42
42
|
* Checks required fields and the `id`/`version` patterns, validates the `config`
|
|
43
43
|
* descriptors, and runs the credential-key lint (rejecting credential-shaped
|
|
@@ -48,5 +48,5 @@ export interface ManifestValidationResult {
|
|
|
48
48
|
* @param manifest - The parsed manifest object to validate.
|
|
49
49
|
* @returns `{ valid, errors }` — `valid: true` with an empty `errors` array on success.
|
|
50
50
|
*/
|
|
51
|
-
export declare function
|
|
51
|
+
export declare function validateSourceManifest(manifest: unknown): ManifestValidationResult;
|
|
52
52
|
//# sourceMappingURL=manifest.d.ts.map
|
package/dist/manifest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AA+CH;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG1D;AAuCD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,sCAAsC;IACtC,KAAK,EAAE,OAAO,CAAC;IACf,iEAAiE;IACjE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AA+CH;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG1D;AAuCD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,sCAAsC;IACtC,KAAK,EAAE,OAAO,CAAC;IACf,iEAAiE;IACjE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,OAAO,GAAG,wBAAwB,CAkClF"}
|
package/dist/manifest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* (see the
|
|
2
|
+
* Source manifest validation for `trove source validate`
|
|
3
|
+
* (see the sources manifest reference).
|
|
4
4
|
*
|
|
5
5
|
* Two checks live here:
|
|
6
6
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* `id` pattern (`^[a-z0-9-]+$`), and well-formedness of `config`.
|
|
9
9
|
* 2. **Credential-key lint** — the same spirit as the server-side
|
|
10
10
|
* `validateConfig` (`src/graphql/validate-config.ts`, invariant #6): a
|
|
11
|
-
*
|
|
11
|
+
* source's `config` holds **user preferences only, never credentials**.
|
|
12
12
|
* The cloud rejects writes whose config contains credential-shaped keys, so
|
|
13
13
|
* the SDK lints the manifest locally to catch the mistake before deploy. Auth
|
|
14
14
|
* material belongs in the (PROPOSED) `auth` block — surfaced from the macOS
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* @module
|
|
21
21
|
*/
|
|
22
22
|
/**
|
|
23
|
-
* Credential-shaped key patterns that may NOT appear in a
|
|
23
|
+
* Credential-shaped key patterns that may NOT appear in a source's `config`
|
|
24
24
|
* (invariant #6). Mirrors the authoritative cloud deny-list in
|
|
25
25
|
* `src/graphql/validate-config.ts`. Matched case-insensitively and
|
|
26
26
|
* separator-insensitively as substrings, so `apiKey`, `api_key`, `access_token`,
|
|
@@ -99,11 +99,11 @@ function validateConfigBlock(config, errors) {
|
|
|
99
99
|
if (offending.length > 0) {
|
|
100
100
|
const unique = [...new Set(offending)];
|
|
101
101
|
errors.push(`manifest.config must not contain credential-shaped key(s): ${unique.join(', ')}. ` +
|
|
102
|
-
'
|
|
102
|
+
'Source credentials belong in the macOS Keychain (declared as `auth`), not in `config`.');
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
|
-
* Validate a
|
|
106
|
+
* Validate a source `manifest.json` for `trove source validate`.
|
|
107
107
|
*
|
|
108
108
|
* Checks required fields and the `id`/`version` patterns, validates the `config`
|
|
109
109
|
* descriptors, and runs the credential-key lint (rejecting credential-shaped
|
|
@@ -114,7 +114,7 @@ function validateConfigBlock(config, errors) {
|
|
|
114
114
|
* @param manifest - The parsed manifest object to validate.
|
|
115
115
|
* @returns `{ valid, errors }` — `valid: true` with an empty `errors` array on success.
|
|
116
116
|
*/
|
|
117
|
-
export function
|
|
117
|
+
export function validateSourceManifest(manifest) {
|
|
118
118
|
const errors = [];
|
|
119
119
|
if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest)) {
|
|
120
120
|
return { valid: false, errors: ['manifest must be a JSON object'] };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The local-run harness — what makes `trove
|
|
3
|
-
* work (
|
|
2
|
+
* The local-run harness — what makes `trove source dev` / `trove source test`
|
|
3
|
+
* work (sources/sdk-reference; the cursors guide).
|
|
4
4
|
*
|
|
5
|
-
* {@link
|
|
5
|
+
* {@link runSource} builds a {@link SourceContext} from a `{ config, cursor }`
|
|
6
6
|
* spec, invokes `sync(ctx)`, then normalizes and validates the result: it accepts
|
|
7
|
-
* either a `
|
|
8
|
-
* `id` (first occurrence wins, matching server-side `(
|
|
7
|
+
* either a `SourceSyncResult` or a bare `SourceDocument[]`, deduplicates by
|
|
8
|
+
* `id` (first occurrence wins, matching server-side `(feed, id)` dedup), and
|
|
9
9
|
* validates every document's required fields, surfacing problems clearly instead
|
|
10
10
|
* of pushing a malformed payload to the cloud.
|
|
11
11
|
*
|
|
12
12
|
* It is the symmetric sibling of `@ontrove/mcp`'s `dispatch`/`toFetchHandler`: that
|
|
13
|
-
* runs a tool call end-to-end without the hosted runtime; this runs a
|
|
13
|
+
* runs a tool call end-to-end without the hosted runtime; this runs a source
|
|
14
14
|
* sync end-to-end without the Mac app sync engine.
|
|
15
15
|
*
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
|
-
import type {
|
|
18
|
+
import type { FetchLike, SourceDocument, TroveSource, Watermark } from './types.js';
|
|
19
19
|
/**
|
|
20
|
-
* The options {@link
|
|
21
|
-
* source's stored config and current cursor; tests inject `fetch`,
|
|
22
|
-
* `now` for determinism.
|
|
20
|
+
* The options {@link runSource} builds a `ctx` from. The CLI passes the
|
|
21
|
+
* source's stored config and the feed's current cursor; tests inject `fetch`,
|
|
22
|
+
* `log`, and `now` for determinism.
|
|
23
23
|
*
|
|
24
|
-
* @typeParam C - The shape of the
|
|
24
|
+
* @typeParam C - The shape of the source's typed `ctx.config` preferences.
|
|
25
25
|
*/
|
|
26
26
|
export interface RunOptions<C = Record<string, unknown>> {
|
|
27
27
|
/** The source's preference values (no credentials). Defaults to `{}`. */
|
|
28
28
|
config?: C;
|
|
29
|
-
/** The
|
|
29
|
+
/** The feed's current watermark. Defaults to `{ type: 'none' }`. */
|
|
30
30
|
cursor?: Watermark;
|
|
31
31
|
/** The fetch implementation to expose as `ctx.fetch`. Defaults to global `fetch`. */
|
|
32
32
|
fetchImpl?: FetchLike;
|
|
@@ -36,13 +36,13 @@ export interface RunOptions<C = Record<string, unknown>> {
|
|
|
36
36
|
now?: () => Date;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* The outcome of {@link
|
|
39
|
+
* The outcome of {@link runSource}: the validated, deduped documents, the
|
|
40
40
|
* resolved cursor, and the captured log lines. Mirrors enough of what the cloud
|
|
41
|
-
* ingest reports for `trove
|
|
41
|
+
* ingest reports for `trove source test` to print a useful summary.
|
|
42
42
|
*/
|
|
43
43
|
export interface RunResult {
|
|
44
44
|
/** The validated, deduped documents `sync` returned. */
|
|
45
|
-
documents:
|
|
45
|
+
documents: SourceDocument[];
|
|
46
46
|
/** The cursor `sync` returned, or `{ type: 'none' }` if it returned none. */
|
|
47
47
|
cursor: Watermark;
|
|
48
48
|
/** Captured `ctx.log(...)` lines (when no custom `logSink` was supplied). */
|
|
@@ -51,20 +51,20 @@ export interface RunResult {
|
|
|
51
51
|
duplicatesSkipped: number;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* Run a
|
|
54
|
+
* Run a source's `sync` against a built `ctx` and collect/validate the result.
|
|
55
55
|
*
|
|
56
|
-
* This is the harness the CLI drives for `trove
|
|
57
|
-
* test`: it builds the {@link
|
|
56
|
+
* This is the harness the CLI drives for `trove source dev` / `trove source
|
|
57
|
+
* test`: it builds the {@link SourceContext} from `{ config, cursor }`, runs
|
|
58
58
|
* `sync(ctx)`, normalizes a bare-array return, validates every document's
|
|
59
59
|
* required fields (clear, indexed errors), and dedups by `id`. Errors thrown by
|
|
60
60
|
* `sync` itself propagate unchanged so the CLI can report a failed run exactly as
|
|
61
61
|
* the Mac app would.
|
|
62
62
|
*
|
|
63
|
-
* @typeParam C - The shape of the
|
|
64
|
-
* @param
|
|
63
|
+
* @typeParam C - The shape of the source's typed `ctx.config` preferences.
|
|
64
|
+
* @param source - The source whose `sync` to run.
|
|
65
65
|
* @param options - The `{ config, cursor }` spec plus test injection points.
|
|
66
66
|
* @returns The validated, deduped {@link RunResult}.
|
|
67
67
|
* @throws {Error} If `sync` throws, returns a malformed value, or a document fails validation.
|
|
68
68
|
*/
|
|
69
|
-
export declare function
|
|
69
|
+
export declare function runSource<C = Record<string, unknown>>(source: TroveSource<C>, options?: RunOptions<C>): Promise<RunResult>;
|
|
70
70
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,SAAS,EAET,cAAc,EAEd,WAAW,EACX,SAAS,EACV,MAAM,YAAY,CAAC;AAKpB;;;;;;GAMG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrD,yEAAyE;IACzE,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,oEAAoE;IACpE,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,qFAAqF;IACrF,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,wFAAwF;IACxF,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,wDAAwD;IACxD,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,6EAA6E;IAC7E,MAAM,EAAE,SAAS,CAAC;IAClB,6EAA6E;IAC7E,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;IAClB,mEAAmE;IACnE,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AA+ED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,SAAS,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,GAAE,UAAU,CAAC,CAAC,CAAM,GAC1B,OAAO,CAAC,SAAS,CAAC,CAgCpB"}
|