@niscorp/haptic 0.0.0-stage → 0.1.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/ARTIFACTS.md +319 -0
- package/DESIGN.md +79 -0
- package/LICENSE +202 -0
- package/README.md +77 -2
- package/STATUS.md +49 -0
- package/dist/artifact/fold.d.ts +1 -0
- package/dist/artifact/fold.js +10 -0
- package/dist/artifact/formats.d.ts +35 -0
- package/dist/artifact/formats.js +123 -0
- package/dist/artifact/grammar.d.ts +18 -0
- package/dist/artifact/grammar.js +37 -0
- package/dist/artifact/index.d.ts +12 -0
- package/dist/artifact/index.js +6 -0
- package/dist/artifact/prepare.d.ts +24 -0
- package/dist/artifact/prepare.js +210 -0
- package/dist/artifact/request.d.ts +15 -0
- package/dist/artifact/request.js +71 -0
- package/dist/artifact/schema.d.ts +300 -0
- package/dist/artifact/schema.js +219 -0
- package/dist/artifact/stage.d.ts +26 -0
- package/dist/artifact/stage.js +90 -0
- package/dist/artifact/walk.d.ts +56 -0
- package/dist/artifact/walk.js +324 -0
- package/dist/connector/default-profile.json +1 -0
- package/dist/connector/http-content-core.d.ts +5 -0
- package/dist/connector/http-content-core.js +62 -0
- package/dist/connector/http-transport.endpoint.d.ts +14 -0
- package/dist/connector/http-transport.endpoint.js +199 -0
- package/dist/connector/http.schema.d.ts +8 -0
- package/dist/connector/http.schema.js +21 -0
- package/dist/discovery/attempt.d.ts +33 -0
- package/dist/discovery/attempt.js +313 -0
- package/dist/discovery/author-output.d.ts +23 -0
- package/dist/discovery/author-output.js +91 -0
- package/dist/discovery/calls.d.ts +52 -0
- package/dist/discovery/calls.js +129 -0
- package/dist/discovery/discover.d.ts +57 -0
- package/dist/discovery/discover.js +186 -0
- package/dist/discovery/findings.d.ts +38 -0
- package/dist/discovery/findings.js +126 -0
- package/dist/discovery/index.d.ts +6 -0
- package/dist/discovery/index.js +2 -0
- package/dist/discovery/links.d.ts +19 -0
- package/dist/discovery/links.js +57 -0
- package/dist/discovery/lists.d.ts +11 -0
- package/dist/discovery/lists.js +42 -0
- package/dist/discovery/members.d.ts +15 -0
- package/dist/discovery/members.js +57 -0
- package/dist/discovery/model-transport.d.ts +33 -0
- package/dist/discovery/model-transport.js +177 -0
- package/dist/discovery/output-rejection.d.ts +15 -0
- package/dist/discovery/output-rejection.js +59 -0
- package/dist/discovery/output-rejection.json +28 -0
- package/dist/discovery/phrase.d.ts +4 -0
- package/dist/discovery/phrase.js +49 -0
- package/dist/discovery/profile.d.ts +45 -0
- package/dist/discovery/profile.js +75 -0
- package/dist/discovery/program.d.ts +30 -0
- package/dist/discovery/program.js +110 -0
- package/dist/discovery/prompts.d.ts +30 -0
- package/dist/discovery/prompts.js +66 -0
- package/dist/discovery/read.d.ts +45 -0
- package/dist/discovery/read.js +124 -0
- package/dist/discovery/rules.d.ts +27 -0
- package/dist/discovery/rules.js +292 -0
- package/dist/discovery/sections.d.ts +15 -0
- package/dist/discovery/sections.js +52 -0
- package/dist/discovery/view.d.ts +15 -0
- package/dist/discovery/view.js +143 -0
- package/dist/engine/contracts.d.ts +27 -0
- package/dist/engine/contracts.js +1 -0
- package/dist/engine/control.d.ts +9 -0
- package/dist/engine/control.js +18 -0
- package/dist/engine/default-profile.json +8 -0
- package/dist/engine/errors.d.ts +6 -0
- package/dist/engine/errors.js +10 -0
- package/dist/engine/json.d.ts +4 -0
- package/dist/engine/json.js +82 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/dist/migrations/index.d.ts +109 -0
- package/dist/migrations/index.js +3 -0
- package/dist/readers/headers.d.ts +1 -0
- package/dist/readers/headers.js +5 -0
- package/dist/readers/html/base-policy.d.ts +1 -0
- package/dist/readers/html/base-policy.js +64 -0
- package/dist/readers/html/base.d.ts +9 -0
- package/dist/readers/html/base.js +41 -0
- package/dist/readers/html/cells.d.ts +2 -0
- package/dist/readers/html/cells.js +48 -0
- package/dist/readers/html/decode.d.ts +5 -0
- package/dist/readers/html/decode.js +26 -0
- package/dist/readers/html/default-profile.json +14 -0
- package/dist/readers/html/fields.d.ts +33 -0
- package/dist/readers/html/fields.js +107 -0
- package/dist/readers/html/index.d.ts +7 -0
- package/dist/readers/html/index.js +6 -0
- package/dist/readers/html/locator.d.ts +6 -0
- package/dist/readers/html/locator.js +81 -0
- package/dist/readers/html/profile.schema.d.ts +23 -0
- package/dist/readers/html/profile.schema.js +56 -0
- package/dist/readers/html/structure.d.ts +30 -0
- package/dist/readers/html/structure.js +217 -0
- package/dist/readers/xml/decode.d.ts +5 -0
- package/dist/readers/xml/decode.js +41 -0
- package/dist/readers/xml/default-profile.json +8 -0
- package/dist/readers/xml/index.d.ts +9 -0
- package/dist/readers/xml/index.js +59 -0
- package/dist/readers/xml/profile.schema.d.ts +11 -0
- package/dist/readers/xml/profile.schema.js +14 -0
- package/dist/render/child.d.mts +1 -0
- package/dist/render/child.mjs +16 -0
- package/dist/render/index.d.ts +3 -0
- package/dist/render/index.js +2 -0
- package/dist/render/render.d.ts +17 -0
- package/dist/render/render.js +89 -0
- package/dist/render/signal.d.ts +1 -0
- package/dist/render/signal.js +16 -0
- package/dist/search/duckduckgo.d.ts +2 -0
- package/dist/search/duckduckgo.js +49 -0
- package/dist/search/image-challenge.d.ts +20 -0
- package/dist/search/image-challenge.js +124 -0
- package/dist/search/image-choice/choices.d.ts +6 -0
- package/dist/search/image-choice/choices.js +15 -0
- package/dist/search/image-choice/contracts.d.ts +44 -0
- package/dist/search/image-choice/contracts.js +45 -0
- package/dist/search/image-choice/imagescript-profile.json +11 -0
- package/dist/search/image-choice/imagescript.d.ts +52 -0
- package/dist/search/image-choice/imagescript.js +81 -0
- package/dist/search/image-choice/reader.d.ts +2 -0
- package/dist/search/image-choice/reader.js +60 -0
- package/dist/search/index.d.ts +6 -0
- package/dist/search/index.js +4 -0
- package/dist/search/prompts.d.ts +11 -0
- package/dist/search/prompts.js +12 -0
- package/dist/search/provider.d.ts +108 -0
- package/dist/search/provider.js +84 -0
- package/dist/search/search.d.ts +165 -0
- package/dist/search/search.js +329 -0
- package/dist/web/default-profile.json +8 -0
- package/dist/web/html.d.ts +18 -0
- package/dist/web/html.js +44 -0
- package/dist/web/source.d.ts +24 -0
- package/dist/web/source.js +36 -0
- package/dist/web/transport.d.ts +28 -0
- package/dist/web/transport.js +102 -0
- package/package.json +119 -3
package/ARTIFACTS.md
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# Writing an artifact
|
|
2
|
+
|
|
3
|
+
An artifact is JSON data: where the items are on a page, which values to take from each, and how to shape the result. Haptic runs it with no model. Discovery writes artifacts from an instruction, but anyone can write one: a person, a model given this page, or a tool. Haptic checks it and runs it the same way.
|
|
4
|
+
|
|
5
|
+
## The smallest artifact
|
|
6
|
+
|
|
7
|
+
The free books on `https://www.perl.org/books/library.html`, written by hand:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"policy": {
|
|
12
|
+
"maxPages": 1,
|
|
13
|
+
"maxRedirects": 3,
|
|
14
|
+
"stripFragments": true,
|
|
15
|
+
"accept": { "statuses": [200] }
|
|
16
|
+
},
|
|
17
|
+
"stages": [
|
|
18
|
+
{
|
|
19
|
+
"kind": "records",
|
|
20
|
+
"format": "html",
|
|
21
|
+
"render": false,
|
|
22
|
+
"selector": "div.col-12",
|
|
23
|
+
"fields": {
|
|
24
|
+
"title": { "selector": "h3", "attribute": null },
|
|
25
|
+
"link": { "selector": "p.description a", "attribute": "href" }
|
|
26
|
+
},
|
|
27
|
+
"required": ["title", "link"],
|
|
28
|
+
"where": { "in": "text", "contains": "the entire book free online" },
|
|
29
|
+
"limit": null
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"mapping": {
|
|
33
|
+
"$map": {
|
|
34
|
+
"over": { "$ref": "$.records" },
|
|
35
|
+
"as": "r",
|
|
36
|
+
"body": {
|
|
37
|
+
"title": { "$get": { "from": { "$var": "r" }, "path": ["fields", "title"] } },
|
|
38
|
+
"link": { "$get": { "from": { "$var": "r" }, "path": ["fields", "link"] } }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"outputSchema": {
|
|
43
|
+
"type": "array",
|
|
44
|
+
"items": { "type": "object", "required": ["title", "link"] }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Each `div.col-12` is one record. Records without a title or link are left out, and so are records whose text does not mention "the entire book free online". The mapping turns each remaining record into `{ title, link }`. `stamp` can be left out: an artifact without one is read as written for the current grammar, and `prepareArtifact` adds the current stamp.
|
|
50
|
+
|
|
51
|
+
## Check, inspect, run
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { createWebTransport, prepareArtifact } from '@niscorp/haptic';
|
|
55
|
+
|
|
56
|
+
const prepared = prepareArtifact(artifact); // throws ArtifactError naming every problem it finds
|
|
57
|
+
const web = createWebTransport();
|
|
58
|
+
const seen = await prepared.inspect({ url }, { web, signal: AbortSignal.timeout(60_000) });
|
|
59
|
+
web.close();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
An artifact with a `request` is run with its inputs instead of an address: `prepared.inspect({ inputs: { query: 'haptic feedback' } }, …)` (see [Requests, inputs and more pages](#requests-inputs-and-more-pages)).
|
|
63
|
+
|
|
64
|
+
`prepareArtifact` checks the artifact once, in this order, and stops at the first check that fails. The error lists every problem that check found, each with its place in the artifact:
|
|
65
|
+
|
|
66
|
+
| `ArtifactError.code` | What is wrong | Example message |
|
|
67
|
+
| -------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `UPGRADE` | The `stamp` names a grammar version that cannot be upgraded. | |
|
|
69
|
+
| `GRAMMAR` | A key is missing, unknown or of the wrong type, or `required` or `where.in` names a field the stage lacks. | `stages.0.where.in: "price" is not a field or "text"; this stage's fields are "title", "link"` |
|
|
70
|
+
| `SELECTOR` | A CSS selector the HTML reader cannot run, or an XPath expression that does not parse. | `stages.0.fields.title.selector: "h3[" is not CSS the reader runs (…)` |
|
|
71
|
+
| `PROGRAM` | The mapping or a reference program is not a valid Prism program. | `mapping: $mapp: Not a Prism op. …` |
|
|
72
|
+
| `OUTPUT_SCHEMA` | `outputSchema` is not a JSON Schema. | |
|
|
73
|
+
|
|
74
|
+
`inspect` runs the artifact exactly like `run`, but it does not throw when the run stops. It returns:
|
|
75
|
+
|
|
76
|
+
- `pages`: one entry per page at each stage, in order. A page the run started from also gives the `values` it was requested with, or the `link` that reached it.
|
|
77
|
+
- A link or reference stage gives the addresses that page led to. For a link stage, it also gives `selected`, the number of elements its selector matched.
|
|
78
|
+
- A record stage gives these counts:
|
|
79
|
+
- `selected`: elements its selector matched;
|
|
80
|
+
- `missing`: elements left out because a `required` field had no value, counted under the first such field;
|
|
81
|
+
- `failedWhere`: elements left out by `where`;
|
|
82
|
+
- `duplicates`: records whose fields equal an earlier record's;
|
|
83
|
+
- `pastLimit`: elements not read because `limit` was reached;
|
|
84
|
+
- `kept`: records kept;
|
|
85
|
+
- `empty`: for each field, how many kept records have no value for it.
|
|
86
|
+
- `records`: the records the mapping received. These are there even when the mapping failed or its result did not fit `outputSchema`.
|
|
87
|
+
- `result`: what `run` returns, or `null` when the run stopped.
|
|
88
|
+
- `error`: why the run stopped, with the code of the error that stopped it, or `null`. Examples: `INPUT` (the run was not given what the artifact needs), `STATUS` (an HTTP status not in `policy.accept.statuses`), `NO_PAGES` (a link stage found nothing to follow), `MORE` (`request.more` failed, or answered something other than start values or `null`), `PROGRAM` (the mapping failed on these records), `SCHEMA` (the result does not fit `outputSchema`).
|
|
89
|
+
|
|
90
|
+
A selector that matches nothing shows as `selected: 0`. A field rule that matches nothing in the kept records shows as `empty` equal to `kept`.
|
|
91
|
+
|
|
92
|
+
## Reference
|
|
93
|
+
|
|
94
|
+
### Top level
|
|
95
|
+
|
|
96
|
+
| Key | Meaning |
|
|
97
|
+
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
98
|
+
| `stamp` | Optional. The grammar versions it was written for, e.g. `{ "nisc.haptic": 1, "nisc.prism": 3 }`. |
|
|
99
|
+
| `inputs` | Optional. Named strings a run is given, each `{ "description" }` (below). |
|
|
100
|
+
| `request` | Optional. The first request, as a template; an artifact with one is run without an address (below). |
|
|
101
|
+
| `next` | Optional. `{ "selector", "attribute" }`: the link to the next page of the pages the run starts from (below). |
|
|
102
|
+
| `policy` | Limits of one run (below). |
|
|
103
|
+
| `stages` | One stage per level of pages: link or reference stages first, exactly one record stage last. |
|
|
104
|
+
| `mapping` | A [Prism](https://github.com/moccadroid/niscorp/blob/main/packages/prism/DOCS.md) program over `{ records }`; its result is the run's `data`. |
|
|
105
|
+
| `outputSchema` | JSON Schema the result must fit; `{}` accepts anything. |
|
|
106
|
+
|
|
107
|
+
`policy`: `maxPages` (pages one run may fetch, the start page included), `maxRedirects` (per page), `stripFragments` (drop `#…` from followed addresses), `accept.statuses` (e.g. `[200]`), optional `accept.mediaTypes` (accepted content types; absent or `null` accepts any), optional `maxResources` (files a run may download; absent means none).
|
|
108
|
+
|
|
109
|
+
### HTML stages
|
|
110
|
+
|
|
111
|
+
A **record stage** (`"kind": "records", "format": "html"`):
|
|
112
|
+
|
|
113
|
+
| Key | Meaning |
|
|
114
|
+
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `render` | `true` runs the page's own inline scripts before reading it (no network; for addresses or content that a script writes). |
|
|
116
|
+
| `selector` | CSS for one record. |
|
|
117
|
+
| `fields` | Field name to a field rule (below). |
|
|
118
|
+
| `required` | Field names; a record without a non-empty value for one of them is left out. |
|
|
119
|
+
| `where` | `null`, or `{ "in": <field name or "text">, "contains": <phrase> }`: kept when that value contains the phrase, with case, whitespace, dashes and quotes ignored. |
|
|
120
|
+
| `limit` | `null`, or the first N records of each page that pass `required` and `where`. |
|
|
121
|
+
| `resources` | Optional `{ "selector", "attribute" }`: files this page leads to, downloaded up to `policy.maxResources`. |
|
|
122
|
+
|
|
123
|
+
A record stage also leaves out every record whose fields all equal an earlier record's (one link behind its text, its image and its file name is one item).
|
|
124
|
+
|
|
125
|
+
A **field rule**: `selector` (CSS inside the record; `:scope` is the record itself; a list like `"p, li"` is allowed), `attribute` (`null` reads the text; a name reads that attribute, and `href` values are resolved to absolute addresses), optional `"list": true` (every match instead of the first), optional `closest` (CSS for the nearest element at or above the record to run the selector in instead, e.g. the table row a cell belongs to).
|
|
126
|
+
|
|
127
|
+
A **link stage** (`"kind": "links", "format": "html"`): `render`, `selector` (CSS for one link record), `link` (a field rule reading the address), `limit` (`null` or how many distinct addresses not yet visited to follow), optional `resources`. Its pages' addresses become the next stage's pages.
|
|
128
|
+
|
|
129
|
+
CSS is what [css-select](https://github.com/fb55/css-select) runs, limited to structure: tags, classes, ids, attributes, combinators, and the pseudo-classes `:first-child`, `:last-child`, `:only-child`, `:first-of-type`, `:last-of-type`, `:only-of-type`, `:nth-child()`, `:nth-last-child()`, `:nth-of-type()`, `:nth-last-of-type()`, `:not()`, `:has()`, `:contains()`, `:icontains()`, `:empty`, `:scope`. Merged table cells (`rowspan`) are copied into every row they cover before selectors run.
|
|
130
|
+
|
|
131
|
+
### XML and JSON stages
|
|
132
|
+
|
|
133
|
+
- **XML record stage** (`"kind": "records", "format": "xml"`): `selector` (XPath 1.0 selecting the record elements), `namespaces` (prefix to namespace URI; `{}` for XML without namespaces), `fields` (field name to an XPath expression relative to the record), `required`, `where`, `limit`.
|
|
134
|
+
- **XML reference stage** (`"kind": "references", "format": "xml"`): `selector`, `namespaces`, `fields` as above, `references` (a Prism program over `{ records }` returning `{ links?: [address], resources?: [address] }`), `limit`.
|
|
135
|
+
- **JSON record stage** (`"kind": "records", "format": "json"`): no other keys. Each page's whole document is one record.
|
|
136
|
+
- **JSON reference stage** (`"kind": "references", "format": "json"`): `references` (a Prism program over `{ document }` returning `{ links?, resources? }`), `limit`.
|
|
137
|
+
|
|
138
|
+
### What the mapping receives
|
|
139
|
+
|
|
140
|
+
`{ records }`: the last stage's records from all its pages, in page order.
|
|
141
|
+
|
|
142
|
+
- HTML record: `{ sourceUrl, text, attributes, fields }`. `text` is the record's text content as it appears in the page. `attributes` are the record element's own attributes. `fields` has one value per field rule: a string or `null`, or a list for `list` fields. Text values have whitespace collapsed. `href` values are absolute addresses.
|
|
143
|
+
- XML record: `{ sourceUrl, text, fields }`; a field is a list of texts for a node-set, or a string, number or boolean.
|
|
144
|
+
- JSON record: `{ sourceUrl, document }`.
|
|
145
|
+
|
|
146
|
+
### What a run returns
|
|
147
|
+
|
|
148
|
+
`{ data, records, visited, redirects, limited, resources, emptyPages, broken }`. `limited` means a stage had more pages than `policy.maxPages` left room for. `broken` means a page of the last stage gave no records, so the artifact no longer fits that page. A page that continues the start and gives nothing new only ends the paging.
|
|
149
|
+
|
|
150
|
+
### Requests, inputs and more pages
|
|
151
|
+
|
|
152
|
+
A run starts from the address it is given. An artifact may instead carry its **first request**, filled with **inputs** the run is given. The pages a run starts from may also **continue**, either by a next link or by the next request's values, and the first stage reads all of them. None of this needs a browser: these are plain requests.
|
|
153
|
+
|
|
154
|
+
- `inputs`: name to `{ "description" }`. A run must give every input, as a string, and no other: `run({ inputs: { query: "…" } }, …)`.
|
|
155
|
+
- `request`:
|
|
156
|
+
- `method`: `"GET"` or `"POST"`.
|
|
157
|
+
- `url`.
|
|
158
|
+
- `headers`, optional: on top of the transport's own; for a header named in both, the artifact's wins.
|
|
159
|
+
- `body`, optional and with POST only: `{ "form": { name: value } }` (sent form-encoded) or `{ "json": value }` (sent as JSON).
|
|
160
|
+
- `start`, optional: the values `more` changes, each a string or a number.
|
|
161
|
+
- `more`, optional (below).
|
|
162
|
+
|
|
163
|
+
How values fill the template:
|
|
164
|
+
- `{name}` in `url` and in header values is replaced by that input or start value. In `url` it is percent-encoded.
|
|
165
|
+
- In a body, only a string that is exactly `"{name}"` is replaced, by the value itself: `"first": "{n}"` with `n = 10` sends `10`. Every other string goes as written. So a GraphQL query, full of braces, is never touched; put its variables in `json.variables`.
|
|
166
|
+
- A redirect after a POST: 301, 302 and 303 are fetched with GET and no body; 307 and 308 send the request again.
|
|
167
|
+
- `more`: a Prism program over `{ document, headers, values, url }` of the page just read. `document` is its JSON, or `null`; each header is a list. It answers `null` to stop, or the start values to change, and the request is filled with them and sent again. A counter, an offset and a cursor from the answer are all this one program.
|
|
168
|
+
- `next`: `{ "selector", "attribute" }` over the whole page, when the first stage is HTML. It gives the next page's address, for pages whose next address can't be counted, such as a cursor in the link. An artifact uses `next` or `more`, not both. `more` belongs to `request`, so an artifact run from an address continues only by `next`. Give a JSON source that pages by a value a `request`.
|
|
169
|
+
|
|
170
|
+
Paging stops at the first of these:
|
|
171
|
+
- no next link;
|
|
172
|
+
- `more` answers `null`;
|
|
173
|
+
- the next request was already sent this run;
|
|
174
|
+
- a page gives nothing the first stage hasn't already read: no new record, the same JSON document, or no new address;
|
|
175
|
+
- `policy.maxPages`, which also sets `limited`.
|
|
176
|
+
|
|
177
|
+
A record already read on an earlier page of the start is left out and counted as a `duplicate`. When the first stage is a link stage, its index pages continue until they hold the addresses that its `limit` and `maxPages` leave room for.
|
|
178
|
+
|
|
179
|
+
Hacker News, three pages by the next link:
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"next": { "selector": "a.morelink", "attribute": "href" },
|
|
184
|
+
"policy": { "maxPages": 3, "maxRedirects": 3, "stripFragments": true, "accept": { "statuses": [200] } },
|
|
185
|
+
"stages": [
|
|
186
|
+
{
|
|
187
|
+
"kind": "records",
|
|
188
|
+
"format": "html",
|
|
189
|
+
"render": false,
|
|
190
|
+
"selector": "tr.athing",
|
|
191
|
+
"fields": {
|
|
192
|
+
"title": { "selector": ".titleline > a", "attribute": null },
|
|
193
|
+
"link": { "selector": ".titleline > a", "attribute": "href" }
|
|
194
|
+
},
|
|
195
|
+
"required": ["title"],
|
|
196
|
+
"where": null,
|
|
197
|
+
"limit": null
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
"mapping": {
|
|
201
|
+
"$map": {
|
|
202
|
+
"over": { "$ref": "$.records" },
|
|
203
|
+
"as": "r",
|
|
204
|
+
"body": {
|
|
205
|
+
"title": { "$get": { "from": { "$var": "r" }, "path": ["fields", "title"] } },
|
|
206
|
+
"link": { "$get": { "from": { "$var": "r" }, "path": ["fields", "link"] } }
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
"outputSchema": { "type": "array" }
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Run with `{ url: "https://news.ycombinator.com/" }`: 30 stories a page, 90 in all, `limited: true`.
|
|
215
|
+
|
|
216
|
+
dev.to's feed, a JSON page counter:
|
|
217
|
+
|
|
218
|
+
```json
|
|
219
|
+
{
|
|
220
|
+
"request": {
|
|
221
|
+
"method": "GET",
|
|
222
|
+
"url": "https://dev.to/search/feed_content?per_page=15&page={page}&sort_by=hotness_score&sort_direction=desc&class_name=Article",
|
|
223
|
+
"start": { "page": 0 },
|
|
224
|
+
"more": {
|
|
225
|
+
"$case": {
|
|
226
|
+
"branches": [{ "when": { "$empty": { "$ref": "$.document.result" } }, "then": { "$const": null } }],
|
|
227
|
+
"else": { "page": { "$add": [{ "$ref": "$.values.page" }, 1] } }
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
"policy": { "maxPages": 5, "maxRedirects": 3, "stripFragments": true, "accept": { "statuses": [200] } },
|
|
232
|
+
"stages": [{ "kind": "records", "format": "json" }],
|
|
233
|
+
"mapping": {
|
|
234
|
+
"$flatMap": {
|
|
235
|
+
"over": { "$ref": "$.records" },
|
|
236
|
+
"as": "r",
|
|
237
|
+
"body": {
|
|
238
|
+
"$map": {
|
|
239
|
+
"over": { "$get": { "from": { "$var": "r" }, "path": ["document", "result"] } },
|
|
240
|
+
"as": "a",
|
|
241
|
+
"body": {
|
|
242
|
+
"title": { "$get": { "from": { "$var": "a" }, "path": ["title"] } },
|
|
243
|
+
"link": { "$fill": { "phrase": "https://dev.to{path}", "slots": { "path": { "$get": { "from": { "$var": "a" }, "path": ["path"] } } } } }
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
"outputSchema": { "type": "array" }
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Run with `{}`: pages 0 to 4, 15 articles each, `limited: true`. Without the cap it stops at the first page whose `result` is empty.
|
|
254
|
+
|
|
255
|
+
A search form, posted with an input:
|
|
256
|
+
|
|
257
|
+
```json
|
|
258
|
+
{
|
|
259
|
+
"inputs": { "query": { "description": "What to search for, in words." } },
|
|
260
|
+
"request": { "method": "POST", "url": "https://html.duckduckgo.com/html/", "body": { "form": { "q": "{query}" } } },
|
|
261
|
+
"policy": { "maxPages": 1, "maxRedirects": 3, "stripFragments": true, "accept": { "statuses": [200] } },
|
|
262
|
+
"stages": [
|
|
263
|
+
{
|
|
264
|
+
"kind": "records",
|
|
265
|
+
"format": "html",
|
|
266
|
+
"render": false,
|
|
267
|
+
"selector": ".result",
|
|
268
|
+
"fields": {
|
|
269
|
+
"title": { "selector": "a.result__a", "attribute": null },
|
|
270
|
+
"link": { "selector": "a.result__a", "attribute": "href" },
|
|
271
|
+
"snippet": { "selector": ".result__snippet", "attribute": null }
|
|
272
|
+
},
|
|
273
|
+
"required": ["title", "link"],
|
|
274
|
+
"where": null,
|
|
275
|
+
"limit": null
|
|
276
|
+
}
|
|
277
|
+
],
|
|
278
|
+
"mapping": {
|
|
279
|
+
"$map": {
|
|
280
|
+
"over": { "$ref": "$.records" },
|
|
281
|
+
"as": "r",
|
|
282
|
+
"body": {
|
|
283
|
+
"title": { "$get": { "from": { "$var": "r" }, "path": ["fields", "title"] } },
|
|
284
|
+
"link": { "$get": { "from": { "$var": "r" }, "path": ["fields", "link"] } },
|
|
285
|
+
"snippet": { "$get": { "from": { "$var": "r" }, "path": ["fields", "snippet"] } }
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
"outputSchema": { "type": "array" }
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Run with `{ inputs: { query: "haptic feedback" } }`.
|
|
294
|
+
|
|
295
|
+
## Patterns
|
|
296
|
+
|
|
297
|
+
- **The record holds every field.** The record selector picks the smallest element that contains all of an item's fields. When a post's title sits outside its `<article>`, the record is the element around both, e.g. `main`.
|
|
298
|
+
- **The record is the value.** When each item is a single element, such as one link, select that element as the record and read it with `"selector": ":scope"`: `{ "selector": ":scope", "attribute": "href" }` gives its address and `{ "selector": ":scope", "attribute": null }` gives its text.
|
|
299
|
+
- **Records found by what comes before them.** Combinators work across the page. `h4:contains("Legacy versions") ~ table a` gives the links in the tables after that heading. `center:has(h4:contains("Legacy versions")) ~ table a` does the same when the heading is wrapped in another element. `a[href$=".tar.gz"]` keeps only addresses that end that way.
|
|
300
|
+
- **A list field goes through as a list.** `{ "$get": { "from": { "$var": "r" }, "path": ["fields", "body"] } }` on a `list` field gives an array of strings. Each value has its whitespace collapsed, so a code block becomes one line.
|
|
301
|
+
- **A result that is not objects.** A `$map` body can be a single value. With `"body": { "$get": { "from": { "$var": "r" }, "path": ["fields", "link"] } }`, the result is a list of addresses.
|
|
302
|
+
- **Keep some records in the mapping** when `where` cannot say which ones. Wrap `$.records` in `$filter` and map over that:
|
|
303
|
+
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"$filter": {
|
|
307
|
+
"over": { "$ref": "$.records" },
|
|
308
|
+
"as": "r",
|
|
309
|
+
"when": {
|
|
310
|
+
"$endsWith": {
|
|
311
|
+
"value": { "$get": { "from": { "$var": "r" }, "path": ["fields", "link"] } },
|
|
312
|
+
"suffix": { "$const": ".tar.gz" }
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Comparing, numbers from text (`$toNumber`), splitting (`$split`), dates and local variables (`$with`) are all Prism ops. They are listed in [Prism's DOCS.md](https://github.com/moccadroid/niscorp/blob/main/packages/prism/DOCS.md).
|
package/DESIGN.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Haptic design
|
|
2
|
+
|
|
3
|
+
Discovery asks a model small questions that code can check, and writes what it learned as data. The artifact holds only that data (selectors, Prism programs, an output schema, crawl limits); Haptic's runtime executes it, the way Prism executes a config. Model calls go through signal, every checked model question is a cortex agent, Prism shapes the data, Strata versions the grammar.
|
|
4
|
+
|
|
5
|
+
## The artifact (`nisc.haptic` grammar, version 0)
|
|
6
|
+
|
|
7
|
+
Perl's free online books, as discovery wrote it (`tests/fixtures/discovery/perl.json`):
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"stamp": { "nisc.haptic": 0, "nisc.prism": 3 },
|
|
12
|
+
"policy": {
|
|
13
|
+
"maxPages": 21,
|
|
14
|
+
"maxRedirects": 3,
|
|
15
|
+
"stripFragments": true,
|
|
16
|
+
"accept": { "statuses": [200] }
|
|
17
|
+
},
|
|
18
|
+
"stages": [
|
|
19
|
+
{
|
|
20
|
+
"kind": "records",
|
|
21
|
+
"format": "html",
|
|
22
|
+
"render": false,
|
|
23
|
+
"selector": "div.col-12",
|
|
24
|
+
"fields": {
|
|
25
|
+
"title": { "selector": "h3", "attribute": null },
|
|
26
|
+
"link": { "selector": "p.description a", "attribute": "href" }
|
|
27
|
+
},
|
|
28
|
+
"required": ["title", "link"],
|
|
29
|
+
"where": { "in": "text", "contains": "the entire book free online" },
|
|
30
|
+
"limit": null
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"mapping": { "$map": { "over": { "$ref": "$.records" }, "as": "r", "body": { "…": "…" } } },
|
|
34
|
+
"outputSchema": { "type": "array", "items": { "…": "…" } }
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- **Stages** run in order, one per level of pages: link or reference stages first, one record stage last. A run starts from the address it is given, or from the artifact's request filled with its inputs; the first stage reads that page and the pages that continue it (a next link, or the next request's values). The program sees `{ records }`, the last level's records from all pages in page order. [ARTIFACTS.md](ARTIFACTS.md) has every key, what a record holds, what a run returns, the check errors and `inspect`.
|
|
39
|
+
- **Versions**: `prepareArtifact` upgrades an older stamp through Strata (`HAPTIC_SEQUENCE` with Prism's sequence) before checking it. A change to the artifact schema appends a migration; `pnpm check:grammars` at the repository root holds the grammar to its snapshot and upgrades the captured artifacts in `strata/corpus/haptic`.
|
|
40
|
+
|
|
41
|
+
## Discovery
|
|
42
|
+
|
|
43
|
+
One entry point, `discover`, one module per step (`src/discovery/`):
|
|
44
|
+
|
|
45
|
+
| Step | Module | Model |
|
|
46
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------------------------------------------------------------------- |
|
|
47
|
+
| The page as numbered text lines; each line knows its element | `view.ts` | — |
|
|
48
|
+
| A text view over 64 KB: Jev picks the section to read | `sections.ts` | Jev, one choice |
|
|
49
|
+
| **Read**: cite up to 5 example items by line, count them, the limit asked for, or the links to follow and what to take from each linked page | `read.ts` | 120b, cortex agent; code checks every citation and sends the problems back |
|
|
50
|
+
| The link rule for the cited links; the next level's task without line numbers | `links.ts` | — |
|
|
51
|
+
| Record and field rules that give every cited example; the list nearest Read's count | `rules.ts`, `lists.ts` | field rules from 120b only when code finds none |
|
|
52
|
+
| Which uncited records answer the instruction | `members.ts` | Jev, one yes/no per record, 25 per call |
|
|
53
|
+
| One phrase that keeps those and drops the rest: the stage's `where` | `phrase.ts` | — |
|
|
54
|
+
| The program: a copy of the fields when nothing is left to filter, else Prism's mapping agent, checked against the examples and asked once to match the labels | `program.ts` | 120b, Prism's published agent |
|
|
55
|
+
| Findings: cited examples missing or lost, label mismatches, "N items, the reader counted M" | `findings.ts` | — |
|
|
56
|
+
| Rendering: when a level has 3+ links sharing one address with different texts (a script sets the real addresses), every page of the level is rendered | `../render/` | — |
|
|
57
|
+
| One attempt through the levels | `attempt.ts` | — |
|
|
58
|
+
| The ladder: an attempt at low effort; a stop or a finding other than the count runs it again at high; the first stands unless the second is strictly better. Then the artifact runs once on fresh pages with no model (the trial) | `discover.ts` | — |
|
|
59
|
+
|
|
60
|
+
Every model call goes through one module (`calls.ts`): it counts tokens, stops new calls at the input-token cap (400k per discovery), allows 250 Jev questions per attempt (one per record labelled or section chosen; up to 25 records go in one call), treats an empty provider reply as no answer, and reports a provider rate-limit block as `blocked`. Every text a model reads is in `prompts.ts`, word for word as approved.
|
|
61
|
+
|
|
62
|
+
## Search
|
|
63
|
+
|
|
64
|
+
`search` (`src/search/`): the provider page for the query; its image challenge when one appears (`image-challenge.ts`: fetch the tiles, one Jev question per tile, post the chosen tiles and the success form, follow the redirects within the allowed origins); the results unwrapped and de-duplicated; a cortex agent ranks them; `discover` runs on each in order, each spending one follow slot. When the queue is spent, follow slots and rewrites remain and too few sources are usable, a cortex agent rewrites the query. A failure in a later round becomes `continuationError` when a source is already usable. A provider is data (`SearchProviderSchema`); `duckduckgo` is the shipped one.
|
|
65
|
+
|
|
66
|
+
## Rendering
|
|
67
|
+
|
|
68
|
+
jsdom runs the page's own inline scripts with no network and no external files, 600 ms for timers. It runs in a child process under Node's permission model (it reads only its own folder and jsdom's, writes nothing, starts no process), with an empty environment, killed after each page or at 15 s. A page that cannot be rendered is read as fetched. Node's permission model does not close the network; a host that needs that wraps the process in an OS sandbox.
|
|
69
|
+
|
|
70
|
+
## Modules
|
|
71
|
+
|
|
72
|
+
| Module | Question it answers |
|
|
73
|
+
| ----------------------------- | -------------------------------------------------------------------------------- |
|
|
74
|
+
| `artifact` | What is an artifact, and how does one run with no model? |
|
|
75
|
+
| `web`, `connector`, `readers` | How are pages fetched and their bytes read (bounded HTTP, HTML and XML readers)? |
|
|
76
|
+
| `render` | When and how does a page run its own scripts? |
|
|
77
|
+
| `discovery` | How does an instruction and an address become an artifact? |
|
|
78
|
+
| `search` | How does an instruction alone become artifacts for several sources? |
|
|
79
|
+
| `migrations` | Which grammar and schemas describe a stored artifact? |
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|