@paddockai/server 0.0.4 → 0.0.5
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/dist/index.cjs +80 -135
- package/dist/index.d.cts +578 -605
- package/dist/index.d.ts +578 -605
- package/dist/index.js +79 -123
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -33,9 +23,8 @@ __export(index_exports, {
|
|
|
33
23
|
AgentResources: () => AgentResources,
|
|
34
24
|
Agents: () => Agents,
|
|
35
25
|
Collection: () => Collection,
|
|
36
|
-
ConnectorResources: () => ConnectorResources,
|
|
37
|
-
Connectors: () => Connectors,
|
|
38
26
|
EventStream: () => EventStream,
|
|
27
|
+
Inbox: () => Inbox,
|
|
39
28
|
Marketplaces: () => Marketplaces,
|
|
40
29
|
ModelProviders: () => ModelProviders,
|
|
41
30
|
Models: () => Models,
|
|
@@ -67,8 +56,10 @@ var streamEventNames = [
|
|
|
67
56
|
"config.applied",
|
|
68
57
|
"session.status",
|
|
69
58
|
"outbox.queued",
|
|
59
|
+
"outbox.retrying",
|
|
70
60
|
"outbox.delivered",
|
|
71
61
|
"outbox.failed",
|
|
62
|
+
"inbox.failed",
|
|
72
63
|
"status.update",
|
|
73
64
|
"error"
|
|
74
65
|
];
|
|
@@ -569,9 +560,12 @@ var SessionOperations = class {
|
|
|
569
560
|
get base() {
|
|
570
561
|
return `/sessions/${segment(this.id)}`;
|
|
571
562
|
}
|
|
572
|
-
/**
|
|
573
|
-
|
|
574
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Stores a user message; resolves with its event once stored (004#messages). author, the person
|
|
565
|
+
* the message speaks for, is allowed with an API key or a function token, never a session token.
|
|
566
|
+
*/
|
|
567
|
+
send(text, options = {}) {
|
|
568
|
+
return this.transport.request({ method: "POST", path: `${this.base}/messages`, json: { text, ...options } });
|
|
575
569
|
}
|
|
576
570
|
/** Stores a stop.requested event and resolves with it. */
|
|
577
571
|
stop() {
|
|
@@ -581,13 +575,15 @@ var SessionOperations = class {
|
|
|
581
575
|
stream(options = {}) {
|
|
582
576
|
return new EventStream(this.transport, `${this.base}/stream`, options);
|
|
583
577
|
}
|
|
584
|
-
/**
|
|
578
|
+
/**
|
|
579
|
+
* Mints a session token for the browser: ttl in seconds; participant authors the token's
|
|
580
|
+
* messages; readOnly makes a token that can only read and follow the session (004#credentials).
|
|
581
|
+
*/
|
|
585
582
|
createToken(options) {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
});
|
|
583
|
+
const json = { ttlSeconds: options.ttl };
|
|
584
|
+
if (options.participant) json.participant = options.participant;
|
|
585
|
+
if (options.readOnly) json.readOnly = true;
|
|
586
|
+
return this.transport.request({ method: "POST", path: `${this.base}/tokens`, json });
|
|
591
587
|
}
|
|
592
588
|
/** Reads the session. */
|
|
593
589
|
get() {
|
|
@@ -596,7 +592,7 @@ var SessionOperations = class {
|
|
|
596
592
|
};
|
|
597
593
|
|
|
598
594
|
// src/version.ts
|
|
599
|
-
var version = "0.0.
|
|
595
|
+
var version = "0.0.5";
|
|
600
596
|
|
|
601
597
|
// src/client.ts
|
|
602
598
|
function nodeProcess() {
|
|
@@ -679,7 +675,7 @@ var Paddock = class {
|
|
|
679
675
|
modelProviders;
|
|
680
676
|
agents;
|
|
681
677
|
sessions;
|
|
682
|
-
|
|
678
|
+
inbox;
|
|
683
679
|
outbox;
|
|
684
680
|
constructor(options = {}) {
|
|
685
681
|
const { apiKey, baseUrl } = lookup(options);
|
|
@@ -696,7 +692,7 @@ var Paddock = class {
|
|
|
696
692
|
this.modelProviders = new ModelProviders(transport);
|
|
697
693
|
this.agents = new Agents(transport);
|
|
698
694
|
this.sessions = new Sessions(transport);
|
|
699
|
-
this.
|
|
695
|
+
this.inbox = new Inbox(transport);
|
|
700
696
|
this.outbox = new Outbox(transport);
|
|
701
697
|
}
|
|
702
698
|
};
|
|
@@ -706,18 +702,35 @@ var Templates = class {
|
|
|
706
702
|
}
|
|
707
703
|
t;
|
|
708
704
|
/**
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
*
|
|
705
|
+
* Creates a template version from a bundle, the gzip tar that `paddock templates create DIR`
|
|
706
|
+
* builds from a template directory (014#build). secrets holds values of the template's
|
|
707
|
+
* template secrets. The server assigns the version; a bundle whose digest equals the latest
|
|
708
|
+
* version returns that version. With dryRun, the server checks everything and returns the
|
|
709
|
+
* version a create would return, storing nothing.
|
|
713
710
|
*/
|
|
714
|
-
async create(
|
|
711
|
+
async create(bundle, options = {}) {
|
|
715
712
|
const query = options.dryRun ? { dryRun: true } : void 0;
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
713
|
+
const form = new FormData();
|
|
714
|
+
const blob = bundle instanceof Blob ? bundle : new Blob([bundle], { type: "application/gzip" });
|
|
715
|
+
form.append("bundle", blob, "bundle.tar.gz");
|
|
716
|
+
if (options.secrets && Object.keys(options.secrets).length > 0)
|
|
717
|
+
form.append("secrets", JSON.stringify(options.secrets));
|
|
718
|
+
return this.t.request({ method: "POST", path: "/templates", query, body: form });
|
|
719
|
+
}
|
|
720
|
+
/** Each inbox entry of a template name's latest version with its template URL (010#endpoints). */
|
|
721
|
+
async inbox(name) {
|
|
722
|
+
return (await this.t.request({ method: "GET", path: `/templates/${segment(name)}/inbox` })).data;
|
|
723
|
+
}
|
|
724
|
+
/** A template name's template secrets, shared by its versions: names and set times, never values. */
|
|
725
|
+
secrets(name) {
|
|
726
|
+
const base = `/templates/${segment(name)}/secrets`;
|
|
727
|
+
return {
|
|
728
|
+
list: async () => (await this.t.request({ method: "GET", path: base })).data,
|
|
729
|
+
set: (secret, value) => this.t.request({ method: "PUT", path: `${base}/${segment(secret)}`, json: { value } }),
|
|
730
|
+
delete: async (secret) => {
|
|
731
|
+
await this.t.request({ method: "DELETE", path: `${base}/${segment(secret)}`, read: "none" });
|
|
732
|
+
}
|
|
733
|
+
};
|
|
721
734
|
}
|
|
722
735
|
/** "name@version" reads that version; "name" reads the latest. */
|
|
723
736
|
get(ref) {
|
|
@@ -797,6 +810,11 @@ var Agents = class {
|
|
|
797
810
|
this.t = t;
|
|
798
811
|
}
|
|
799
812
|
t;
|
|
813
|
+
/**
|
|
814
|
+
* Creates an agent from "name@version". env holds its own env values, which override the
|
|
815
|
+
* template's by name; secrets a value for every agent secret the template declares; harness,
|
|
816
|
+
* when given, replaces the template's harness block for this agent (014#harness-override).
|
|
817
|
+
*/
|
|
800
818
|
async create(options) {
|
|
801
819
|
return agentHandle(this.t, await this.t.request({ method: "POST", path: "/agents", json: options }));
|
|
802
820
|
}
|
|
@@ -897,8 +915,10 @@ var AgentResources = class {
|
|
|
897
915
|
/** The value is null when neither the agent nor its template sets one. */
|
|
898
916
|
systemPrompt;
|
|
899
917
|
workflows;
|
|
900
|
-
/** The agent's effective
|
|
918
|
+
/** The agent's effective configuration as paddock.yaml in JSON, secrets by name only. */
|
|
901
919
|
export;
|
|
920
|
+
/** The agent's secrets: names and set times, never values. */
|
|
921
|
+
secrets;
|
|
902
922
|
/**
|
|
903
923
|
* Sends text to the agent's default session, its newest session whose defaultSession
|
|
904
924
|
* metadata is "true", created on the first send; resolves with the stored user
|
|
@@ -906,8 +926,6 @@ var AgentResources = class {
|
|
|
906
926
|
*/
|
|
907
927
|
send;
|
|
908
928
|
permissions;
|
|
909
|
-
/** The key patterns the agent may send to: its own list, or else the template's (015#allow). */
|
|
910
|
-
outbox;
|
|
911
929
|
memory;
|
|
912
930
|
files;
|
|
913
931
|
sessions;
|
|
@@ -923,16 +941,15 @@ var AgentResources = class {
|
|
|
923
941
|
const workflows = new Collection(t, `${base}/workflows`);
|
|
924
942
|
this.workflows = { list: (o) => workflows.list(o), get: (name) => workflows.get(name) };
|
|
925
943
|
this.export = () => t.request({ method: "GET", path: `${base}/export` });
|
|
926
|
-
this.
|
|
944
|
+
this.secrets = {
|
|
945
|
+
list: async () => (await t.request({ method: "GET", path: `${base}/secrets` })).data,
|
|
946
|
+
set: (name, value) => t.request({ method: "PUT", path: `${base}/secrets/${segment(name)}`, json: { value } })
|
|
947
|
+
};
|
|
948
|
+
this.send = (text, options = {}) => t.request({ method: "POST", path: `${base}/messages`, json: { text, ...options } });
|
|
927
949
|
this.permissions = {
|
|
928
950
|
get: () => t.request({ method: "GET", path: `${base}/permissions` }),
|
|
929
951
|
set: (spec) => t.request({ method: "PUT", path: `${base}/permissions`, json: spec })
|
|
930
952
|
};
|
|
931
|
-
this.outbox = {
|
|
932
|
-
get: () => t.request({ method: "GET", path: `${base}/outbox` }),
|
|
933
|
-
set: (spec) => t.request({ method: "PUT", path: `${base}/outbox`, json: spec }),
|
|
934
|
-
delete: () => t.request({ method: "DELETE", path: `${base}/outbox` })
|
|
935
|
-
};
|
|
936
953
|
const memoryPath = (p) => `${base}/memory/${segment(p, true)}`;
|
|
937
954
|
this.memory = {
|
|
938
955
|
list: () => t.request({ method: "GET", path: `${base}/memory`, timeoutMs: longTimeoutMs }),
|
|
@@ -980,7 +997,7 @@ var AgentResources = class {
|
|
|
980
997
|
const page = await t.request({
|
|
981
998
|
method: "GET",
|
|
982
999
|
path: `${base}/sessions`,
|
|
983
|
-
query: { metadata: o.metadata, limit: o.limit, cursor: cursor ?? o.cursor }
|
|
1000
|
+
query: { metadata: o.metadata, key: o.key, limit: o.limit, cursor: cursor ?? o.cursor }
|
|
984
1001
|
});
|
|
985
1002
|
return { ...page, data: page.data.map((s) => sessionHandle(t, s)) };
|
|
986
1003
|
})
|
|
@@ -1018,6 +1035,7 @@ var Sessions = class {
|
|
|
1018
1035
|
query: {
|
|
1019
1036
|
agentId: options.agentId,
|
|
1020
1037
|
metadata: options.metadata,
|
|
1038
|
+
key: options.key,
|
|
1021
1039
|
createdAfter: options.createdAfter,
|
|
1022
1040
|
createdBefore: options.createdBefore,
|
|
1023
1041
|
limit: options.limit,
|
|
@@ -1034,116 +1052,43 @@ var Sessions = class {
|
|
|
1034
1052
|
await this.t.request({ method: "DELETE", path: `/sessions/${segment(id)}`, read: "none" });
|
|
1035
1053
|
}
|
|
1036
1054
|
};
|
|
1037
|
-
var
|
|
1038
|
-
constructor(t) {
|
|
1039
|
-
this.t = t;
|
|
1040
|
-
}
|
|
1041
|
-
t;
|
|
1042
|
-
/** Creates a connector with the sides given; the secret is generated when omitted. */
|
|
1043
|
-
async create(spec) {
|
|
1044
|
-
return connectorHandle(
|
|
1045
|
-
this.t,
|
|
1046
|
-
await this.t.request({ method: "POST", path: "/connectors", json: spec })
|
|
1047
|
-
);
|
|
1048
|
-
}
|
|
1049
|
-
/** The connectors, newest first. */
|
|
1050
|
-
list(options = {}) {
|
|
1051
|
-
return new PageList(async (cursor) => {
|
|
1052
|
-
const page = await this.t.request({
|
|
1053
|
-
method: "GET",
|
|
1054
|
-
path: "/connectors",
|
|
1055
|
-
query: { limit: options.limit, cursor: cursor ?? options.cursor }
|
|
1056
|
-
});
|
|
1057
|
-
return { ...page, data: page.data.map((c) => connectorHandle(this.t, c)) };
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
/** By ID or by name. */
|
|
1061
|
-
async get(idOrName) {
|
|
1062
|
-
return connectorHandle(
|
|
1063
|
-
this.t,
|
|
1064
|
-
await this.t.request({ method: "GET", path: `/connectors/${segment(idOrName)}` })
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
/** Sets which sides exist and the outbound rate limit; a side omitted or null is removed with its function. */
|
|
1068
|
-
async update(id, spec) {
|
|
1069
|
-
return connectorHandle(
|
|
1070
|
-
this.t,
|
|
1071
|
-
await this.t.request({ method: "PUT", path: `/connectors/${segment(id)}`, json: spec })
|
|
1072
|
-
);
|
|
1073
|
-
}
|
|
1074
|
-
/** Deletes its functions first; its URL answers 404 at once, and its deliveries and outbox messages are removed. */
|
|
1075
|
-
async delete(id) {
|
|
1076
|
-
await this.t.request({ method: "DELETE", path: `/connectors/${segment(id)}`, read: "none" });
|
|
1077
|
-
}
|
|
1078
|
-
/** Stock function code per side, in both runtimes, with the params each reads (015#presets). */
|
|
1079
|
-
async functionPresets() {
|
|
1080
|
-
const out = await this.t.request({
|
|
1081
|
-
method: "GET",
|
|
1082
|
-
path: "/connectors/function-presets"
|
|
1083
|
-
});
|
|
1084
|
-
return out.presets;
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
var ConnectorResources = class {
|
|
1088
|
-
/** The connector's named secrets, whose values only these return; name defaults to "default". */
|
|
1089
|
-
secret;
|
|
1090
|
-
/** The code each side runs: inbound on every request, outbound on every message sent. */
|
|
1091
|
-
functions;
|
|
1055
|
+
var Inbox = class {
|
|
1092
1056
|
deliveries;
|
|
1093
|
-
constructor(t
|
|
1094
|
-
const base = `/connectors/${segment(connectorId)}`;
|
|
1095
|
-
this.secret = {
|
|
1096
|
-
get: (o = {}) => t.request({ method: "GET", path: `${base}/secret`, query: { name: o.name } }),
|
|
1097
|
-
rotate: (o = {}) => t.request({ method: "POST", path: `${base}/secret`, json: o }),
|
|
1098
|
-
delete: async (o) => {
|
|
1099
|
-
await t.request({ method: "DELETE", path: `${base}/secret`, query: { name: o.name }, read: "none" });
|
|
1100
|
-
}
|
|
1101
|
-
};
|
|
1102
|
-
const fn = (side) => `${base}/functions/${segment(side)}`;
|
|
1103
|
-
this.functions = {
|
|
1104
|
-
get: (side) => t.request({ method: "GET", path: fn(side) }),
|
|
1105
|
-
set: (side, spec) => t.request({ method: "PUT", path: fn(side), json: spec }),
|
|
1106
|
-
delete: async (side) => {
|
|
1107
|
-
await t.request({ method: "DELETE", path: fn(side), read: "none" });
|
|
1108
|
-
},
|
|
1109
|
-
test: (side, request) => t.request({ method: "POST", path: `${fn(side)}/test`, json: request })
|
|
1110
|
-
};
|
|
1057
|
+
constructor(t) {
|
|
1111
1058
|
this.deliveries = {
|
|
1112
1059
|
list: (o = {}) => new PageList(
|
|
1113
1060
|
(cursor) => t.request({
|
|
1114
1061
|
method: "GET",
|
|
1115
|
-
path:
|
|
1116
|
-
query: {
|
|
1062
|
+
path: "/inbox/deliveries",
|
|
1063
|
+
query: {
|
|
1064
|
+
template: o.template,
|
|
1065
|
+
entry: o.entry,
|
|
1066
|
+
agentId: o.agentId,
|
|
1067
|
+
status: o.status,
|
|
1068
|
+
limit: o.limit,
|
|
1069
|
+
cursor: cursor ?? o.cursor
|
|
1070
|
+
}
|
|
1117
1071
|
})
|
|
1118
1072
|
),
|
|
1119
|
-
get: (id) => t.request({ method: "GET", path:
|
|
1120
|
-
replay: (id) => t.request({ method: "POST", path:
|
|
1073
|
+
get: (id) => t.request({ method: "GET", path: `/inbox/deliveries/${segment(id)}` }),
|
|
1074
|
+
replay: (id) => t.request({ method: "POST", path: `/inbox/deliveries/${segment(id)}/replay` })
|
|
1121
1075
|
};
|
|
1122
1076
|
}
|
|
1123
1077
|
};
|
|
1124
|
-
function connectorHandle(t, connector) {
|
|
1125
|
-
const resources = new ConnectorResources(t, connector.id);
|
|
1126
|
-
const handle = { ...connector };
|
|
1127
|
-
for (const [name, value] of Object.entries(resources)) {
|
|
1128
|
-
Object.defineProperty(handle, name, { value, enumerable: false });
|
|
1129
|
-
}
|
|
1130
|
-
return handle;
|
|
1131
|
-
}
|
|
1132
1078
|
var Outbox = class {
|
|
1133
1079
|
constructor(t) {
|
|
1134
1080
|
this.t = t;
|
|
1135
1081
|
}
|
|
1136
1082
|
t;
|
|
1137
|
-
/**
|
|
1083
|
+
/** Outbox messages newest first; every filter left out matches all. */
|
|
1138
1084
|
list(options = {}) {
|
|
1139
1085
|
return new PageList(
|
|
1140
1086
|
(cursor) => this.t.request({
|
|
1141
1087
|
method: "GET",
|
|
1142
1088
|
path: "/outbox",
|
|
1143
1089
|
query: {
|
|
1144
|
-
|
|
1090
|
+
agentId: options.agentId,
|
|
1145
1091
|
sessionId: options.sessionId,
|
|
1146
|
-
key: options.key,
|
|
1147
1092
|
status: options.status,
|
|
1148
1093
|
limit: options.limit,
|
|
1149
1094
|
cursor: cursor ?? options.cursor
|
|
@@ -1151,10 +1096,11 @@ var Outbox = class {
|
|
|
1151
1096
|
})
|
|
1152
1097
|
);
|
|
1153
1098
|
}
|
|
1099
|
+
/** A message with each entry's deliver step and each target input's status, attempts, and last answer. */
|
|
1154
1100
|
get(id) {
|
|
1155
1101
|
return this.t.request({ method: "GET", path: `/outbox/${segment(id)}` });
|
|
1156
1102
|
}
|
|
1157
|
-
/** Queues
|
|
1103
|
+
/** Queues the message's failed steps again with their idempotency keys and their places in order. */
|
|
1158
1104
|
retry(id) {
|
|
1159
1105
|
return this.t.request({ method: "POST", path: `/outbox/${segment(id)}/retry` });
|
|
1160
1106
|
}
|
|
@@ -1164,9 +1110,8 @@ var Outbox = class {
|
|
|
1164
1110
|
AgentResources,
|
|
1165
1111
|
Agents,
|
|
1166
1112
|
Collection,
|
|
1167
|
-
ConnectorResources,
|
|
1168
|
-
Connectors,
|
|
1169
1113
|
EventStream,
|
|
1114
|
+
Inbox,
|
|
1170
1115
|
Marketplaces,
|
|
1171
1116
|
ModelProviders,
|
|
1172
1117
|
Models,
|