@coffer-org/plugin-http 1.4.0 → 2.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.
@@ -4,12 +4,29 @@ const log = getLogger('http-connector');
4
4
  const CONNECTOR = 'http';
5
5
  const DEFAULT_MAX_DEPTH = 30;
6
6
  export async function recordUser(m) {
7
- await putThreadMessage({ connector: CONNECTOR, chatId: m.chatId, msgId: m.msgId, role: 'user', sender: m.sender ?? null, text: m.text, ts: m.ts, replyToId: m.replyToId });
7
+ await putThreadMessage({
8
+ connector: CONNECTOR,
9
+ chatId: m.chatId,
10
+ msgId: m.msgId,
11
+ role: 'user',
12
+ sender: m.sender ?? null,
13
+ text: m.text,
14
+ ts: m.ts,
15
+ replyToId: m.replyToId,
16
+ });
8
17
  }
9
18
  export async function recordAssistant(m) {
10
19
  if (m.botMsgId == null || !m.text.trim())
11
20
  return false;
12
- await putThreadMessage({ connector: CONNECTOR, chatId: m.chatId, msgId: m.botMsgId, role: 'assistant', text: m.text, ts: m.now, replyToId: m.parentMsgId });
21
+ await putThreadMessage({
22
+ connector: CONNECTOR,
23
+ chatId: m.chatId,
24
+ msgId: m.botMsgId,
25
+ role: 'assistant',
26
+ text: m.text,
27
+ ts: m.now,
28
+ replyToId: m.parentMsgId,
29
+ });
13
30
  return true;
14
31
  }
