@sapiom/tools 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/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/cjs/_client/index.d.ts +68 -0
- package/dist/cjs/_client/index.d.ts.map +1 -0
- package/dist/cjs/_client/index.js +115 -0
- package/dist/cjs/_client/index.js.map +1 -0
- package/dist/cjs/agent/index.d.ts +90 -0
- package/dist/cjs/agent/index.d.ts.map +1 -0
- package/dist/cjs/agent/index.js +108 -0
- package/dist/cjs/agent/index.js.map +1 -0
- package/dist/cjs/client.d.ts +51 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +50 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +59 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/repositories/index.d.ts +59 -0
- package/dist/cjs/repositories/index.d.ts.map +1 -0
- package/dist/cjs/repositories/index.js +107 -0
- package/dist/cjs/repositories/index.js.map +1 -0
- package/dist/cjs/sandboxes/index.d.ts +67 -0
- package/dist/cjs/sandboxes/index.d.ts.map +1 -0
- package/dist/cjs/sandboxes/index.js +255 -0
- package/dist/cjs/sandboxes/index.js.map +1 -0
- package/dist/cjs/sandboxes/types.d.ts +111 -0
- package/dist/cjs/sandboxes/types.d.ts.map +1 -0
- package/dist/cjs/sandboxes/types.js +3 -0
- package/dist/cjs/sandboxes/types.js.map +1 -0
- package/dist/esm/_client/index.d.ts +68 -0
- package/dist/esm/_client/index.d.ts.map +1 -0
- package/dist/esm/_client/index.js +110 -0
- package/dist/esm/_client/index.js.map +1 -0
- package/dist/esm/agent/index.d.ts +90 -0
- package/dist/esm/agent/index.d.ts.map +1 -0
- package/dist/esm/agent/index.js +103 -0
- package/dist/esm/agent/index.js.map +1 -0
- package/dist/esm/client.d.ts +51 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +47 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/repositories/index.d.ts +59 -0
- package/dist/esm/repositories/index.d.ts.map +1 -0
- package/dist/esm/repositories/index.js +99 -0
- package/dist/esm/repositories/index.js.map +1 -0
- package/dist/esm/sandboxes/index.d.ts +67 -0
- package/dist/esm/sandboxes/index.d.ts.map +1 -0
- package/dist/esm/sandboxes/index.js +249 -0
- package/dist/esm/sandboxes/index.js.map +1 -0
- package/dist/esm/sandboxes/types.d.ts +111 -0
- package/dist/esm/sandboxes/types.d.ts.map +1 -0
- package/dist/esm/sandboxes/types.js +2 -0
- package/dist/esm/sandboxes/types.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +69 -0
- package/src/agent/README.md +36 -0
- package/src/repositories/README.md +29 -0
- package/src/sandboxes/README.md +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Sapiom
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @sapiom/tools
|
|
2
|
+
|
|
3
|
+
A typed TypeScript client for Sapiom capabilities — sandboxes, git repositories, and coding agents — authenticated to your tenant.
|
|
4
|
+
|
|
5
|
+
These are the same capabilities your Sapiom agents call as tools; this package makes them callable directly from your own code.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sapiom/tools
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @sapiom/tools
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createClient } from "@sapiom/tools";
|
|
17
|
+
|
|
18
|
+
const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
|
|
19
|
+
|
|
20
|
+
// Create a repo, have a coding agent build into it, then publish.
|
|
21
|
+
const repo = await sapiom.repositories.create("landing-page");
|
|
22
|
+
const run = await sapiom.agent.coding.run({
|
|
23
|
+
task: "Build a one-page marketing site in index.html.",
|
|
24
|
+
gitRepository: repo, // cloned into the run's sandbox at /workspace/landing-page
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (run.result?.success) {
|
|
28
|
+
const { sha } = await repo.pushFromSandbox(run.sandbox, { message: "build: landing" });
|
|
29
|
+
console.log("published", sha);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Authentication
|
|
34
|
+
|
|
35
|
+
There are two ways to authenticate, both exposing the identical capability surface:
|
|
36
|
+
|
|
37
|
+
- **Explicit** — pass a key to `createClient`. This is the standalone entry point:
|
|
38
|
+
```typescript
|
|
39
|
+
const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
|
|
40
|
+
await sapiom.sandboxes.create({ name: "demo" });
|
|
41
|
+
```
|
|
42
|
+
- **Ambient** — import the namespaces directly and they resolve credentials from `SAPIOM_API_KEY` (or, inside a Sapiom workflow step, from the client the runtime provides):
|
|
43
|
+
```typescript
|
|
44
|
+
import { sandboxes, repositories, agent } from "@sapiom/tools";
|
|
45
|
+
await sandboxes.create({ name: "demo" });
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Attribution
|
|
49
|
+
|
|
50
|
+
Calls can be attributed to an agent and trace so they show up correctly in your transaction history. Attribution is set **once, on the client** — not per call:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const sapiom = createClient({
|
|
54
|
+
apiKey: process.env.SAPIOM_API_KEY,
|
|
55
|
+
attribution: { agentName: "digest-bot", traceId },
|
|
56
|
+
});
|
|
57
|
+
// every call this client makes is now attributed to digest-bot / traceId
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Inside a Sapiom workflow you don't set this at all — the runtime constructs the client with the running execution's attribution, so every tool call is attributed automatically.
|
|
61
|
+
|
|
62
|
+
If a single process makes calls on behalf of more than one agent or trace, derive a client per context with `sapiom.withAttribution({ ... })`.
|
|
63
|
+
|
|
64
|
+
## Capabilities
|
|
65
|
+
|
|
66
|
+
Each capability is a namespace, importable from the barrel or its own subpath (e.g. `@sapiom/tools/sandboxes`). Every capability has its own README with usage details, preconditions, and gotchas the type signatures can't express — read it before first use.
|
|
67
|
+
|
|
68
|
+
| Namespace | What it is | Docs |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| `sandboxes` | Isolated, ephemeral compute | [src/sandboxes](./src/sandboxes/README.md) |
|
|
71
|
+
| `repositories` | Private, in-network git repos | [src/repositories](./src/repositories/README.md) |
|
|
72
|
+
| `agent` | Coding agents (LLM execution) | [src/agent](./src/agent/README.md) |
|
|
73
|
+
|
|
74
|
+
## Composing capabilities
|
|
75
|
+
|
|
76
|
+
Capabilities are designed to work together. A coding `agent` run hands back the live `Sandbox` it executed in, and a `Repository` can publish a working tree straight from that sandbox:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
const run = await agent.coding.run({ task, gitRepository: repo });
|
|
80
|
+
await repo.pushFromSandbox(run.sandbox);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
A useful pattern: let the agent do the open-ended work (writing files) and perform exact, repeatable actions — committing, pushing, deploying — in your own code rather than in the agent's prompt. The agent produces the changes; `pushFromSandbox` publishes them deterministically.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth + transport core for `@sapiom/tools` — the private "runtime half" every
|
|
3
|
+
* capability namespace wraps. Capability modules call THIS; they never import each
|
|
4
|
+
* other's runtime, so the cross-capability mesh (`repo.pushFromSandbox(sandbox)`)
|
|
5
|
+
* has no package/module cycles. See docs/plans/capability-authoring-sdk.md.
|
|
6
|
+
*
|
|
7
|
+
* The credential resolves from one of two sources, same surface either way:
|
|
8
|
+
* - explicit: createClient({ apiKey }) — standalone / open-source use
|
|
9
|
+
* - ambient: SAPIOM_API_KEY (env), which the workflow engine injects per
|
|
10
|
+
* execution so step authors write zero auth plumbing.
|
|
11
|
+
*
|
|
12
|
+
* Attribution (which agent / trace a call belongs to) is execution context the
|
|
13
|
+
* runtime owns, NOT a parameter of any operation — so it lives here on the
|
|
14
|
+
* transport, set once and injected on every request, never threaded through
|
|
15
|
+
* capability methods. The engine sets it per execution by constructing the
|
|
16
|
+
* per-execution client; `withAttribution(...)` is a quiet escape hatch for the
|
|
17
|
+
* router / standalone cases. Capability method signatures deliberately have no
|
|
18
|
+
* attribution argument: that absence keeps LLM-authored step code from setting
|
|
19
|
+
* (and getting wrong) context it doesn't own.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Per-request attribution recorded with the gateway transaction. Every field is
|
|
23
|
+
* optional and maps 1:1 to an `x-sapiom-*` header the collapsed flow understands.
|
|
24
|
+
*/
|
|
25
|
+
export interface Attribution {
|
|
26
|
+
/** Human-readable agent name. Mutually exclusive with `agentId` (gateway-enforced). */
|
|
27
|
+
agentName?: string;
|
|
28
|
+
/** Agent UUID. Mutually exclusive with `agentName` (gateway-enforced). */
|
|
29
|
+
agentId?: string;
|
|
30
|
+
/** Sapiom trace id to attribute this call to. */
|
|
31
|
+
traceId?: string;
|
|
32
|
+
/** Your own external trace / correlation id. */
|
|
33
|
+
traceExternalId?: string;
|
|
34
|
+
/** Arbitrary JSON object stored with the transaction. Must be an object. */
|
|
35
|
+
metadata?: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
export interface TransportConfig {
|
|
38
|
+
/** Explicit tenant API key. Omit inside a workflow step — the engine injects it ambiently. */
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
/** Inject a fetch (tests / non-standard runtimes). Defaults to global fetch. */
|
|
41
|
+
fetch?: typeof globalThis.fetch;
|
|
42
|
+
/** Default attribution applied to every request this transport makes (see class doc). */
|
|
43
|
+
attribution?: Attribution;
|
|
44
|
+
}
|
|
45
|
+
export declare class Transport {
|
|
46
|
+
private readonly apiKey;
|
|
47
|
+
private readonly fetchImpl;
|
|
48
|
+
private readonly attribution;
|
|
49
|
+
constructor(config?: TransportConfig);
|
|
50
|
+
/**
|
|
51
|
+
* A new transport sharing this one's credential and fetch, with `attribution`
|
|
52
|
+
* merged over the current defaults. The escape hatch for the cases where one
|
|
53
|
+
* process attributes to many agents/traces (a router) — not something
|
|
54
|
+
* step-authoring code reaches for.
|
|
55
|
+
*/
|
|
56
|
+
withAttribution(attribution: Attribution): Transport;
|
|
57
|
+
/**
|
|
58
|
+
* Authenticated raw fetch — capabilities that need streaming or custom
|
|
59
|
+
* response handling (filesystem, log streams) use this and inspect the
|
|
60
|
+
* `Response` themselves. Injects the tenant credential + attribution headers;
|
|
61
|
+
* sets no content-type.
|
|
62
|
+
*/
|
|
63
|
+
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
64
|
+
/** Authenticated JSON request — parses the body and throws on a non-2xx status. */
|
|
65
|
+
request<T>(url: string, init?: RequestInit): Promise<T>;
|
|
66
|
+
}
|
|
67
|
+
export declare function defaultTransport(): Transport;
|
|
68
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/_client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B,8FAA8F;IAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,yFAAyF;IACzF,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AA4BD,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;gBAE9B,MAAM,GAAE,eAAoB;IAMxC;;;;;OAKG;IACH,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS;IAQpD;;;;;OAKG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiBnE,mFAAmF;IAC7E,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,CAAC;CAUlE;AAID,wBAAgB,gBAAgB,IAAI,SAAS,CAE5C"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Auth + transport core for `@sapiom/tools` — the private "runtime half" every
|
|
4
|
+
* capability namespace wraps. Capability modules call THIS; they never import each
|
|
5
|
+
* other's runtime, so the cross-capability mesh (`repo.pushFromSandbox(sandbox)`)
|
|
6
|
+
* has no package/module cycles. See docs/plans/capability-authoring-sdk.md.
|
|
7
|
+
*
|
|
8
|
+
* The credential resolves from one of two sources, same surface either way:
|
|
9
|
+
* - explicit: createClient({ apiKey }) — standalone / open-source use
|
|
10
|
+
* - ambient: SAPIOM_API_KEY (env), which the workflow engine injects per
|
|
11
|
+
* execution so step authors write zero auth plumbing.
|
|
12
|
+
*
|
|
13
|
+
* Attribution (which agent / trace a call belongs to) is execution context the
|
|
14
|
+
* runtime owns, NOT a parameter of any operation — so it lives here on the
|
|
15
|
+
* transport, set once and injected on every request, never threaded through
|
|
16
|
+
* capability methods. The engine sets it per execution by constructing the
|
|
17
|
+
* per-execution client; `withAttribution(...)` is a quiet escape hatch for the
|
|
18
|
+
* router / standalone cases. Capability method signatures deliberately have no
|
|
19
|
+
* attribution argument: that absence keeps LLM-authored step code from setting
|
|
20
|
+
* (and getting wrong) context it doesn't own.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.Transport = void 0;
|
|
24
|
+
exports.defaultTransport = defaultTransport;
|
|
25
|
+
function attributionToHeaders(a) {
|
|
26
|
+
const h = {};
|
|
27
|
+
if (a.agentName)
|
|
28
|
+
h["x-sapiom-agent-name"] = a.agentName;
|
|
29
|
+
if (a.agentId)
|
|
30
|
+
h["x-sapiom-agent-id"] = a.agentId;
|
|
31
|
+
if (a.traceId)
|
|
32
|
+
h["x-sapiom-trace-id"] = a.traceId;
|
|
33
|
+
if (a.traceExternalId)
|
|
34
|
+
h["x-sapiom-trace-external-id"] = a.traceExternalId;
|
|
35
|
+
if (a.metadata)
|
|
36
|
+
h["x-sapiom-metadata"] = JSON.stringify(a.metadata);
|
|
37
|
+
return h;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Standalone-only ambient attribution. Read once for the process-global default
|
|
41
|
+
* transport. NOT the engine's injection channel — `process.env` is process-wide,
|
|
42
|
+
* so it would bleed across step executions that share a worker. The engine sets
|
|
43
|
+
* attribution by constructing the per-execution client instead. Safe only for the
|
|
44
|
+
* one-execution-per-process case (CLI, scripts).
|
|
45
|
+
*/
|
|
46
|
+
function attributionFromEnv() {
|
|
47
|
+
const a = {};
|
|
48
|
+
if (process.env.SAPIOM_AGENT_ID)
|
|
49
|
+
a.agentId = process.env.SAPIOM_AGENT_ID;
|
|
50
|
+
if (process.env.SAPIOM_AGENT_NAME)
|
|
51
|
+
a.agentName = process.env.SAPIOM_AGENT_NAME;
|
|
52
|
+
if (process.env.SAPIOM_TRACE_ID)
|
|
53
|
+
a.traceId = process.env.SAPIOM_TRACE_ID;
|
|
54
|
+
if (process.env.SAPIOM_TRACE_EXTERNAL_ID)
|
|
55
|
+
a.traceExternalId = process.env.SAPIOM_TRACE_EXTERNAL_ID;
|
|
56
|
+
return a;
|
|
57
|
+
}
|
|
58
|
+
class Transport {
|
|
59
|
+
constructor(config = {}) {
|
|
60
|
+
this.apiKey = config.apiKey ?? process.env.SAPIOM_API_KEY ?? undefined;
|
|
61
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
62
|
+
this.attribution = config.attribution ?? {};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A new transport sharing this one's credential and fetch, with `attribution`
|
|
66
|
+
* merged over the current defaults. The escape hatch for the cases where one
|
|
67
|
+
* process attributes to many agents/traces (a router) — not something
|
|
68
|
+
* step-authoring code reaches for.
|
|
69
|
+
*/
|
|
70
|
+
withAttribution(attribution) {
|
|
71
|
+
return new Transport({
|
|
72
|
+
apiKey: this.apiKey,
|
|
73
|
+
fetch: this.fetchImpl,
|
|
74
|
+
attribution: { ...this.attribution, ...attribution },
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Authenticated raw fetch — capabilities that need streaming or custom
|
|
79
|
+
* response handling (filesystem, log streams) use this and inspect the
|
|
80
|
+
* `Response` themselves. Injects the tenant credential + attribution headers;
|
|
81
|
+
* sets no content-type.
|
|
82
|
+
*/
|
|
83
|
+
async fetch(url, init = {}) {
|
|
84
|
+
if (!this.apiKey) {
|
|
85
|
+
throw new Error("@sapiom/tools: no tenant credential. Pass createClient({ apiKey }) for standalone use, " +
|
|
86
|
+
"or run inside a Sapiom workflow (the engine injects SAPIOM_API_KEY).");
|
|
87
|
+
}
|
|
88
|
+
return this.fetchImpl(url, {
|
|
89
|
+
...init,
|
|
90
|
+
headers: {
|
|
91
|
+
"x-sapiom-api-key": this.apiKey,
|
|
92
|
+
...attributionToHeaders(this.attribution),
|
|
93
|
+
...(init.headers ?? {}),
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** Authenticated JSON request — parses the body and throws on a non-2xx status. */
|
|
98
|
+
async request(url, init = {}) {
|
|
99
|
+
const res = await this.fetch(url, {
|
|
100
|
+
...init,
|
|
101
|
+
headers: { "content-type": "application/json", ...(init.headers ?? {}) },
|
|
102
|
+
});
|
|
103
|
+
if (!res.ok) {
|
|
104
|
+
throw new Error(`${init.method ?? "GET"} ${url} → ${res.status} ${await res.text()}`);
|
|
105
|
+
}
|
|
106
|
+
return (await res.json());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.Transport = Transport;
|
|
110
|
+
/** The ambient default transport used by barrel-imported capabilities when no client is supplied. */
|
|
111
|
+
let _default;
|
|
112
|
+
function defaultTransport() {
|
|
113
|
+
return (_default ?? (_default = new Transport({ attribution: attributionFromEnv() })));
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/_client/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAqHH,4CAEC;AA3FD,SAAS,oBAAoB,CAAC,CAAc;IAC1C,MAAM,CAAC,GAA2B,EAAE,CAAC;IACrC,IAAI,CAAC,CAAC,SAAS;QAAE,CAAC,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC;IACxD,IAAI,CAAC,CAAC,OAAO;QAAE,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;IAClD,IAAI,CAAC,CAAC,OAAO;QAAE,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;IAClD,IAAI,CAAC,CAAC,eAAe;QAAE,CAAC,CAAC,4BAA4B,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC;IAC3E,IAAI,CAAC,CAAC,QAAQ;QAAE,CAAC,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpE,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB;IACzB,MAAM,CAAC,GAAgB,EAAE,CAAC;IAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe;QAAE,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;I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gBAC/B,GAAG,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC;gBACzC,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;aACxB;SACF,CAAC,CAAC;IACL,CAAC;IAED,mFAAmF;IACnF,KAAK,CAAC,OAAO,CAAI,GAAW,EAAE,OAAoB,EAAE;QAClD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;YAChC,GAAG,IAAI;YACP,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE;SACzE,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,GAAG,MAAM,GAAG,CAAC,MAAM,IAAI,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAM,CAAC;IACjC,CAAC;CACF;AA3DD,8BA2DC;AAED,qGAAqG;AACrG,IAAI,QAA+B,CAAC;AACpC,SAAgB,gBAAgB;IAC9B,OAAO,CAAC,QAAQ,KAAR,QAAQ,GAAK,IAAI,SAAS,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,EAAE,CAAC,EAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agent` capability — LLM execution (coding agents). The fuzzy counterpart to a
|
|
3
|
+
* deterministic step: hand it a task in natural language, it edits a checkout in a
|
|
4
|
+
* sandbox.
|
|
5
|
+
*
|
|
6
|
+
* import { agent, repositories } from "@sapiom/tools";
|
|
7
|
+
* const repo = await repositories.create("landing");
|
|
8
|
+
* const run = await agent.coding.run({
|
|
9
|
+
* task: "Build a one-page landing site in index.html.",
|
|
10
|
+
* gitRepository: repo, // auto-cloned into the sandbox at /workspace/<slug>
|
|
11
|
+
* });
|
|
12
|
+
* await repo.pushFromSandbox(run.sandbox, { message: "build: landing" });
|
|
13
|
+
*
|
|
14
|
+
* `run` awaits completion; `launch` returns a handle to poll yourself. Both return
|
|
15
|
+
* a live `Sandbox` handle so a later step can read files, exec, or push from it.
|
|
16
|
+
* The cross-capability inputs (`gitRepository: Repository`, `sandbox: Sandbox`) are
|
|
17
|
+
* passed as instances and resolved here to their wire ids.
|
|
18
|
+
*
|
|
19
|
+
* The wire contract is the gateway's JSON:API-shaped envelope (`data.attributes` /
|
|
20
|
+
* `data.relationships.execution_environment`). Attributes are snake_case on the
|
|
21
|
+
* wire; this module maps them to the camelCase SDK surface below.
|
|
22
|
+
*/
|
|
23
|
+
import { Transport } from "../_client/index.js";
|
|
24
|
+
import { Sandbox } from "../sandboxes/index.js";
|
|
25
|
+
import type { Repository } from "../repositories/index.js";
|
|
26
|
+
/** Run lifecycle, mirrored from the gateway's `AgentsRunStatus`. */
|
|
27
|
+
export type RunStatus = "pending" | "queued" | "running" | "completed" | "failed";
|
|
28
|
+
export interface CodingRunSpec {
|
|
29
|
+
/** Natural-language instruction for the coding agent. */
|
|
30
|
+
task: string;
|
|
31
|
+
/** Repo to clone into the sandbox at `/workspace/<slug>` and operate on. */
|
|
32
|
+
gitRepository?: Repository;
|
|
33
|
+
/** Reuse an existing sandbox instead of provisioning a fresh one. */
|
|
34
|
+
sandbox?: Sandbox;
|
|
35
|
+
/** Subdirectory (under the runner root) the agent SDK runs in. */
|
|
36
|
+
workingDirectory?: string;
|
|
37
|
+
/** Keep the sandbox alive after the run finishes. SDK default: true (the mesh needs it). */
|
|
38
|
+
keepSandbox?: boolean;
|
|
39
|
+
/** Override the model the agent runs on. */
|
|
40
|
+
model?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface CodingRunUsage {
|
|
43
|
+
inputTokens: number;
|
|
44
|
+
outputTokens: number;
|
|
45
|
+
cacheReadTokens: number;
|
|
46
|
+
cacheCreateTokens: number;
|
|
47
|
+
thinkingTokens: number;
|
|
48
|
+
}
|
|
49
|
+
export interface CodingRunOutcome {
|
|
50
|
+
success: boolean;
|
|
51
|
+
turns: number;
|
|
52
|
+
modelUsed: string | null;
|
|
53
|
+
durationMs: number;
|
|
54
|
+
toolCallCount: number;
|
|
55
|
+
usage: CodingRunUsage;
|
|
56
|
+
}
|
|
57
|
+
export interface CodingRunError {
|
|
58
|
+
/** `launch` (failed before the agent ran) vs `run` (failed mid-execution). */
|
|
59
|
+
stage: string;
|
|
60
|
+
message: string;
|
|
61
|
+
}
|
|
62
|
+
export interface CodingRunResult {
|
|
63
|
+
runId: string;
|
|
64
|
+
status: RunStatus;
|
|
65
|
+
summary: string | null;
|
|
66
|
+
result: CodingRunOutcome | null;
|
|
67
|
+
error: CodingRunError | null;
|
|
68
|
+
/** Live handle to the sandbox the run executed in. */
|
|
69
|
+
sandbox: Sandbox;
|
|
70
|
+
}
|
|
71
|
+
/** A launched-but-not-awaited run. */
|
|
72
|
+
export interface RunHandle {
|
|
73
|
+
runId: string;
|
|
74
|
+
sandbox: Sandbox;
|
|
75
|
+
/** Fetch the current status without blocking. */
|
|
76
|
+
status(): Promise<RunStatus>;
|
|
77
|
+
/** Poll to a terminal state and resolve the full result. */
|
|
78
|
+
wait(opts?: {
|
|
79
|
+
timeoutMs?: number;
|
|
80
|
+
pollMs?: number;
|
|
81
|
+
}): Promise<CodingRunResult>;
|
|
82
|
+
}
|
|
83
|
+
export declare function launch(spec: CodingRunSpec, transport?: Transport, baseUrl?: string): Promise<RunHandle>;
|
|
84
|
+
export declare function run(spec: CodingRunSpec, transport?: Transport, baseUrl?: string): Promise<CodingRunResult>;
|
|
85
|
+
/** Ambient-bound `agent.coding` namespace. */
|
|
86
|
+
export declare const coding: {
|
|
87
|
+
run: typeof run;
|
|
88
|
+
launch: typeof launch;
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@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AM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;IAC7B,sDAAsD;IACtD,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,sCAAsC;AACtC,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7B,4DAA4D;IAC5D,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAChF;AA6DD,wBAAsB,MAAM,CAC1B,IAAI,EAAE,aAAa,EACnB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,SAAS,CAAC,CA0CpB;AAED,wBAAsB,GAAG,CACvB,IAAI,EAAE,aAAa,EACnB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,eAAe,CAAC,CAG1B;AAED,8CAA8C;AAC9C,eAAO,MAAM,MAAM;;;CAAkB,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coding = void 0;
|
|
4
|
+
exports.launch = launch;
|
|
5
|
+
exports.run = run;
|
|
6
|
+
/**
|
|
7
|
+
* `agent` capability — LLM execution (coding agents). The fuzzy counterpart to a
|
|
8
|
+
* deterministic step: hand it a task in natural language, it edits a checkout in a
|
|
9
|
+
* sandbox.
|
|
10
|
+
*
|
|
11
|
+
* import { agent, repositories } from "@sapiom/tools";
|
|
12
|
+
* const repo = await repositories.create("landing");
|
|
13
|
+
* const run = await agent.coding.run({
|
|
14
|
+
* task: "Build a one-page landing site in index.html.",
|
|
15
|
+
* gitRepository: repo, // auto-cloned into the sandbox at /workspace/<slug>
|
|
16
|
+
* });
|
|
17
|
+
* await repo.pushFromSandbox(run.sandbox, { message: "build: landing" });
|
|
18
|
+
*
|
|
19
|
+
* `run` awaits completion; `launch` returns a handle to poll yourself. Both return
|
|
20
|
+
* a live `Sandbox` handle so a later step can read files, exec, or push from it.
|
|
21
|
+
* The cross-capability inputs (`gitRepository: Repository`, `sandbox: Sandbox`) are
|
|
22
|
+
* passed as instances and resolved here to their wire ids.
|
|
23
|
+
*
|
|
24
|
+
* The wire contract is the gateway's JSON:API-shaped envelope (`data.attributes` /
|
|
25
|
+
* `data.relationships.execution_environment`). Attributes are snake_case on the
|
|
26
|
+
* wire; this module maps them to the camelCase SDK surface below.
|
|
27
|
+
*/
|
|
28
|
+
const index_js_1 = require("../_client/index.js");
|
|
29
|
+
const index_js_2 = require("../sandboxes/index.js");
|
|
30
|
+
const DEFAULT_BASE_URL = process.env.SAPIOM_AGENTS_URL || "https://agents.services.sapiom.ai";
|
|
31
|
+
const TERMINAL = new Set(["completed", "failed"]);
|
|
32
|
+
function mapResult(r) {
|
|
33
|
+
if (!r)
|
|
34
|
+
return null;
|
|
35
|
+
return {
|
|
36
|
+
success: r.success,
|
|
37
|
+
turns: r.turns,
|
|
38
|
+
modelUsed: r.model_used ?? null,
|
|
39
|
+
durationMs: r.duration_ms,
|
|
40
|
+
toolCallCount: r.tool_call_count,
|
|
41
|
+
usage: {
|
|
42
|
+
inputTokens: r.usage?.input_tokens ?? 0,
|
|
43
|
+
outputTokens: r.usage?.output_tokens ?? 0,
|
|
44
|
+
cacheReadTokens: r.usage?.cache_read_tokens ?? 0,
|
|
45
|
+
cacheCreateTokens: r.usage?.cache_create_tokens ?? 0,
|
|
46
|
+
thinkingTokens: r.usage?.thinking_tokens ?? 0,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function buildBody(spec) {
|
|
51
|
+
return {
|
|
52
|
+
task: spec.task,
|
|
53
|
+
git_repository: spec.gitRepository?.slug,
|
|
54
|
+
execution_environment_id: spec.sandbox?.name,
|
|
55
|
+
working_directory: spec.workingDirectory,
|
|
56
|
+
keep_sandbox: spec.keepSandbox ?? true,
|
|
57
|
+
model: spec.model,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async function launch(spec, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
61
|
+
// 202 + a launch document; the execution_environment relationship is always present.
|
|
62
|
+
const doc = await transport.request(`${baseUrl}/v1/coding/runs`, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
body: JSON.stringify(buildBody(spec)),
|
|
65
|
+
});
|
|
66
|
+
const runId = doc.data.id;
|
|
67
|
+
const envId = doc.data.relationships?.execution_environment?.data?.id;
|
|
68
|
+
// Reuse the caller's sandbox handle when they supplied one; otherwise adopt the
|
|
69
|
+
// environment the run provisioned (its id is the sandbox name) so later steps
|
|
70
|
+
// can act on it.
|
|
71
|
+
const sandbox = spec.sandbox ?? index_js_2.Sandbox.attach(envId ?? runId, {}, transport);
|
|
72
|
+
const fetchDoc = () => transport.request(`${baseUrl}/v1/coding/runs/${encodeURIComponent(runId)}`);
|
|
73
|
+
const toResult = (d) => ({
|
|
74
|
+
runId,
|
|
75
|
+
status: d.data.attributes.status,
|
|
76
|
+
summary: d.data.attributes.summary ?? null,
|
|
77
|
+
result: mapResult(d.data.attributes.result),
|
|
78
|
+
error: d.data.attributes.error ?? null,
|
|
79
|
+
sandbox,
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
runId,
|
|
83
|
+
sandbox,
|
|
84
|
+
async status() {
|
|
85
|
+
return (await fetchDoc()).data.attributes.status;
|
|
86
|
+
},
|
|
87
|
+
async wait({ timeoutMs = 20 * 60000, pollMs = 3000 } = {}) {
|
|
88
|
+
const deadline = Date.now() + timeoutMs;
|
|
89
|
+
// eslint-disable-next-line no-constant-condition
|
|
90
|
+
while (true) {
|
|
91
|
+
const d = await fetchDoc();
|
|
92
|
+
if (TERMINAL.has(d.data.attributes.status))
|
|
93
|
+
return toResult(d);
|
|
94
|
+
if (Date.now() > deadline) {
|
|
95
|
+
throw new Error(`coding run ${runId} timed out after ${timeoutMs}ms (last status: ${d.data.attributes.status})`);
|
|
96
|
+
}
|
|
97
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function run(spec, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
103
|
+
const handle = await launch(spec, transport, baseUrl);
|
|
104
|
+
return handle.wait();
|
|
105
|
+
}
|
|
106
|
+
/** Ambient-bound `agent.coding` namespace. */
|
|
107
|
+
exports.coding = { run, launch };
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/index.ts"],"names":[],"mappings":";;;AAqJA,wBA8CC;AAED,kBAOC;AA5MD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,kDAAkE;AAClE,oDAAgD;AAGhD,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,mCAAmC,CAAC;AAI9F,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAY,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AA0F7D,SAAS,SAAS,CAAC,CAAgC;IACjD,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,OAAO;QACL,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,SAAS,EAAE,CAAC,CAAC,UAAU,IAA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,CAAC,CAAC;gBAC/D,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;oBAC1B,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,oBAAoB,SAAS,oBAAoB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;gBACnH,CAAC;gBACD,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,GAAG,CACvB,IAAmB,EACnB,YAAuB,IAAA,2BAAgB,GAAE,EACzC,OAAO,GAAG,gBAAgB;IAE1B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC;AAED,8CAA8C;AACjC,QAAA,MAAM,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createClient` — builds a `Sapiom` client whose capability namespaces are bound
|
|
3
|
+
* to an explicit credential. This is the standalone / open-source entry point:
|
|
4
|
+
*
|
|
5
|
+
* import { createClient } from "@sapiom/tools";
|
|
6
|
+
* const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
|
|
7
|
+
* const box = await sapiom.sandboxes.create({ name: "demo" });
|
|
8
|
+
*
|
|
9
|
+
* Inside a workflow step the engine hands you an already-auth'd `sapiom` of this
|
|
10
|
+
* same shape; you can also barrel-import the ambient-bound namespaces directly
|
|
11
|
+
* (`import { sandboxes } from "@sapiom/tools"`).
|
|
12
|
+
*
|
|
13
|
+
* Attribution is set once (the engine constructs the per-execution client with
|
|
14
|
+
* it; standalone callers pass it to `createClient`), never per capability call.
|
|
15
|
+
* `withAttribution(...)` derives a client for the router case — see `_client`.
|
|
16
|
+
*/
|
|
17
|
+
import { type TransportConfig, type Attribution } from "./_client/index.js";
|
|
18
|
+
import { Sandbox } from "./sandboxes/index.js";
|
|
19
|
+
import type { SandboxCreateOptions } from "./sandboxes/index.js";
|
|
20
|
+
import { Repository } from "./repositories/index.js";
|
|
21
|
+
import type { CodingRunSpec, CodingRunResult, RunHandle } from "./agent/index.js";
|
|
22
|
+
export interface Sapiom {
|
|
23
|
+
readonly sandboxes: {
|
|
24
|
+
create(opts: SandboxCreateOptions): Promise<Sandbox>;
|
|
25
|
+
attach(name: string, opts?: {
|
|
26
|
+
workspaceRoot?: string;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
}): Sandbox;
|
|
29
|
+
};
|
|
30
|
+
readonly repositories: {
|
|
31
|
+
create(slug: string): Promise<Repository>;
|
|
32
|
+
get(slug: string): Promise<Repository>;
|
|
33
|
+
list(): Promise<Repository[]>;
|
|
34
|
+
delete(slug: string): Promise<void>;
|
|
35
|
+
attach(slug: string, cloneUrl: string): Repository;
|
|
36
|
+
};
|
|
37
|
+
readonly agent: {
|
|
38
|
+
coding: {
|
|
39
|
+
run(spec: CodingRunSpec): Promise<CodingRunResult>;
|
|
40
|
+
launch(spec: CodingRunSpec): Promise<RunHandle>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Derive a client that attributes its calls to a different agent/trace. For the
|
|
45
|
+
* router case (one process acting for many agents); step-authoring code doesn't
|
|
46
|
+
* need this — attribution is set once when the client is constructed.
|
|
47
|
+
*/
|
|
48
|
+
withAttribution(attribution: Attribution): Sapiom;
|
|
49
|
+
}
|
|
50
|
+
export declare function createClient(config?: TransportConfig): Sapiom;
|
|
51
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GA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;OAIG;IACH,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAAC;CAEnD;AA0BD,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createClient = createClient;
|
|
4
|
+
/**
|
|
5
|
+
* `createClient` — builds a `Sapiom` client whose capability namespaces are bound
|
|
6
|
+
* to an explicit credential. This is the standalone / open-source entry point:
|
|
7
|
+
*
|
|
8
|
+
* import { createClient } from "@sapiom/tools";
|
|
9
|
+
* const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
|
|
10
|
+
* const box = await sapiom.sandboxes.create({ name: "demo" });
|
|
11
|
+
*
|
|
12
|
+
* Inside a workflow step the engine hands you an already-auth'd `sapiom` of this
|
|
13
|
+
* same shape; you can also barrel-import the ambient-bound namespaces directly
|
|
14
|
+
* (`import { sandboxes } from "@sapiom/tools"`).
|
|
15
|
+
*
|
|
16
|
+
* Attribution is set once (the engine constructs the per-execution client with
|
|
17
|
+
* it; standalone callers pass it to `createClient`), never per capability call.
|
|
18
|
+
* `withAttribution(...)` derives a client for the router case — see `_client`.
|
|
19
|
+
*/
|
|
20
|
+
const index_js_1 = require("./_client/index.js");
|
|
21
|
+
const index_js_2 = require("./sandboxes/index.js");
|
|
22
|
+
const index_js_3 = require("./repositories/index.js");
|
|
23
|
+
const index_js_4 = require("./agent/index.js");
|
|
24
|
+
/** Bind every capability namespace to a transport. `withAttribution` rebinds to a derived one. */
|
|
25
|
+
function bind(transport) {
|
|
26
|
+
return {
|
|
27
|
+
sandboxes: {
|
|
28
|
+
create: (opts) => index_js_2.Sandbox.create(opts, transport),
|
|
29
|
+
attach: (name, opts) => index_js_2.Sandbox.attach(name, opts, transport),
|
|
30
|
+
},
|
|
31
|
+
repositories: {
|
|
32
|
+
create: (slug) => index_js_3.Repository.create(slug, transport),
|
|
33
|
+
get: (slug) => index_js_3.Repository.get(slug, transport),
|
|
34
|
+
list: () => index_js_3.Repository.list(transport),
|
|
35
|
+
delete: (slug) => index_js_3.Repository.delete(slug, transport),
|
|
36
|
+
attach: (slug, cloneUrl) => index_js_3.Repository.attach(slug, cloneUrl, transport),
|
|
37
|
+
},
|
|
38
|
+
agent: {
|
|
39
|
+
coding: {
|
|
40
|
+
run: (spec) => (0, index_js_4.run)(spec, transport),
|
|
41
|
+
launch: (spec) => (0, index_js_4.launch)(spec, transport),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
withAttribution: (attribution) => bind(transport.withAttribution(attribution)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function createClient(config) {
|
|
48
|
+
return bind(new index_js_1.Transport(config));
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;AA0EA,oCAEC;AA5ED;;;;;;;;;;;;;;;GAeG;AACH,iDAAuF;AACvF,mDAA+C;AAE/C,sDAAqD;AACrD,+CAA4E;AA8B5E,kGAAkG;AAClG,SAAS,IAAI,CAAC,SAAoB;IAChC,OAAO;QACL,SAAS,EAAE;YACT,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAO,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC;YACjD,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,kBAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC;SAC9D;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAU,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC;YACpD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAU,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC;YAC9C,IAAI,EAAE,GAAG,EAAE,CAAC,qBAAU,CAAC,IAAI,CAAC,SAAS,CAAC;YACtC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAU,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC;YACpD,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,qBAAU,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC;SACzE;QACD,KAAK,EAAE;YACL,MAAM,EAAE;gBACN,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,cAAS,EAAC,IAAI,EAAE,SAAS,CAAC;gBACzC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,iBAAY,EAAC,IAAI,EAAE,SAAS,CAAC;aAChD;SACF;QACD,eAAe,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;KAC/E,CAAC;AACJ,CAAC;AAED,SAAgB,YAAY,CAAC,MAAwB;IACnD,OAAO,IAAI,CAAC,IAAI,oBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sapiom/tools` — the typed Sapiom capability client.
|
|
3
|
+
*
|
|
4
|
+
* The same catalog your agents call over MCP, callable from code. Capabilities are
|
|
5
|
+
* namespaces (`sandboxes`, `repositories`, `agent`, … ), importable from the barrel
|
|
6
|
+
* or a subpath:
|
|
7
|
+
*
|
|
8
|
+
* import { sandboxes } from "@sapiom/tools";
|
|
9
|
+
* import { sandboxes } from "@sapiom/tools/sandboxes";
|
|
10
|
+
*
|
|
11
|
+
* Auth is implicit: ambient (engine-injected) inside a workflow step, or explicit
|
|
12
|
+
* via `createClient({ apiKey })` standalone.
|
|
13
|
+
*/
|
|
14
|
+
export { createClient } from "./client.js";
|
|
15
|
+
export type { Sapiom } from "./client.js";
|
|
16
|
+
export type { TransportConfig, Attribution } from "./_client/index.js";
|
|
17
|
+
export * as sandboxes from "./sandboxes/index.js";
|
|
18
|
+
export { Sandbox } from "./sandboxes/index.js";
|
|
19
|
+
export * as repositories from "./repositories/index.js";
|
|
20
|
+
export { Repository } from "./repositories/index.js";
|
|
21
|
+
export * as agent from "./agent/index.js";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEvE,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC"}
|