15
32
  export async function buildChain(headMsgId, opts) {
@@ -22,7 +39,9 @@ export async function buildChain(headMsgId, opts) {
22
39
  const stored = await getThreadMessage(CONNECTOR, opts.chatId, cur);
23
40
  if (!stored)
24
41
  break;
25
- acc.push({ role: stored.role, content: stored.text, sender: stored.sender, msgId: stored.msgId, ts: stored.ts });
42
+ if (stored.role !== 'reasoning') {
43
+ acc.push({ role: stored.role, content: stored.text, sender: stored.sender, msgId: stored.msgId, ts: stored.ts });
44
+ }
26
45
  cur = stored.replyToId;
27
46
  }
28
47
  if (acc.length >= max)
@@ -1,19 +1,22 @@
1
+ import { plainRender } from '@coffer-org/plugin-orchestrator/runtime';
1
2
  import { recordAssistant as storeAssistant } from "./chain-store.js";
3
+ const HTTP_MAX = 100_000;
2
4
  export function makeBufferedConnector(opts) {
3
5
  const buffer = [];
4
6
  const record = opts.record ?? storeAssistant;
5
7
  let recordedId = null;
6
- const capabilities = {
7
- streaming: false,
8
- typing: false,
9
- maxMessageLength: 100_000,
10
- };
11
8
  const connector = {
12
9
  id: 'http',
13
- capabilities,
14
- async sendMessage(_chatId, text) {
15
- buffer.push(text);
16
- return { msgId: opts.botMsgId };
10
+ reply(_chatId, _ctx) {
11
+ return {
12
+ update() { },
13
+ segment() { },
14
+ async finish(r) {
15
+ for (const part of plainRender(HTTP_MAX)(r))
16
+ buffer.push(part);
17
+ return opts.botMsgId;
18
+ },
19
+ };
17
20
  },
18
21
  async recordAssistant(m) {
19
22
  const wrote = await record({
package/dist/schema.js CHANGED
@@ -4609,6 +4609,25 @@ function internalApiToken(o) {
4609
4609
  ]
4610
4610
  });
4611
4611
  }
4612
+ /**
4613
+ * Internal "connected apps" list — the OAuth clients (claude.ai & co) the user
4614
+ * has authorized for MCP access. Same "internal" caveat and custom-renderer
4615
+ * trick as internalApiToken(): read-only rows + a revoke action, never part of
4616
+ * the parent form's save.
4617
+ */
4618
+ function internalOauthGrants(o) {
4619
+ return group({
4620
+ key: o.key,
4621
+ label: o.label ?? o.key,
4622
+ multiple: true,
4623
+ view: { kind: "internalOauthGrants" },
4624
+ fields: [
4625
+ string({ key: "clientName" }),
4626
+ string({ key: "createdAt" }),
4627
+ string({ key: "lastUsedAt" })
4628
+ ]
4629
+ });
4630
+ }
4612
4631
  var SLUG_RE = /^[a-z0-9-]+$/;
4613
4632
  function slug(raw) {
4614
4633
  const o = normalizeOpts(raw);
@@ -5038,7 +5057,8 @@ var presets = {
5038
5057
  weight,
5039
5058
  dimensions,
5040
5059
  country,
5041
- internalApiToken
5060
+ internalApiToken,
5061
+ internalOauthGrants
5042
5062
  };
5043
5063
  //#endregion
5044
5064
  //#region ../../node_modules/iso-639-1/src/data.js
@@ -5865,7 +5885,7 @@ function group(o) {
5865
5885
  required: o.required,
5866
5886
  unique: r.unique,
5867
5887
  label: o.label,
5868
- icon: v.icon,
5888
+ icon: o.icon,
5869
5889
  display: v.display ?? "wrap",
5870
5890
  kind: v.kind,
5871
5891
  fixed: r.fixed,
@@ -5876,11 +5896,9 @@ function group(o) {
5876
5896
  function row(o) {
5877
5897
  return group({
5878
5898
  label: o.label,
5899
+ icon: o.icon,
5879
5900
  fields: o.fields,
5880
- view: {
5881
- ...o.view,
5882
- display: "scroll"
5883
- }
5901
+ view: { display: "scroll" }
5884
5902
  });
5885
5903
  }
5886
5904
  /** Tabular collection (array of rows → <table>, aligned by columns). Sugar. */
@@ -5888,14 +5906,12 @@ function table(o) {
5888
5906
  return group({
5889
5907
  key: o.key,
5890
5908
  label: o.label,
5909
+ icon: o.icon,
5891
5910
  fields: o.fields,
5892
5911
  multiple: true,
5893
5912
  required: o.required,
5894
5913
  rules: o.rules,
5895
- view: {
5896
- ...o.view,
5897
- display: "table"
5898
- }
5914
+ view: { display: "table" }
5899
5915
  });
5900
5916
  }
5901
5917
  /**
@@ -5911,11 +5927,9 @@ function sheet(o) {
5911
5927
  });
5912
5928
  return group({
5913
5929
  label: o.label,
5930
+ icon: o.icon,
5914
5931
  fields: flat,
5915
- view: {
5916
- ...o.view,
5917
- display: "sheet"
5918
- }
5932
+ view: { display: "sheet" }
5919
5933
  });
5920
5934
  }
5921
5935
  /**
@@ -5947,8 +5961,8 @@ function keyed(o) {
5947
5961
  return {
5948
5962
  ...(o.container ?? group)({
5949
5963
  label: o.label,
5950
- fields: [o.by, ...o.fields],
5951
- view: o.view
5964
+ icon: o.icon,
5965
+ fields: [o.by, ...o.fields]
5952
5966
  }),
5953
5967
  key: o.key,
5954
5968
  multiple: true,
@@ -6384,7 +6398,7 @@ function relation(raw) {
6384
6398
  },
6385
6399
  relation: {
6386
6400
  library: raw.options.library,
6387
- type: raw.options.shelf
6401
+ shelf: raw.options.shelf
6388
6402
  },
6389
6403
  ...multi && { json: true },
6390
6404
  zod: optionalize(s, required)
@@ -6764,15 +6778,44 @@ function period(raw) {
6764
6778
  zod: optionalize(s, required)
6765
6779
  });
6766
6780
  }
6781
+ /** Keys a file entry may carry. Everything else is rejected — see fileEntryIssue. */
6782
+ var FILE_KEYS = /* @__PURE__ */ new Set([
6783
+ "name",
6784
+ "mime",
6785
+ "size"
6786
+ ]);
6787
+ /** Keys that mean "the author pasted a remote address" — the one mistake worth naming. */
6788
+ var FILE_URL_KEYS = [
6789
+ "url",
6790
+ "src",
6791
+ "href",
6792
+ "link"
6793
+ ];
6794
+ /**
6795
+ * A file entry points at a file already uploaded to the server: `{ name }`, where
6796
+ * name is the bare filename returned by POST /api/upload. Anything else — a remote
6797
+ * URL, an extra key, a path — is refused here, so a record can never hold a
6798
+ * reference the server cannot serve. `mime`/`size` are accepted (legacy payloads
6799
+ * and the web uploader send them) but the server overwrites them from disk.
6800
+ * Returns a vmsg code, or null when the entry is well-formed.
6801
+ */
6802
+ function fileEntryIssue(it) {
6803
+ if (typeof it !== "object" || it === null || Array.isArray(it)) return "file_structure";
6804
+ const rec = it;
6805
+ if (FILE_URL_KEYS.some((k) => k in rec)) return "file_remote_url";
6806
+ const name = rec["name"];
6807
+ if (typeof name !== "string" || name === "") return "file_structure";
6808
+ if (name.includes("://") || name.startsWith("//")) return "file_remote_url";
6809
+ if (/[\\/]/.test(name) || name.includes("..")) return "file_name";
6810
+ for (const k of Object.keys(rec)) if (!FILE_KEYS.has(k)) return "file_unknown_key";
6811
+ if (rec["mime"] !== void 0 && typeof rec["mime"] !== "string") return "file_structure";
6812
+ if (rec["size"] !== void 0 && typeof rec["size"] !== "number") return "file_structure";
6813
+ return null;
6814
+ }
6767
6815
  function makeFile(kind, raw) {
6768
6816
  const o = normalizeOpts(raw);
6769
6817
  const required = o.required ?? false;
6770
6818
  const multiple = o.multiple ?? false;
6771
- const rowSchema = object({
6772
- name: string$1().min(1),
6773
- mime: string$1().optional(),
6774
- size: number$1().optional()
6775
- });
6776
6819
  const s = unknown().superRefine((raw, ctx) => {
6777
6820
  if (typeof raw === "string") try {
6778
6821
  JSON.parse(raw);
@@ -6785,12 +6828,15 @@ function makeFile(kind, raw) {
6785
6828
  }
6786
6829
  const parsed = jsonValue(raw);
6787
6830
  const items = Array.isArray(parsed) ? parsed : [parsed];
6788
- for (const it of items) if (!rowSchema.safeParse(it).success) {
6789
- ctx.addIssue({
6790
- code: ZodIssueCode.custom,
6791
- message: vmsg("file_structure")
6792
- });
6793
- return;
6831
+ for (const it of items) {
6832
+ const code = fileEntryIssue(it);
6833
+ if (code) {
6834
+ ctx.addIssue({
6835
+ code: ZodIssueCode.custom,
6836
+ message: vmsg(code)
6837
+ });
6838
+ return;
6839
+ }
6794
6840
  }
6795
6841
  });
6796
6842
  return wrapKey(o, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffer-org/plugin-http",
3
- "version": "1.4.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -25,9 +25,9 @@
25
25
  "test": "node --import tsx --test \"src/runtime/*.test.ts\""
26
26
  },
27
27
  "dependencies": {
28
- "@coffer-org/plugin-orchestrator": "^1.4.0",
29
- "@coffer-org/sdk": "^1.5.0",
30
- "@coffer-org/server": "^1.8.0"
28
+ "@coffer-org/plugin-orchestrator": "^2.1.0",
29
+ "@coffer-org/sdk": "^2.1.0",
30
+ "@coffer-org/server": "^2.2.0"
31
31
  },
32
32
  "devDependencies": {},
33
33
  "coffer": {